ultralytics / yolov3

YOLOv3 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
10.18k stars 3.44k forks source link

Help training shapes #1768

Closed bkbilly-intrack closed 3 years ago

bkbilly-intrack commented 3 years ago

❔Question

I am trying to create a model that can recognize shapes (cylinder, sphere, box). I have followed the guide for training custom data, but the results are really disappointing. Can someone guide me on what I can change to have better results?

Additional context

shapes.yaml

train: ../data_shapes/images/train  # 175 images
val: ../data_shapes/images/val  # 26 images
test: ../data_shapes/images/test  # 49 images
nc: 3
names: [ 'cylinder', 'sphere', 'box' ]

data structure:

../data_shapes/
├── images
│   ├── test
│   │   ├── set31.jpg
│   │   ├── ...
│   │   └── set39.jpg
│   ├── train
│   │   ├── my_image_10.jpg
│   │   ├── ...
│   │   └── test_image_whitebackground_hard_9.jpg
│   └── val
│       ├── my_image_105.jpg
│       ├── ...
│       └── test_image_whitebackground_hard_2.jpg
└── labels
    ├── test
    │   ├── set31.txt
    │   ├── ...
    │   └── set39.txt
    ├── train
    │   ├── my_image_10.txt
    │   ├── ...
    │   └── test_image_whitebackground_hard_9.txt
    └── val
        ├── my_image_105.txt
        ├── ...
        └── test_image_whitebackground_hard_2.txt

Results

I have visualized the results here: https://wandb.ai/bkbilly/YOLOv5/runs/13v83iij?workspace=user-bkbilly

github-actions[bot] commented 3 years ago

👋 Hello @koulis-probotek, thank you for your interest in YOLOv3 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

YOLOv3 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv3 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv3 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 3 years ago

@koulis-probotek 👋 Hello! Thanks for asking about improving 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/

bkbilly-intrack commented 3 years ago

@glenn-jocher I didn't try the YoloV5 instructions, though if you think that it will help, I will give it a try. Also I have a small dataset with a sample of images: 175 train, 26 val, 49 test. It's difficult to find annotated images for shapes, so is it going to be a problem? I have to mention that I did a train for only 5 epochs just like the tutorial for YoloV3 like so:

$ python train.py --img 640 --batch 16 --epochs 5 --data shapes.yaml --weights yolov3.pt

I've uploaded the output images here on github, though I have them visualized at the WanDB: https://wandb.ai/bkbilly/YOLOv5/runs/13v83iij?workspace=user-bkbilly

R_curve: R_curve results: results test_batch0_labels: test_batch0_labels test_batch0_pred: test_batch0_pred train_batch0: train_batch0 train_batch1: train_batch1 train_batch2: train_batch2 confusion_matrix: confusion_matrix F1_curve: F1_curve

glenn-jocher commented 3 years ago

@koulis-probotek you're clearly not following the guidance I pasted above. I would recommend you read it closely and follow it for best results.

bkbilly-intrack commented 3 years ago

The results I posted are from the YoloV3 guidance. I will take a look on the one you posted for the YoloV5. I am kind of new on training new datasets, so thanks for pointing me to the right direction.

glenn-jocher commented 11 months ago

@bkbilly-intrack you're welcome! Training custom datasets can be challenging, but the YOLOv5 guide should help you optimize your results. If you have any more questions as you work through it, feel free to ask. Good luck!