Installation and Environment Creation
Official installation reference: Installing conda - conda documentation
Download link: Download anaconda
You can download Miniconda and set up environments manually as needed.
Create a running environment:
| |
Activate the environment:
| |
Installing PyTorch
For the CPU version, use this command directly:
| |
For the GPU version, visit the official site at https://pytorch.org/get-started/locally/ to get the installation command.
Check your CUDA version using:
| |
After installation, verify if it’s working:
| |
Labeling Images
For small local datasets, you can use labelImg. Install it via pip:
| |
Then open the GUI using:
| |
Remember to select your image path and label save directory, and switch the data format to YOLO.
Press W (uppercase) to create a new annotation.
Training the Model
YOLO26 Official Documentation: Ultralytics YOLO26
Install YOLO:
| |
Training code:
| |
Data configuration file data.yaml:
| |
Training Outputs
Once training is complete, outputs are generated in runs/detect.
Inside the weights/ folder are the model files:
best.pt: Weights with the highest accuracy.last.pt: Weights from the final epoch.
Charts:
results.png: Combines training loss and accuracy metrics (mAP).- If the curve is still rising, the model is still learning; if it plateaus, the model has converged.
confusion_matrix.png: Shows the probability of the model mistaking objects for background or other classes.- The brighter the diagonal, the more accurate the recognition.
Box*_curve.png: Represents Precision, Recall, and their balance curves.labels.jpg: Statistics for all annotations, showing box size distribution and class ratios.
Image Annotations:
train_batch*.jpg: Specific images used by the model during training.val_batch*_labels.jpg: Labeled images used for validation.val_batch*_pred.jpg: Model prediction results.
Other Files:
args.yaml: All parameter settings for this training run, useful for reproduction.results.csv: Raw data for theresults.pngchart.
Using the Model
| |
Modifying the Model
In your conda environment, run the following command to find the YOLO installation location:
| |
However, this method will fail if you update the library. You can download the official source code locally instead.
Download address: ultralytics/ultralytics
Then, in the project root directory, use pip to load the library in editable mode:
| |
This way, your changes will be synchronized.