ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.23k stars 16.44k forks source link

Resumed model is not detecting correctly #7920

Closed Muhammad4hmed closed 2 years ago

Muhammad4hmed commented 2 years ago

Search before asking

YOLOv5 Component

No response

Bug

I trained my model into two parts, the model was supposed to train for 10 epochs

!WANDB_MODE="dryrun" python train.py --img 720 --batch 8 --epochs 10 --data ./data_fold_{foldx}.yaml --hyp ./yolov5/hyp.scratch.yaml --weight yolov5x6.pt 

but the training failed at 5 epochs and I resumed it using

!WANDB_MODE="dryrun" python train.py --img 720 --batch 8 --epochs 10 --data ./data_fold_{foldx}.yaml --hyp ./yolov5/hyp.scratch.yaml --resume './yolov5x6-ep5/weights/last.pt' 

It finished training and validation's MAP was ~0.77 which is pretty good. but on detecting, the results are not good. I detected on test set using:

!python detect.py --weights $weights_dir \
--img 720\
--conf 0.01\
--iou 0.5\
--source $test_dir\
--save-txt --save-conf --exist-ok 

When I trained the model for 5 epochs without failing, it gave leaderboard score of ~0.72 but when I used the above model which was trained for 10 epochs (including failure), the leaderboard score is ~0.2. Which means there is clearly some bug here

Environment

Latest yolov5 from github

Minimal Reproducible Example

Train using

!WANDB_MODE="dryrun" python train.py --img 720 --batch 8 --epochs 10 --data ./data_fold_{foldx}.yaml --hyp ./yolov5/hyp.scratch.yaml --weight yolov5x6.pt 

make it fail and resume

!WANDB_MODE="dryrun" python train.py --img 720 --batch 8 --epochs 10 --data ./data_fold_{foldx}.yaml --hyp ./yolov5/hyp.scratch.yaml --resume './yolov5x6-ep5/weights/last.pt' 

Now predict !python detect.py --weights $weights_dir \ --img 720\ --conf 0.01\ --iou 0.5\ --source $test_dir\ --save-txt --save-conf --exist-ok



if you check the predicted labels, they are not good enough.

### Additional

_No response_

### Are you willing to submit a PR?

- [ ] Yes I'd like to help by submitting a PR!
glenn-jocher commented 2 years ago

@Muhammad4hmed πŸ‘‹ Hello! Thanks for asking about improving YOLOv5 πŸš€ training results.

Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.

If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name directory, typically yolov5/runs/train/exp.

We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.

Dataset

COCO Analysis

Model Selection

Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.

YOLOv5 Models

Training Settings

Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.

Further Reading

If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/

Good luck πŸ€ and let us know if you have any other questions!

github-actions[bot] commented 2 years ago

πŸ‘‹ Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 πŸš€ resources:

Access additional Ultralytics ⚑ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 πŸš€ and Vision AI ⭐!