迁移学习模型错误,ValueError:“train_function”的意外结果(空日志)

发布于 2025-01-17 05:01:04 字数 1624 浏览 2 评论 0原文

感谢您的阅读,我在使用迁移学习模型时遇到问题。不过,我认为问题是由于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌酱 2025-01-24 05:01:04

检查您的输入图像是否有形状;它们是灰度或 RGB,或者是空输入图像的可能性。

Check Your input images have a shape; they are grayscale or RGB, or the possibility of an empty input image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文