简体   繁体   English

保存 YOLOv3 模型状态和加载

[英]Saving YOLOv3 Model State and Loading

I am trying to train YOLOv3 model following ImageAi documentation with my custom dataset.But the training is taking too much time that Google Colab time is not enough for this.我正在尝试使用我的自定义数据集按照 ImageAi 文档训练 YOLOv3 模型。但是训练花费了太多时间,Google Colab 时间不足以完成此任务。 Now how can I save Model state and load it after 50/60 epoch completion?现在如何保存模型状态并在 50/60 纪元完成后加载它? As I am a beginner I am not getting Tensorflow Model Checkpoint t由于我是初学者,我没有得到 Tensorflow 模型检查点

Here is a sample of the code:下面是代码示例:

from imageai.Detection.Custom import DetectionModelTrainer 

trainer = DetectionModelTrainer() 
trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="/content/drive/My Drive/Dataset") 
trainer.setTrainConfig(object_names_array=["obj1","obj2"], batch_size=4, num_experiments=421) 
trainer.trainModel()

You should use a ModelChekpoint as callback of your method.您应该使用 ModelChekpoint 作为方法的回调。 But you use a custom class that already handle this.但是您使用了一个已经处理过这个问题的自定义类。

If you have a look at the code on there github you can see that they use some custom callbacks如果您查看 github 上的代码,您会发现它们使用了一些自定义回调

They save the model after each epoch by only the best one (not the last one).他们在每个 epoch 之后只保存最好的模型(而不是最后一个)。 The model should be saved in the folder <data_directory>/models/detection_model- :模型应保存在文件夹 <data_directory>/models/detection_model- 中:

self.__model_directory = os.path.join(data_directory, "models")
self.__train_weights_name = os.path.join(self.__model_directory, "detection_model-")

If you want to save the last iteration you have to overwrite the method for custom callbacks and change save_best_only to False .如果要保存最后一次迭代,则必须覆盖自定义回调的方法并将save_best_only更改为False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM