[英]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.