问题
- 在自定义继承自
keras.Model
的模型时,使用model.save("mode.h5")
会报错,于是,可行的方法是,使用model.save_weights("seg_model_weights.h5")
时正确保存。但是在加载模型时报错:
'Unable to load weights saved in HDF5 format into a subclassed ’ ValueError: Unable to load weights saved in HDF5 format into a
subclassed Model which has not created its variables yet. Call the
Model first, then load the weights.
解决方法
- 在加载之前先
build
,model.build(input_shape =<Input shape>)
。下面是样例
model.build(input_shape =(None,256,256,3))
model.load_weights(path)