首页 > 解决方案 > 如何使用 tensorflow 微调训练好的模型和保存的模型?

问题描述

我有一个大数据集,我想通过这个数据集训练efficientnetb0,但是 google colab 运行超时,所以我想训练模型的完全连接层并保存它,然后在几个小时后再次加载并微调基本模型(高效网络b0)。我怎样才能做到这一点?

标签: tensorflowdeep-learningtransfer-learningefficientnet

解决方案


您可以通过以下方式执行此操作。请根据您的要求进行更改。这是起点的快照。

if not os.path.exists('e10.h5'):
    model = get_model() #this method constructs the model and compiles it 
else:
    model = load_model('tf_keras_cifar10.h5') #load the model from file
    print('lr is ', K.get_session().run(model.optimizer.lr))
    initial_epoch=10
    epochs=13

history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs,validation_data=(x_test, y_test), initial_epoch=initial_epoch)
model.save('e.h5')

推荐阅读