Tianxiaomo / pytorch-YOLOv4

PyTorch ,ONNX and TensorRT implementation of YOLOv4
Apache License 2.0
4.48k stars 1.49k forks source link

How to further train on a custom pretrained model? #307

Open kepler62f opened 4 years ago

kepler62f commented 4 years ago

Thanks for this PyTorch implementation of Yolov4! I successfully used the train script to custom train a 2-class object detector in 300 epochs. The last model output is Yolov4_epoch300.pth with AP (IoU=0.50:0.95 | area=all | maxDets=100) = 0.182 and AR (IoU=0.50:0.95 | area=all | maxDets=100) = 0.495. I could use this file to make inference using the model.py script. However when I use the same model file as "pretrained weights" to do a new training (same dataset, classes & config), I find that at epoch 1, the AP and AR start from 0.000. I thought they might start at the levels of AP and AR similar to that at epoch 300 of the previous training. Can model output files from training be used for new / further training?

berkantay commented 4 years ago

Hello @kepler62f how did you build the structure of your dataset. I dont know how to make the structure for yolo format.

kepler62f commented 4 years ago

Hello @kepler62f how did you build the structure of your dataset. I dont know how to make the structure for yolo format.

The training script doesn't take in yolo format. I structure my dataset according to the format specified in readme.md:

train.txt image_path1 x1,y1,x2,y2,id x1,y1,x2,y2,id x1,y1,x2,y2,id ... image_path2 x1,y1,x2,y2,id x1,y1,x2,y2,id x1,y1,x2,y2,id ..

I downloaded custom data using OIDv4_Toolkit but did some more crude scripting to convert the annotations into above format.

By the way, I trained a few more epochs using the last training model file as pretrained model weights (Yolov4_epoch300.pth) and then tried inference on it and the result was off. Doesn't seem to be able to use model output for further training. Any one knows how?

alaap001 commented 3 years ago

Thanks for this PyTorch implementation of Yolov4! I successfully used the train script to custom train a 2-class object detector in 300 epochs. The last model output is Yolov4_epoch300.pth with AP (IoU=0.50:0.95 | area=all | maxDets=100) = 0.182 and AR (IoU=0.50:0.95 | area=all | maxDets=100) = 0.495. I could use this file to make inference using the model.py script. However when I use the same model file as "pretrained weights" to do a new training (same dataset, classes & config), I find that at epoch 1, the AP and AR start from 0.000. I thought they might start at the levels of AP and AR similar to that at epoch 300 of the previous training. Can model output files from training be used for new / further training?

I am facing the same issue! I think it is not loading pre trained weights even after mentioning, did you solved it?

kepler62f commented 3 years ago

Thanks for this PyTorch implementation of Yolov4! I successfully used the train script to custom train a 2-class object detector in 300 epochs. The last model output is Yolov4_epoch300.pth with AP (IoU=0.50:0.95 | area=all | maxDets=100) = 0.182 and AR (IoU=0.50:0.95 | area=all | maxDets=100) = 0.495. I could use this file to make inference using the model.py script. However when I use the same model file as "pretrained weights" to do a new training (same dataset, classes & config), I find that at epoch 1, the AP and AR start from 0.000. I thought they might start at the levels of AP and AR similar to that at epoch 300 of the previous training. Can model output files from training be used for new / further training?

I am facing the same issue! I think it is not loading pre trained weights even after mentioning, did you solved it?

No I did not. Incidentally, I tried training on AlexeyAB/darknet yolov4 and was able to use its output weights to continue training in a separate run.