迁移学习模型错误,ValueError:“train_function”的意外结果(空日志)
感谢您的阅读,我在使用迁移学习模型时遇到问题。不过,我认为问题是由于 model.fit_generator() 造成的,因为当我尝试运行自定义卷积神经网络时,会发生完全相同的错误。
# transfer learning model, vgg16
vgg = VGG16(input_shape= IMAGE_SIZE + [3], weights = 'imagenet', include_top = False)
x = vgg.output
x = Flatten()(x)
x = Dropout(0.3)(x)
x = Dense(128, activation='relu')(x)
x = Dropout(0.3)(x)
prediction = Dense(nb_classes, activation='softmax')(x)
for layers in vgg.layers:
layers.trainable = False
model_name = 'vgg16.h5'
early_stop = EarlyStopping(monitor='val_loss',min_delta=0.003, patience=15, verbose=1, mode='auto',
restore_best_weights=True)
checkpoint_fixed_name = ModelCheckpoint(model_name,
monitor='val_loss', verbose=1, save_best_only=True,
save_weights_only=True, mode='auto', save_Freq=5)
callbacks = [checkpoint_fixed_name, early_stop]
model = Model( inputs = vgg.input, outputs = prediction)
model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics= ['accuracy'])
# train model
history = model.fit_generator(training_set,epochs=100,steps_per_epoch=int(len(training_set)/8),
validation_steps=int(len(test_set)/4),validation_data=valid_set,
callbacks=callbacks)
#Error
ValueError: Unexpected result of `train_function` (Empty logs). Please use `Model.compile(..., run_eagerly=True)`, or `tf.config.run_functions_eagerly(True)` for more information of where went wrong, or file a issue/bug to `tf.keras`.
我尝试拆分每一行,发现错误可能是由于回调=回调造成的,但我不确定如何修复它?
谢谢。
thanks for reading, I am having an issue when using a transfer learning model. However I believe the issue is due to the model.fit_generator() as the exact same error occurs when I try to run my custom convolutional neural network.
# transfer learning model, vgg16
vgg = VGG16(input_shape= IMAGE_SIZE + [3], weights = 'imagenet', include_top = False)
x = vgg.output
x = Flatten()(x)
x = Dropout(0.3)(x)
x = Dense(128, activation='relu')(x)
x = Dropout(0.3)(x)
prediction = Dense(nb_classes, activation='softmax')(x)
for layers in vgg.layers:
layers.trainable = False
model_name = 'vgg16.h5'
early_stop = EarlyStopping(monitor='val_loss',min_delta=0.003, patience=15, verbose=1, mode='auto',
restore_best_weights=True)
checkpoint_fixed_name = ModelCheckpoint(model_name,
monitor='val_loss', verbose=1, save_best_only=True,
save_weights_only=True, mode='auto', save_Freq=5)
callbacks = [checkpoint_fixed_name, early_stop]
model = Model( inputs = vgg.input, outputs = prediction)
model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics= ['accuracy'])
# train model
history = model.fit_generator(training_set,epochs=100,steps_per_epoch=int(len(training_set)/8),
validation_steps=int(len(test_set)/4),validation_data=valid_set,
callbacks=callbacks)
#Error
ValueError: Unexpected result of `train_function` (Empty logs). Please use `Model.compile(..., run_eagerly=True)`, or `tf.config.run_functions_eagerly(True)` for more information of where went wrong, or file a issue/bug to `tf.keras`.
I tried splitting each line and found out that the error is probably due to the callbacks=callbacks but I am not sure how to fix it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查您的输入图像是否有形状;它们是灰度或 RGB,或者是空输入图像的可能性。
Check Your input images have a shape; they are grayscale or RGB, or the possibility of an empty input image.