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

mAP is too low and val obj_loss is increasing while training is decreasing #7384

Closed sarmientoj24 closed 2 years ago

sarmientoj24 commented 2 years ago

Search before asking

Question

I have a YOLOv5 run that involves small number of annotated dataset.

The mAP is too small, about 0.08 and the val obj_loss is increasing while the training is not. What could be the potential reason why obj_loss is increasing for validation? Anything that stands out as wrong from the config?

image

Configs

# hyp-low
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.20
anchor_t: 4.0
# anchors: 3
fl_gamma: 0.0
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
degrees: 0.0
translate: 0.1
scale: 0.0
shear: 0.0
perspective: 0.0
flipud: 0.0
fliplr: 0.5
mosaic: 1.0
mixup: 0.0
copy_paste: 0.0
# Modified augmentations
            T = [
                A.ImageCompression(quality_lower=75, p=0.2),
                A.RandomBrightnessContrast(
                    brightness_limit=0.1, contrast_limit=0.1, p=0.3
                ),
                A.OneOf(
                    [A.Blur(blur_limit=3, p=1.0), A.MedianBlur(blur_limit=3, p=1.0)], p=0.25
                ),
                # A.GaussNoise(var_limit=(0.0001, 0.0005), per_channel=False, p=0.1),
                A.OneOf([A.Sharpen(), A.Emboss()], p=0.25),
                # A.ToGray(p=0.1),
                A.CLAHE(p=0.25),
                A.ShiftScaleRotate(
                    shift_limit=0.0625, scale_limit=0.2, rotate_limit=25, p=0.15,
                ),
                A.OneOf(
                    [
                        A.RandomSizedBBoxSafeCrop(width=1280, height=768, p=1.0),
                        A.RandomSizedCrop([320, 720], 768, 1280, p=1.0)
                    ], p=0.15
                ), 
                A.Resize(width=1280, height=768, always_apply=True, p=1)
            ]  # transforms

Command

train.py --hyp data/hyps/hyp.scratch-low.yaml --data data.yaml --img 1280 --rect --epochs 200 --weights VisDrone/VisDrone2/weights/best.pt --project PAVE --name BATCH1_EXP3_Vis_PT --batch-size 16 --cache --workers 8 --device 1

Sample bbox debuger image

I actually also tried validating using the train images in the validation set just to check and it loooks quite good.

               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 59/59 [00:35<00:00,  1.64it/s]          
                 all       1859       7131      0.922      0.817      0.894      0.598
                 D01       1859        445      0.966      0.905      0.951      0.605
                 D03       1859        368      0.951      0.842      0.945       0.64
                 D04       1859       1115      0.928      0.868      0.933      0.686
                 D06       1859       3252      0.972        0.9      0.964      0.663
                 D11       1859        655      0.883      0.656      0.751      0.468
                 D12       1859       1063      0.901      0.821      0.876      0.569
                 D13       1859        233      0.853      0.725      0.838      0.557

Additional

No response

glenn-jocher commented 2 years ago

@sarmientoj24 πŸ‘‹ 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!

sarmientoj24 commented 2 years ago

labels.jpg image

P_curve image

Losses image

PR_curve image

F1_curve image

Confusion Matrix image

glenn-jocher commented 2 years ago

@sarmientoj24 πŸ‘‹ 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!

sarmientoj24 commented 2 years ago
Verify labels. View train_batch*.jpg to verify that your labels appear correct, i.e. see [example](https://docs.ultralytics.com/yolov5/tutorials/train_custom_data#local-logging) mosaic.

I am actually not getting train_batch*.jpg

glenn-jocher commented 2 years ago

@sarmientoj24 train_batch*.jpg are created in your runs/exp/train directory on training start. First 3 batches are saved after they run.

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 ⭐!

fatejzz commented 2 years ago

Sorry to bother you, have you ever solved this problem since I also have this question.

ruman1609 commented 1 year ago

Try do geometrical augmentation (rotate 90Β°, flipping, etc.).

After that when you training your data, please set shuffle parameter in dataloader to True.

in my case it really help, my validation mAP become 72% right now.

glenn-jocher commented 1 year ago

@ruman1609 yes, applying geometric augmentations such as rotation, flipping, and other transformations can help improve the training performance of YOLOv5. These augmentations can increase the variety and diversity of the training data, leading to better generalization capabilities.

Additionally, setting the shuffle parameter in the dataloader to True can also contribute to better results. Shuffling the training data ensures that the model is exposed to a diverse range of samples throughout the training process, preventing any bias or pattern that may exist in the data from affecting the model's performance.

By incorporating these techniques, you were able to achieve an impressive validation mAP of 72%. Keep in mind that the effectiveness of these strategies can vary depending on the specific dataset and problem you are working on, so it's always recommended to experiment and fine-tune these parameters based on your specific requirements.

Best regards