ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.22k stars 16.21k forks source link

Extremely low accuracy #10532

Closed DhruvAwasthi closed 1 year ago

DhruvAwasthi commented 1 year ago

Search before asking

Question

I am trying to train a detection model to detect the regions in packaged food product images that contain the nutrients and ingredients. So basically there are two classes -ingredients and nutrients.

The sample original image may looks like this:

2482-brazil-nuts-8oz-v4 5 1_web_back

For this, I labeled the training data and exported the *.txt files in yolo format. The sample .txt file looks like this:

0 0.366042 0.395625 0.632083 0.127917
1 0.367083 0.491042 0.634167 0.062917

I labeled around 250 images for this, and then after using augmentations the dataset size grew to over 6,000 images. In the training dataset, I have also included around 10% of random background images.

I organized the training data into the following format:

dataset/
    train/
        images/
        labels/
    val/
        images/
        labels/
    test/
        images/
        labels/

For training, I tried with YOLOv5s, YOLOv5m, and YOLOv5m6. I am training the model for around 300 epochs, using a patience level of 10and using the Adam optimizer. But due to early stopping the model training is stopping in between around 10 and 20 epochs.

The opt.yaml file looks like this:

weights: yolov5m6.pt
cfg: ''
hyp:
  lr0: 0.01
  lrf: 0.01
  momentum: 0.937
  weight_decay: 0.0005
  warmup_epochs: 3.0
  warmup_momentum: 0.8
  warmup_bias_lr: 0.1
  box: 0.05
  cls: 0.5
  cls_pw: 1.0
  obj: 1.0
  obj_pw: 1.0
  iou_t: 0.2
  anchor_t: 4.0
  fl_gamma: 0.0
  hsv_h: 0.015
  hsv_s: 0.7
  hsv_v: 0.4
  degrees: 0.0
  translate: 0.1
  scale: 0.5
  shear: 0.0
  perspective: 0.0
  flipud: 0.0
  fliplr: 0.5
  mosaic: 1.0
  mixup: 0.0
  copy_paste: 0.0
epochs: 300
batch_size: 4
imgsz: 896
rect: false
resume: false
nosave: false
noval: false
noautoanchor: false
noplots: false
evolve: null
bucket: ''
cache: null
image_weights: false
device: ''
multi_scale: false
single_cls: false
optimizer: Adam
sync_bn: false
workers: 8
project: runs/train
name: exp
exist_ok: false
quad: false
cos_lr: false
label_smoothing: 0.0
patience: 10
freeze:
- 0
save_period: -1
seed: 0
local_rank: -1
entity: null
upload_dataset: false
bbox_interval: -1
artifact_alias: latest
save_dir: runs/train/exp

But even after all this, the confidence score that I am getting on the predictions on test images is too low, with the maximum being 0.016 and the lowest in the order of 0.0001xx. These confidence scores are the same for the images that actually contain the classes that I want to predict, and for the images that do not contain these classes at all.

Can you please tell me what you suspect is wrong here?

Thank you, Dhruv

Additional

No response

github-actions[bot] commented 1 year ago

👋 Hello @DhruvAwasthi, thank you for your interest in YOLOv5 🚀! 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://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

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

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 1 year ago

@DhruvAwasthi 👋 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 1 year 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 ⭐!

huntracker commented 1 year ago

@glenn-jocher I am trying to train a detection model to detect the coconut bunches,coconut stem,leaf,leaf stem,spathe in a custom coconut dataset i created. but the map is getting very low. i had tried with different epochs and batch size also changed the hyper parameters and tested but map is very low and not detecting all the classes while testing. result11 yolo11

glenn-jocher commented 11 months ago

@huntracker 👋 Hello! It looks like you've put in a lot of effort creating a custom coconut dataset and training a detection model to recognize different coconut parts. The images you provided show the model's inference results but unfortunately it looks like the model is struggling to accurately detect the coconut parts.

It's great that you've experimented with different epochs, batch sizes, and hyperparameters, but there could be several other factors affecting the model's performance. Some suggestions to consider improving the mAP and class detection are:

  1. Increase the size of the dataset by adding more diverse images and ensuring each class has enough representatives.
  2. Check the label quality to ensure they closely enclose each object.
  3. Train for more epochs if overfitting is not an issue.
  4. Check the dataset balance to ensure the classes are represented equally.

If you haven't already, I'd recommend taking a look at the YoloV5 Documentation for detailed examples and best practices on creating custom datasets and training YOLOv5 models.

Good luck 🍀 and let us know if you have any other questions!

gulati-parth commented 7 months ago

The default settings have nc (number of classes) listed as 80. Is there a specific reason for that/should we change it to our class number?

glenn-jocher commented 7 months ago

@gulati-parth yes, the default setting of nc=80 corresponds to the number of classes in the COCO dataset, which YOLOv5 models are pre-trained on. When you are training on your custom dataset, you should definitely change nc to match the number of classes in your dataset. This is crucial for the model to correctly learn and predict your specific classes.

For example, if your dataset has 5 classes, you would set nc=5 in your dataset's YAML file. This ensures the model's final layer is correctly configured to predict your dataset's classes.

Good luck with your training! 🚀 Let us know if you have any more questions.

parth-gulati commented 7 months ago

@gulati-parth yes, the default setting of nc=80 corresponds to the number of classes in the COCO dataset, which YOLOv5 models are pre-trained on. When you are training on your custom dataset, you should definitely change nc to match the number of classes in your dataset. This is crucial for the model to correctly learn and predict your specific classes.

For example, if your dataset has 5 classes, you would set nc=5 in your dataset's YAML file. This ensures the model's final layer is correctly configured to predict your dataset's classes.

Good luck with your training! 🚀 Let us know if you have any more questions.

Thank you so much!!

glenn-jocher commented 4 months ago

@parth-gulati you're welcome! If you need further assistance or have more questions as you progress, feel free to reach out. Happy training! 🚀