问题描述
我加载保存的模型,出于微调的原因,我在加载的模型的输出中添加了分类层,所以我写的是这样:
def create_keras_model():
model = tf.keras.models.load_model('model.h5',compile=False)
resnet_output = model.output
layer1 = tf.keras.layers.GlobalAveragePooling2D()(resnet_output)
layer2 = tf.keras.layers.Dense(units=256,use_bias=False,name='nonlinear')(layer1)
model_output = tf.keras.layers.Dense(units=2,name='output',activation='relu')(layer2)
model = tf.keras.Model(model.input,model_output)
return model
但我发现此错误:
ValueError: Input 0 of layer global_average_pooling2d is incompatible with the layer: expected ndim=4,found ndim=2. Full shape received: [None,128]
任何人都可以帮助我,从错误中告诉我什么以及如何解决此问题。 谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)