ultralytics / yolov5

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

FLIR THermal Dataset for ADAS #6301

Closed abhimanyuiris96 closed 2 years ago

abhimanyuiris96 commented 2 years ago

Search before asking

Question

I am trying to finetune yolov5x to the FLIR thermal dataset for ADAS and while the training starts out good, it gets stuck halfway through and then shows no improvement at all. Any suggestions for hyperparameter tuning or configurations that I could try?

Link to the dataset:- https://www.kaggle.com/deepnewbie/flir-thermal-images-dataset

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @abhimanyuiris96, 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 Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.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

CI CPU testing

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

glenn-jocher commented 2 years ago

@abhimanyuiris96 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results. The below recommendations should work well for your FLIR dataset.

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!

iceisfun commented 2 years ago

I was able to train it fine using yolov5s batch size 30 epochs 20

     Epoch   gpu_mem       box       obj       cls    labels  img_size
     19/19     6.11G   0.03771   0.03979  0.003014       110       640: 100%|██████████| 235/235 [00:27<00:00,  8.51it/s]                                                           
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|██████████| 41/41 [00:02<00:00, 14.15it/s]                                             
                 all        814       7102      0.854      0.769      0.849      0.451
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 ⭐!

rdabane commented 1 year ago

I was able to train it fine using yolov5s batch size 30 epochs 20

     Epoch   gpu_mem       box       obj       cls    labels  img_size
     19/19     6.11G   0.03771   0.03979  0.003014       110       640: 100%|██████████| 235/235 [00:27<00:00,  8.51it/s]                                                           
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|██████████| 41/41 [00:02<00:00, 14.15it/s]                                             
                 all        814       7102      0.854      0.769      0.849      0.451

@iceisfun , Could you please paste here the details of fine tuning here .. especially lr etc .. or the command you used .. Thanks.

glenn-jocher commented 1 year ago

Hello @rdabane, It seems like @iceisfun was able to train their model fine using yolov5s batch size 30 epochs 20. Regarding the details of fine-tuning, we would need more information from @iceisfun such as the command used and learning rate (lr) to provide more insight. Could you please wait for their response? Thank you.

rdabane commented 1 year ago

@glenn-jocher , Thanks for your quick update. I'll look out for the @iceisfun response. Thanks.

glenn-jocher commented 1 year ago

Hello @rdabane,

Thank you for your prompt response. We will await @iceisfun's reply regarding the details of their fine-tuning process, in order to provide more information.

If you have any other questions or concerns, please feel free to ask. We're here to help.

Best regards,

elmonkey commented 1 year ago

Hi.

I was able to finetune the yolov5 object detector using flir's thermal dataset. Hopefully, this blurb can save people some time.

First, the trick is having the dataset in the right YOLOv5 format (annotations) and directory structure.

The high level description of what I did:

  1. get the dataset from: https://adas-dataset-v2.flirconservator.com/#downloadguide

  2. convert the dataset from COCO to YOLOv5 (I used globox --- there might be other methods like roboflow - idk)

    • run on train, validation, and test task. I like having /images/.jpg and /labels/.txt, else you have to make other unnecessary changes to YOLO to make sure things work well (where to find the annotations)
# from globox
from globox import AnnotationSet

# load annotations
coco = AnnotationSet.from_coco(file_path=input_path) 
# display stats
coco.show_stats()

# SAVE TO YOLOv5
coco.save_yolo_v5(
    save_dir = <output_path>,
    label_to_id={
        "person": 0,
        "car": 1,
        ... etc
    }
)

The data.yaml:

train: $YOLOv5/images_thermal_train/images
val: $YOLOv5/images_thermal_val/images
test: $YOLOv5/video_thermal_test/images
nc: <N>
names: 
    0: 'person'
    1:  'car'
    ...  etc

remember to correctly set the data.yaml file

  1. Modified ultralytics yolov5 notebook to fine-tune yolov5L-pretrained weights using batchsize=32, imsize=480, and I get nice detections after 10 epochs. You will need to modify and/or create a yolov5/data/hyps/.yaml file with things like:
    
    ...

lr0: 0.012 lrf: 0.115 ... etc.



4. Inspect the input data and results. I like using supervision detection datasets (by the roboflow ppl), but the latest ultralytics pkg has nice visualization (usually saved under the `runs` folder)

Good luck,
glenn-jocher commented 1 year ago

@elmonkey hi,

Thank you for sharing your experience and providing some helpful tips for fine-tuning YOLOv5 with FLIR's thermal dataset. It's great to hear that you were able to successfully convert the dataset from COCO to YOLOv5 format using globox. It seems like a useful tool for converting annotations.

Organizing the dataset with the correct directory structure and creating the data.yaml file with the appropriate paths and class names are crucial steps, and it's good that you mentioned them.

Modifying the ultralytics yolov5 notebook and creating a hyps file for setting hyperparameters is also important to achieve good results during fine-tuning. It's nice that you were able to obtain satisfactory detections after ten epochs with a batch size of 32 and image size of 480.

Inspecting the input data and results is essential for evaluating the performance of the model, and it's helpful that you mentioned utilizing supervision detection datasets and the visualization capabilities in the latest ultralytics package.

Thank you once again for sharing your insights and tips. Good luck with your further experiments!