简体   繁体   English

Keras 预训练模型回溯

[英]Keras Pretrained Model Traceback

When running this line:运行此行时:

base_model = MobileNetV2(include_top=False, weights='imagenet', input_tensor=input_tensor, pooling=None, classes=NB_CLASS)

I get the following error我收到以下错误

在此处输入图片说明

How do I solve the problem?我该如何解决问题?

Without the save a'd the load file part of your code it's hard to say from where is the issue.如果没有保存代码的加载文件部分,很难说问题出在哪里。 If I well understood, you saved the weights in a file h5py?如果我很好理解,您将权重保存在文件 h5py 中?

I think it's always easier to save the whole trained model than only the weights:我认为保存整个训练好的模型总是比只保存权重更容易:

from keras.models import load_model
model.save('my_model.h5')  # creates a HDF5 file 'my_model.h5'

# returns a compiled model
# identical to the previous one
model = load_model('my_model.h5')

Managed to solve the problem by deleting the pretrained weights and running the code again to redownload the file.通过删除预训练权重并再次运行代码以重新下载文件,设法解决了问题。

The pretrained weights file was saved in /home in the /.keras hidden folder in a .h5 file.预训练权重文件保存在 /home 中的 /.keras 隐藏文件夹中的 .h5 文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM