我已经使用Google Clouds Vision API创建了一个模型。我花了无数小时来标记数据,并训练了模型。在“训练”模型将近20个小时后,它仍然屡试不爽。
我如何迭代该模型?我不想失去到目前为止所做的“学习”。它可以工作大约3/5次。
我的最佳猜测是,我应该再次遍历对象,找到错误的地方,并相应地进行标记。但是我不确定最好的方法。我应该将“丢失”的所有图像标记为TEST数据图像吗?我是否可以阅读有关此主题的最佳实践或资源?
2)Add dropout layers to prevent over-fitting
3)修补kernel and bias initialisers
4)[问题最相关的答案]保存模型的训练权重,然后在训练之前将其重新加载到新模型中。
5)更改您正在使用的模型架构的类型。然后,使用修补程序添加纪元编号,验证拆分,损失评估公式等。
希望这会有所帮助!
编辑:有关数字4的更多信息
因此您可以在训练模型期间或之后保存和加载模型权重。 See here有关保存的更多详细信息。
广泛地说,让我们介绍一下基础知识。我假设您正在经历keras,但对tf同样适用:训练后保存模型
简单呼叫:
model_json = model.to_json()
with open("{Your_Model}.json", "w") as json_file:
json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("{Your_Model}.h5")
print("Saved model to disk")
加载模型
您可以像这样从json加载模型结构:
from keras.models import model_from_json
json_file = open('{Your_Model.json}', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
如果需要,请加载砝码:
model.load_weights('{Your_Weights}.h5', by_name=True)
然后编译模型,您便可以进行重新训练/预测。对我来说by_name
对于将权重重新加载到同一模型体系结构中至关重要;忽略它可能会导致错误。
训练期间检查模型
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath={checkpoint_path},
save_weights_only=True,
verbose=1)
# Train the model with the new callback
model.fit(train_images,
train_labels,
epochs=10,
validation_data=(test_images,test_labels),
callbacks=[cp_callback]) # Pass callback to training