tensorflow 属性错误:"历史记录"对象没有属性"保存"

plicqrtu  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(187)

来源:tensorflow tutorials - Save and Load
我用EfficientNetB0 from tensorflow hub训练了我的模型,它在合适的时候进行得很好。

# Fit EfficientNet model
efficientnet_history = efficientnet_model.fit(train_data,
                                              epochs=2,
                                              steps_per_epoch=len(train_data),
                                              validation_data=test_data,
                                              validation_steps=len(test_data),
                                              callbacks = [learning_rate_reduction, modelCheckpoint])

结果:

2022-12-23 11:05:43.012196: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
Epoch 1/2
2022-12-23 11:05:51.883413: I tensorflow/stream_executor/cuda/cuda_dnn.cc:369] Loaded cuDNN version 8302
11/11 [==============================] - 20s 819ms/step - loss: 2.1915 - accuracy: 0.2649 - val_loss: 1.9363 - val_accuracy: 0.3286

Epoch 00001: saving model to training_1\cp.ckpt
Epoch 2/2
11/11 [==============================] - 6s 580ms/step - loss: 1.8275 - accuracy: 0.5000 - val_loss: 1.5922 - val_accuracy: 0.6429

Epoch 00002: saving model to training_1\cp.ckpt

但是为什么这个模型不能用efficientnet_history.save保存呢?我的代码:

efficientnet_history.save("signlen_efficientnet_model.h5")

错误:

Traceback (most recent call last):
  File "c:/Users/OOO/Desktop/Projects/SignLens/test/ASL_for_fun/asl_train.py", line 89, in <module>
    efficientnet_history.save("signlen_efficientnet_model.h5")
AttributeError: 'History' object has no attribute 'save'

如何正确保存模型?或者,是否有其他方法可以保存模型?

ymzxtsji

ymzxtsji1#

出现此错误的原因是您正在对历史对象调用save。您应该对模型本身调用save。例如,更改以下内容:

efficientnet_history.save("signlen_efficientnet_model.h5")

对此:

efficientnet_model.save("signlen_efficientnet_model.h5")

相关问题