Table of Contents
💡Tip
Windows | Mac | Linux |
---|---|---|
Download | Download | Download |
Search for Environment Variables
in your system settings.
Click on Environment Variables
.
Under System Variables, select Path
and click Edit.
Click New and add the following environment variable paths:
Launch Anaconda Navigator.
At the bottom of the interface, click Create to add a new environment.
In the Create New Environment dialog, configure the environment as follows:
YOLOv8
C:\User\Ryan\envs\YOLOv8
Ryan
with your actual Windows username if different)3.10.16
Select the newly created YOLOv8
environment and click Open Terminal.
You should now see the terminal window for the environment.
Steps 6~10
can be skipped by using the following commands:
- Open Windows Command Prompt (in Windows 11 it's renamed to Windows Terminal; we will refer to it as
Windows Command
here).- Create the environment with the following command:
conda create --name <environment_name> python=<python_version>
Example:
- To activate the environment, use:
- Once the environment is activated successfully, your terminal should look like this:
Note
Be sure to select the correct version of your operating system.
This guide uses Windows 11 as an example.
Open the section titled Download cuDNN v8.9.7 (December 5th, 2023), for CUDA 11.x
, and select the file as shown in the red box.
You must sign in to your NVIDIA Account to download.
If you don’t have one, please register in a new tab.
After downloading, you will get the file:
cudnn-windows-x86_64-8.9.7.29_cuda11-archive.zip
Locate the following path:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
Extract the contents of the ZIP file and copy the following folders into the CUDA directory above:
bin
include
lib
These should be merged into the corresponding folders inside C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
.
If successful, you will see an output like the following:
nvcc
) is properly installed:7-Zip
, the YOLOv8
repository, and the pretrained YOLOv8n.pt
model.😁 Reminder
Please download the following files from the provided links before proceeding.
7-Zip
: LinkYOLOv8
repository: LinkYOLOv8n.pt
model: LinkInstall 7-Zip
.
To verify the installation, right-click on any file and check if the 7-Zip
menu appears as shown below:
Extract the YOLOv8-main.zip
file using 7-Zip
or another archive tool.
After extraction, you may rename the folder to YOLOv8
and place it in a directory of your choice.
For example:
💡Tip
In this tutorial, we use D:\
as the example directory path.
Move the yolov8n.pt
model file into the YOLOv8
folder.
In the command line inside the YOLOv8
folder, run the following command to install the Ultralytics
package:
Visit the official PyTorch website to find the appropriate version for your environment.
In the Windows Command Prompt, change the directory to your YOLOv8 project folder:
3. Install PyTorch using the following command:
🚨 Note
Replace pip3
with pip
.
4. If this version does not work for your system, visit the Previous PyTorch Versionspage to find a suitable one.
Component | Specification |
---|---|
Running environment | System: Windows 11 Pro, CPU: Intel Core i9-12900K, RAM: 16GB * 2 (32GB), GPU: NVIDIA GeForce RTX 3090 |
Visual Studio Code | Sep 2024 (version 1.94) |
Environment management | Conda 24.9.0 |
Python | Version 3.10.16 |
Use the following command to install all necessary packages.
Ensure the environment matches exactly before using requirements.txt
.
For converting videos recorded from various platforms (Windows, iOS, Android) into a unified MP4 format, use the Batch-Video-Converter tool.
Unzip Batch-Video-Converter-main.zip
and rename the folder to Batch-Video-Converter
.
When prompted with Enter the input directory containing videos:
, enter the path of the folder containing the videos to convert.
When prompted with Enter the output directory for converted MP4 videos:
, enter the desired output path.
output
will be created inside the input directory.When asked Do you want to keep audio in the converted videos? (Y/N, default: N):
, input Y
to retain audio, or N
to remove it (default is N
).
To simplify the labeling process for beginners, Video-Frame-Extractor helps convert videos into image sequences.
Download and unzip the archive, then rename the folder to Video-Frame-Extractor
.
Run the extractor:
3. You'll be prompted to enter:
60
FPS is common)0
.labelimg
.
4. Launch the application:
5. The following window should appear:
6. Use Open Dir to label images in a folder or Open File for a single image.
7. After opening the folder, thumbnails appear in the bottom right, and the current image appears in the center.
8. In the top-left menu, enable Auto Save Mode under the View (V) tab.
9. Set the annotation mode to YOLO format.
10. Click Create RectBox to start labeling.
11. Use the cursor (displayed as a cross) to draw bounding boxes.
12. For custom labels like Helmet
or Coverall
, manually enter and confirm them.
🚨 Note
You must finish labeling all objects in one image before moving to the next. You cannot return to previous images.
13. All labeled items will appear in the box list on the right side.
📌 Pro Tip
- Path: D:\labelImg\data
。
- File: predefined_classes.txt
。
- Add label names to this file for quick label access during annotation.
This means frame_0000.png
was labeled and saved as frame_0000.txt
.
16. You are now in “Annotation Mode”! Already used labels will auto-complete from the menu.
🌐 Resources
For public datasets, consider RoboFlow 官網 and Kaggle 官網. Be sure to cite original authors.
🔍 Basic Prediction Test
Run the following command to test the model with a sample image:
:::spoiler Dataset Structure [Expand]
YOLOv8
└─dataset
│ ├─test
│ │ ├─images
│ │ │ ├─test_img001.jpg
│ │ │ ├─test_img002.jpeg
│ │ │ ├─test_img003.png
│ │ │ └─test_img004.tif
│ │ └─labels
│ │ ├─test_img001.txt
│ │ ├─test_img002.txt
│ │ ├─test_img003.txt
│ │ └─test_img004.txt
│ ├─train
│ │ ├─images
│ │ │ ├─train_img001.jpg
│ │ │ ├─train_img002.jpeg
│ │ │ ├─train_img003.png
│ │ │ └─train_img004.tif
│ │ └─labels
│ │ ├─train_img001.txt
│ │ ├─train_img002.txt
│ │ ├─train_img003.txt
│ │ └─train_img004.txt
│ └─valid
│ ├─images
│ │ ├─valid_img001.jpg
│ │ ├─valid_img002.jpeg
│ │ ├─valid_img003.png
│ │ └─valid_img004.tif
│ └─labels
│ ├─valid_img001.txt
│ ├─valid_img002.txt
│ ├─valid_img003.txt
│ └─valid_img004.txt
└─data.yaml
:::
data.yaml
FileInside your YOLOv8
directory, create a file named data.yaml
.
Example structure:
📝 Parameter Descriptions
train
: Path to the training set.val
: Path to the validation set.test
: Path to the test set.nc
: Number of classes.names
: Class names in order.0
corresponds to Helmet
, 1
to Coverall
.A label file (frame_0000.txt
) may look like this:
📝 Explanation
first
value is the class ID (e.g., 16
, 15
).<x_center> <y_center> <width> <height>
Use the following command to begin training:
Training Logs
YOLOv8 will:
train
, val
, and test
folders📝 Training Metrics
Epoch
: Current training round.GPU mem
: GPU memory usage.box loss
: Bounding box regression loss.cls loss
: Classification loss.dfl loss
: Distribution focal loss (YOLOv8-specific).Instances
: Number of objects processed in current batch.📝 Validation Metrics
Size
: Input image size.Class
: Number of detected classes.Images
: Number of images in validation batch.Box (P)
: Precision score.R
: Recall score.mAP50
: Mean Average Precision at IoU 0.50.mAP50-95
: Average precision across IoU thresholds from 0.50 to 0.95.After training, two model files will be generated:
💭 Model Descriptions
best.pt
:last.pt
:Use the trained model to make predictions:
📝 Inference Parameters Explained
model
: Path to model checkpoint
best.pt
or last.pt
)epochs
: Epoch count for further training (ignored in prediction mode)imgsz
: Image resolution (e.g., 640
, 1280
)conf
: Confidence threshold
conf=0.25
will filter out predictions below 25% confidence.device
: Device to use for prediction
0
= first GPU, cpu
= CPU, mps
= Apple Silicon GPUsource
: Input source
0
= webcamimages/sample.jpg
= single imagevideos/sample.mp4
= video filesave
: Whether to save output images/videos
True
= save output to /runs/
False
= do not saveshow
: Display results in a pop-up window
True
= show predictionFalse
= headless modeThis YOLOv8 tutorial and deployment guide was authored and refined by Yu-Cheng Chang (張育丞), as part of a structured effort to document the full setup, training, and inference process of an object detection system using Ultralytics YOLOv8.
The motivation behind this guide stems from real-world needs in dataset preprocessing, efficient model training, and reproducible development pipelines. The tutorial was developed in an engineering-research context, especially focusing on:
This document serves not only as technical guidance but also as a reproducible lab notebook — one that balances accessibility and precision.
Version | Date | Description |
---|---|---|
1.0 | Jan 01, 2025 | Initial draft created |
2.0 | Jan 15, 2025 | Added CUDA and cuDNN setup instructions |
3.0 | Jan 20, 2025 | Integrated video conversion pipeline |
3.1 | Jan 22, 2025 | Updated video frame extraction documentation |
4.0 | Jan 26, 2025 | Added labeling tool (labelImg) tutorial |
5.0 | Feb 03, 2025 | Integrated YOLOv8 training guide |
5.1 | Feb 17, 2025 | Added YOLO-Class-ID-Replacer explanation |
6.0 | Mar 07, 2025 | Organized complete data.yaml usage details |
6.1 | Mar 22, 2025 | Revised training metrics and evaluation logs |
7.0 | Apr 16, 2025 | Added inference demo and explanation |
8.0 | May 04, 2025 | Finalized English version for GitHub release |
This content is licensed under the MIT License
. See the LICENSE for details.
Contributions or feedback are welcome!
Please feel free to contact me via email for any suggestions or inquiries.