我将Sports_1M caffe模型转换为Keras,并将其作为预训练模型使用到新的Keras模型中,我还加载了预训练的权重。
我删除了预先训练过的模型的顶层,最后与New连接起来。我不想再次训练加载的预训练模型(只是想使用预训练模型的嵌入,并使用它来训练我的新的Keras模型)。
代码如下所示:
from keras.models import model_from_json
from keras import backend as K
K.set_image_dim_ordering('th')
model = model_from_json(open('/content/sports_1M/sports1M_model_new.json', 'r').read())
model.load_weights('/content/sports_1M/sports1M_weights.h5')
我的问题是:
optimizer='adam') model.compile(损失=‘均方误差’)
model2 =模型(model.get_input_at(0),model.get_layer(layer_name).output) input_shape = (3,16,112,112) encoded_l = model2(left_input)预测=致密(1,激活=‘sigmoid’)(Encoded_l)模型(left_input,right_input,预测)
当我们使用内置预训练模型(如VGG )时,我们通常使用VGG(include_top = False , weights = 'imagenet')
。
我这样想是为了我的案子
发布于 2020-07-19 16:03:52
我得到了答案,我们只需设置layers.trainable = False
for layer in model.layers:
layer.trainable = False
https://stackoverflow.com/questions/62982174
复制相似问题