如何 "Iterate" 上 Computer Vision 机器学习模型?

How to "Iterate" on Computer Vision machine learning model?

我使用 google 云视觉 api 创建了一个模型。我花了无数个小时标记数据,并训练了一个模型。在模型 "training" 将近 20 小时结束时,它仍然时好时坏。

如何迭代此模型?我不想丢失目前已完成的 "learning"。它工作了大约 3/5 次。

我最好的猜测是我应该再次遍历对象,找到错误的地方,并相应地标记。但我不确定最好的方法。我是否应该将 "misses" 处的所有图像标记为测试数据图像?是否有我可以阅读的有关此主题的最佳实践或资源?

我绝不是专家,但以下是我按照最重要到最不重要的顺序提出的建议:

1) 如果可能,请添加更多数据。更多数据总是一件好事,有助于提高网络预测的稳健性。

2)

3) 修补一下 kernel and bias initialisers

4) [与您的问题最相关的答案] 保存模型的训练权重并在训练前将它们重新加载到新模型中。

5) 更改您正在使用的模型架构类型。然后,对 epoch 数、验证拆分、损失评估公式等进行修补

希望对您有所帮助!


编辑:关于数字 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)

然后编译模型,就可以retrain/predict了。 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