【发布时间】:2021-07-08 16:35:34
【问题描述】:
我正在为以下问题编写代码:
- 我有一个包含训练和测试目录的水果数据集。在这两个目录中,都包含 6 个类(新鲜/烂苹果、新鲜/烂橙、新鲜/烂香蕉)。
- 我在 MobileNetV2 模型上使用迁移学习
我正在尝试正确设置我的数据拆分,但对如何...
感到困惑- 获取训练、验证和测试拆分设置
- 如何检查它们是否确实设置正确(例如没有数据重叠)
- 如何通过培训保存进度。 (示例:我运行我的脚本训练了 10 个 epoch。当我再次运行我的脚本 x epoch 时,如何确保训练从我中断的地方继续。)
到目前为止我的代码:
train_batches = ImageDataGenerator(preprocessing_function=mobilenet_v2.preprocess_input, validation_split=0.20).flow_from_directory(
train_path, target_size=(im_height, im_width), batch_size=batch_size)
test_batches = ImageDataGenerator(preprocessing_function=mobilenet_v2.preprocess_input).flow_from_directory(
test_path, target_size=(im_height, im_width), batch_size=batch_size)
mobv2 = tf.keras.applications.mobilenet_v2.MobileNetV2()
x = mobv2.layers[-2].output
output_layer = Dense(units=6, activation='softmax')(x)
model = tf.keras.models.Model(inputs=mobv2.input, outputs=output_layer)
for layer in model.layers[:-25]:
layer.trainable = False
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=.0001),
loss='categorical_crossentropy',
metrics=['accuracy']
)
这是我的适合,但还没有完成,因为我不确定要包含什么来进行验证和测试......
model.fit(train_batches, steps_per_epoch=4, )
【问题讨论】:
标签: python tensorflow machine-learning conv-neural-network