本文共 1332 字,大约阅读时间需要 4 分钟。
1 from tensorflow.contrib.keras.api.keras.preprocessing.image import ImageDataGenerator,img_to_array 2 from tensorflow.contrib.keras.api.keras.models import Sequential 3 from tensorflow.contrib.keras.api.keras.layers import Dense, Dropout, Activation, Flatten 4 from tensorflow.contrib.keras.api.keras.layers import Conv2D, MaxPooling2D 5 IMAGE_SIZE = 224 6 img_rows= 224 7 img_cols = 224 8 # 训练图片大小 9 epochs = 50#原来是5010 # 遍历次数11 batch_size = 3212 # 批量大小13 nb_train_samples = 256*214 # 训练样本总数15 nb_validation_samples = 64*216 # 测试样本总数17 train_data_dir = 'D:\\pycode\\learn\\data\\train_data\\'18 validation_data_dir = 'D:\\pycode\\learn\\data\\test_data\\'19 # 样本图片所在路径20 FILE_PATH = 'age.h5'21 22 train_datagen = ImageDataGenerator(23 rescale=1. / 255,24 horizontal_flip=True)25 26 test_datagen = ImageDataGenerator(rescale=1. / 255)27 28 train_generator = train_datagen.flow_from_directory(29 train_data_dir,30 target_size=(img_rows, img_cols),31 batch_size=batch_size,32 class_mode='categorical')33 34 validation_generator = test_datagen.flow_from_directory(35 validation_data_dir,36 target_size=(img_rows, img_cols),37 batch_size=batch_size,38 class_mode='categorical')39 40 # self.train = train_generator41 # self.valid = validation_generator42 print(validation_generator.class_indices)
转载地址:http://kcjpx.baihongyu.com/