【发布时间】:2020-11-08 22:11:35
【问题描述】:
我将 Sports_1M caffe 模型转换为 Keras,并将其作为预训练模型使用到我的新 Keras 模型中。我还加载了预训练的权重。
我删除了 Pretrained 模型的顶层,最后与 New Model 连接。我不想再次训练加载的预训练模型(只想使用预训练模型的嵌入并用它来训练我的新 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')
我的问题是:
-
我应该编译预训练模型然后将其连接起来吗?
model.compile(loss='mean_squared_error', optimizer='adam') -
我怎么知道预训练模型没有再次训练它(我不想要)?
-
如何训练整个(串联)架构?
model2 = Model(model.get_input_at(0),model.get_layer(layer_name).output) input_shape = (3, 16, 112, 112) encoded_l = model2(left_input) prediction = Dense(1,activation='sigmoid')(encoded_l) Model([left_input,right_input] , prediction) -
当我们使用像 VGG 这样的 Inbuild 预训练模型时,我们一般使用
VGG(include_top = False , weights = 'imagenet')
我的情况是这样想的
【问题讨论】:
标签: tensorflow keras deep-learning