Welcome to ROSMASTER M3 repository
05.YOLOv11 Model Training
YOLOv11 Model Training
YOLOv11 Model Training1. Course Content2. Pre-trained Models3. Training Traffic Sign Recognition Model (Case 1)3.1 Start Training4. Training Lane Detection Model (Case 2)5. Model Validation5.1 Test Traffic Sign Recognition Model5.2 Test Lane Detection Model6. Source Code Analysis6.1 YOLOv11 Training Program6.2 Test Model Program
[!IMPORTANT]
- The factory image already contains pre-trained traffic sign recognition models. This section tutorial is provided for users who need to train YOLOv11 object detection models themselves and master model training methods.
- If you want to experience the complete functionality directly, you can skip this section!!!
- If using the dataset in the factory image to train the model, you need to unzip the .zip format dataset compressed package first.
1. Course Content
- Master the method for training YOLOv11 object detection models.
2. Pre-trained Models
- The factory image already contains pre-trained traffic sign recognition models and lane detection models. The paths are as follows:
- yolo11n.pt base model
/home/jetson/MODELS/yolov11/yolo11n.pt
- Lane detection model path:
xxxxxxxxxx/home/jetson/MODELS/auto_drive/lane_V6_int8.engine- Traffic sign recognition model path:
xxxxxxxxxx/home/jetson/MODELS/auto_drive/sign_model.engine
3. Training Traffic Sign Recognition Model (Case 1)
The program path for training YOLOv11 object detection models: /home/jetson/yahboomM3_ws/yolo_train/train.py
Optional startup parameter descriptions:
- project: Training output folder, default is
./project - MODEL_PATH: YOLOv11 base model path, default is
/home/jetson/MODELS/yolov11/yolo11n.pt - epochs: Training rounds, the more rounds the better the recognition model effect, default is 100 rounds
- imgsz: Training image size, default is 640
- train_config: Configuration file path, used to describe dataset path and target categories
3.1 Start Training
- Here we use 50 training rounds as an example (it is recommended to train 100 rounds or more):
xxxxxxxxxxcd ~/yahboomM3_ws/yolo_trainxxxxxxxxxxpython3 train.py --epochs 50 --train_config=/home/jetson/yahboomM3_ws/yolo_train/train_sign/sign.yaml
- During the training process, the training duration and loss values for each round will be displayed

- Epoch: Current training round
- GPU_mem: GPU memory currently occupied by training
- box_loss: Bounding box regression loss value, measuring the difference between predicted boxes and ground truth boxes (position, size). The smaller the value, the more accurate the box positioning.
- cls_loss: Classification loss value, measuring the difference between predicted classes and ground truth classes. The smaller the value, the more accurate the classification.
- dfl_loss: Distribution focal loss, used to optimize bounding box regression accuracy, especially for small targets. The smaller the value, the more accurate the bounding box detail prediction.
- Instances 46: Total number of target instances contained in the current batch.
- Size 640: Input image size is 640x640 (YOLOv11 default training input size).
- After training is completed, the terminal will prompt the save path of the training output files

- In the output folder we can see the following contents
- weights: Trained model weight files
- .png: Score data during training process

4. Training Lane Detection Model (Case 2)
- The training method is the same as before
xxxxxxxxxxcd ~/yahboomM3_ws/yolo_train
- Start training
xxxxxxxxxxpython3 train.py --epochs 50 --train_config=/home/jetson/yahboomM3_ws/yolo_train/train_lane/lane.yaml --project './project2'Here the --project parameter specifies the folder for training output files, used to distinguish from the previous traffic sign recognition model. The path is set to './project2'. After training is completed, the model weight files will be saved in the path specified by the project parameter.
5. Model Validation
The program for testing the model and example images are located in the test folder of the auto_drive package. Use the following command to view the relevant content:
xxxxxxxxxxcd ~/yahboomM3_ws/code_ws/src/auto_drive/testls
[!NOTE]
The test folder in the auto_drive package contains test programs and test images for testing model effects, used to verify whether the trained model meets expectations. Among them, example_1.jpg is a lane image for testing the lane detection model; example_2.jpg is an image containing traffic signs for testing the traffic sign recognition model; test_model.py is the test program.
Optional startup parameters for test_model.py:
- MODEL_PATH: Path to the model weight file to be tested
- half: Whether to perform inference in FP16 half-precision mode to shorten inference time, default is True
- device: Device for model inference, default is cuda:0
- source: Image to be tested
5.1 Test Traffic Sign Recognition Model
- Replace MODEL_PATH with the actual model weight path output during training
- Select ./example_2.jpg for source
xxxxxxxxxxpython3 test_model.py --MODEL_PATH /home/jetson/yahboomM3_ws/yolo_train/project/train3/weights/best.pt --source ./example_2.jpg
5.2 Test Lane Detection Model
- Replace MODEL_PATH with the actual model weight path output during training
- Select ./example_1.jpg for source
xxxxxxxxxxpython3 test_model.py --MODEL_PATH /home/jetson/yahboomM3_ws/yolo_train/project2/train3/weights/best.pt --source ./example_1.jpg
- You can see that it correctly recognizes the left and right lane lines and displays the confidence of the detection boxes

6. Source Code Analysis
6.1 YOLOv11 Training Program
The program source code is located at /home/jetson/yahboomM3_ws/yolo_train/train.py
- Configuration parameters required during training are defined through the
argparselibrary, allowing parameters to be passed through the command line when running the script - During the training process, logs, loss curves, evaluation metrics (such as mAP), and model weight files (best.pt, last.pt, etc.) are automatically generated and saved in the directory specified by
--project.
ximport argparsefrom ultralytics import YOLOdef get_args(): ''' ''' parser = argparse.ArgumentParser() parser.add_argument('--project', default='./project', help='Project file output directory', type=str) parser.add_argument('--MODEL_PATH',default='/home/jetson/MODELS/yolov11/yolo11n.pt' ,help='原始模型权重文件路径Original model weight file path', type=str) parser.add_argument('--epochs', default=100, help='训练轮次Training rounds', type=int) parser.add_argument('--imgsz', default=640, help='图像大小Image size', type=int) parser.add_argument('--train_config', default='', help='配置文件路径Configuration file path', type=str) return parser.parse_args()if __name__ == "__main__": args = get_args() model = YOLO(args.MODEL_PATH) # Load a pretrained model results = model.train(data=args.train_config, epochs=args.epochs, imgsz=args.imgsz,project=args.project)#Start training
6.2 Test Model Program
The program source code is located at /home/jetson/yahboomM3_ws/code_ws/src/auto_drive/test/test_model.py
- Configuration parameters required for testing the model are defined through the
argparselibrary, allowing parameters to be passed through the command line when running the script half=True: Enable FP16 half-precision inference, which can significantly improve speed on GPUresult.show(): Is a convenient method provided by the Ultralytics library that directly displays the image annotated with detection boxes, classes, and confidence in a window
xxxxxxxxxxfrom ultralytics import YOLOimport argparsedef get_args(): parser = argparse.ArgumentParser() parser.add_argument('--MODEL_PATH',default='' ,help='模型文件路径', type=str)