【发布时间】:2018-03-02 21:00:08
【问题描述】:
我已经使用 keras 中 ResNet50 的迁移学习训练了一个宪法网络,如下所示。
base_model = applications.ResNet50(weights='imagenet', include_top=False, input_shape=(333, 333, 3))
## set model architechture
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
x = Dense(256, activation='relu')(x)
predictions = Dense(y_train.shape[1], activation='softmax')(x)
model = Model(input=base_model.input, output=predictions)
model.compile(loss='categorical_crossentropy', optimizer=optimizers.SGD(lr=1e-4, momentum=0.9),
metrics=['accuracy'])
model.summary()
按照下面给出的训练模型后,我想保存模型。
history = model.fit_generator(
train_datagen.flow(x_train, y_train, batch_size=batch_size),
steps_per_epoch=600,
epochs=epochs,
callbacks=callbacks_list
)
我不能使用 keras 模型中的 save_model() 函数,因为这里的模型是 Model 类型。我使用 save() 函数来保存模型。但后来当我加载模型并验证模型时,它的行为就像一个未经训练的模型。我认为重量没有保存。哪里错了。?如何正确保存这个模型?
【问题讨论】:
-
使用
save_model()会发生什么? -
它说模型没有那个功能。
-
你用的是什么版本的keras?
-
Keras 版本为 2.0.6
-
save_model 不是任何模型类的成员函数,它是 keras.models 包中的一个函数。
标签: machine-learning deep-learning keras