Machine Learning Notes - Training YOLOv5 Object Detector on Vehicles Dataset

One, yolov5 source code download 

https://github.com/ultralytics/yolov5 https://github.com/ultralytics/yolov5

         The diagram below shows five YOLOv5 variants, starting with the most tiny YOLOv5 nano model built to run on mobile and embedded devices, and ending with the YOLOv5 XLarge at the other end. We will use the base model YOLOv5s here, which provides a good balance between accuracy and speed.

2. Download the dataset

        The dataset contains only 627 images of various vehicle classes for object detection, such as Car , Bus , Ambulance , Motorcycle , and Truck . The images are from the Open Images open source computer vision dataset.

        Dataset webpage address, this website is still a very good collection of datasets, it is worth exploring, and it is recommended to use the following two methods to download.

Vehicles-OpenImages Object Detection Dataset Download 627 free images labeled with bounding boxes for object detection. https://public.roboflow.com/object-detection/vehicles-openimages         1. You can use the following command to download

        2. You can also download directly from Baidu network disk

链接:https://pan.baidu.com/s/1qa5iI9-uBhYGzp7BMPx0rw?pwd=cpgi 
提取码:cpgi

3. Prepare for training

        Be careful not to put it in the Chinese path.

1. Prepare data

        Create data.yml, which can be placed in the data directory

path: 'vehicles'
train: 'train'
val: 'valid'
nc: 5
names: ['Ambulance', 'Bus', 'Car', 'Motorcycle', 'Truck']

2. Training hyperparameters and model configuration

        YOLOv5 has around 30 hyperparameters for various training settings. These are defined in hyp.scratch-low.yaml for low-augmentation COCO training from scratch, placed in the /data directory. The training data hyperparameters are shown below, which are important to produce good results, so make sure to initialize these values ​​correctly before starting training. For this tutorial, we will simply use the default values, optimized for YOLOv5 COCO training from scratch.

3. Run the train.py script

        The yolov5s.pt file will be downloaded by default. If the download is slow, you can download it manually and put it in the root directory.

        The directory structure is as follows.

         Start training, and the save location will be prompted after the run is complete.

 4. Run the verification script

        Mainly modify two parameters, one is data.yaml, and the other is the path of best.pt obtained after training.

parser.add_argument('--data', type=str, default=ROOT / 'data/data.yaml', help='dataset.yaml path')
parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'runs/train/exp19/weights/best.pt', help='model path(s)')

4. Code download

ml_toolset/Case 102 Using yolov5 to train vehicles dataset at main bashendixie/ml_toolset GitHub Contribute to bashendixie/ml_toolset development by creating an account on GitHub. https://github.com/bashendixie/ml_toolset/tree/main/%E6% A1%88%E4%BE%8B102%20%E4%BD%BF%E7%94%A8yolov5%E8%AE%AD%E7%BB%83vehicles%E6%95%B0%E6%8D%AE%E9% 9B%86

5. Other references

Machine Learning Notes - Using pytorch + yolov5 to train custom datasets https://skydance.blog.csdn.net/article/details/122563689

Guess you like

Origin blog.csdn.net/bashendixie5/article/details/127234323