通常,这个错误是由于将keras_inception_resnet_v2的权重加载时缺少引入产生的。在模型定义时,像下面这样添加一个引用即可:
from keras.layers import Input
from keras.models import Model
from keras_inception_resnet_v2 import InceptionResNetV2
img_input = Input(shape=(299, 299, 3))
model = InceptionResNetV2(include_top=False, weights=None, input_tensor=img_input)
# 下面可以接上自定义的输出层
或者,通过在导入时指定图层规范来修复这个问题,如下所示:
from keras_inception_resnet_v2 import InceptionResNetV2
from tensorflow.keras import Input, Model
from tensorflow.keras.layers import InputSpec
img_input = Input(shape=(299, 299, 3))
model = InceptionResNetV2(include_top=False, weights=None, input_tensor=img_input)
model.layers[0].input_spec = InputSpec(ndim=4, dtype='float32', shape=(None, 299, 299, 3))
上一篇:BERT模型无法适配。
下一篇:Bert模型训练不想停止