简体   繁体   English

keras model.load_weights 错误 NoneType' object 没有属性 'fit'

[英]keras model.load_weights error NoneType' object has no attribute 'fit'

hope someone can help with this, I am trying to train a model base on another pre-trained model, but I keep getting this error.希望有人可以帮助解决这个问题,我正在尝试在另一个预先训练的 model 的基础上训练 model,但我一直收到此错误。

Thanks in advance.提前致谢。 and happy coding.和快乐的编码。

Model Model

model = Unet(backbone_name=efficientnetb2, encoder_weights='imagenet',
             input_shape=(256, 256, 3),
             classes=1, activation='sigmoid')
    model = get_model(
        mparams['backbone'], 
        input_shape=(mparams['img_size'], mparams['img_size'], 3),
        loss_type=mparams['loss'],
        umodel=mparams['umodel'],
        lr=mparams['lr']
    )
    
    # load model
    model = model.load_weights('./models_v24/model_0.hdf5')

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-b3a8ba8f71c6> in <module>
     41             resize=None
     42         )
---> 43         model, history = train_model(PARAMS, n, train_datagen, val_datagen)
     44         plt.plot(history.history['loss'], label='loss')
     45         plt.plot(history.history['val_loss'], label='val_loss')

<ipython-input-17-191deeedc4ed> in train_model(mparams, n_fold, train_datagen, val_datagen)
     53     model = model.load_weights('./models_v24/model_0.hdf5')
     54 
---> 55     history = model.fit(
     56                         train_datagen,
     57                         validation_data=val_datagen,

AttributeError: 'NoneType' object has no attribute 'fit'

Your comment # load model which is not correct.您的评论# load model这是不正确的。 You are just loading weights here, not the whole model .您只是在这里加载重量,而不是整个 model This function returns None when loading weights in HDF5 format which explains the current error here.此 function 在以 HDF5 格式加载权重时返回None ,这解释了此处的当前错误。

If the model is created, you just need model.load_weights('./models_v24/model_0.hdf5') .如果创建了 model,则只需要model.load_weights('./models_v24/model_0.hdf5') Then you should be able to fit the model.然后你应该能够安装 model。

model = get_model(...)

# load weights
model.load_weights('./models_v24/model_0.hdf5')

Also I noticed you did not accept some of the answers in SO.我还注意到您不接受 SO 中的某些答案。 Please take a look at What should I do when someone answers my question?请看一下当有人回答我的问题时我该怎么办?

don't use [model = model.load_weights()] use [model.load_weights()] direactly不要直接使用 [model = model.load_weights()] 使用 [model.load_weights()]

暂无
暂无

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

相关问题 Keras AttributeError: 'NoneType' object 在 load_model 中没有属性 'endswith' - Keras AttributeError: 'NoneType' object has no attribute 'endswith' in load_model model.fit() Keras 分类多输入-单输出给出错误:AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;fit&#39; - model.fit() Keras Classification Multiple Inputs-Single Output gives error: AttributeError: 'NoneType' object has no attribute 'fit' Keras model.load_weights() 错误:ValueError: Invalid high library version bound (invalid high library version bound) - Keras model.load_weights() error: ValueError: Invalid high library version bound (invalid high library version bound) 属性错误:'NoneType' object 在使用 tf.keras fit_generator() 时没有属性 'shape' - Attribute error: 'NoneType' object has no attribute 'shape' when using tf.keras fit_generator() model.save_weights 和 model.load_weights 没有按预期工作 - model.save_weights and model.load_weights not working as expected 使用预训练的 model 和 keras: AttributeError: 'NoneType' object 没有属性 'shape' - Using pretrained model with keras: AttributeError: 'NoneType' object has no attribute 'shape' Keras 导入模型 AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;op&#39; - Keras import model AttributeError: 'NoneType' object has no attribute 'op' AttributeError: 'NoneType' object 没有属性 'evaluate' 评估 keras 中加载的 model - AttributeError: 'NoneType' object has no attribute 'evaluate' with evaluating of loaded model in keras &#39;NoneType&#39;对象在keras中的hyperas没有属性&#39;evaluate&#39;错误 - 'NoneType' object has no attribute 'evaluate' error with hyperas in keras 如果仅对模型进行了少许更改(例如退出),是否应该在使用model.load_weights()之前运行model.compile()? - should model.compile() be run prior to using model.load_weights(), if model has been only slightly changed say dropout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM