Back to Index

Deploy YOLO v8 and train datasets on Windows PC

This document records every step of locally deploying a YOLO v8 system on a Windows PC, building a dataset, and training it.

Part A. Environment set up and architecture design

Following dependecies are required for running YOLO v8: You are required to follow a sequence to conduct installation.

1. Configuring the Conda Environment

Conda comes in two flavors: Miniconda and Anaconda . The difference is that Miniconda ships only the bare-minimum Python packages on first install, whereas Anaconda is ready to go out of the box for basic data-processing work and comes with the visual Navigator tool for managing environments. This guide will use Miniconda for the installation walkthrough.

1.1 Installation

You can download from official website and choose the right version (Windows x64) of installation wizard, just follow the steps it prompted. Make sure you have adequate disk volume and install it at default location, this action could prevent unnecessary troubles.

1.2 Create virtual environment and start using

Once installation succeeds, you'll find Anaconda Prompt and Anaconda Powershell Prompt in your search bar, which means conda has been installed. Launch either one, and if you see (base) appear before the working directory in the terminal, conda is running correctly.


conda create -n yolov8 python=3.8
      
This creates a virtual environment named yolov8 and pins the Python version to 3.8. This will be the virtual environment used for YOLO training; always pin the version to avoid dependency conflicts.

conda activate yolov8
      
Run this command to activate the virtual environment. When the prompt prefix changes from (base) to (yolov8) , the environment is active. Make sure every operation from here on is performed with this environment activated!

2. Installing PyTorch

Check your runtime environment: before installing PyTorch, confirm your platform's hardware setup. If you're training on an Nvidia GPU, you need to check the CUDA version:


nvidia-smi
      
Run this command in the terminal to view your Nvidia GPU info. The CUDA version shown in the first row of the table is your CUDA version. You usually shouldn't install the very latest version of PyTorch. Open the previous versions page on the official site and pick a PyTorch version that's at or below your current CUDA version. If you don't have a GPU, choose the CPU-only version instead.

The install command should look something like:


pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu124
      

Note: This case usually applies if you live in a country that conducting state-wide connection blocking, such as the People's Republic of China:

Sometimes you are not able to connect to the server of PyTorch, you can use network proxy to access. If you use Clash as a system proxy, configure it properly so international connections aren't interrupted mid-transfer. Clash's default port is 7897, so append `--proxy http://127.0.0.1:7897` to the command to route the connection through the proxy:


pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu124 --proxy http://127.0.0.1:7897
      

3. Installing Ultralytics (YOLO v8)

Managing your project structure carefully pays off later when using and migrating it. Pick a location to store your Ultralytics system, for example E:\.

3.1 Project Structure and Installation

There are several ways to install Ultralytics. Building from source lets you flexibly modify config files down the line.

On the GitHub page , download the .zip archive and extract it wherever you like. This folder will become the project's root directory. Once extracted, enter the folder and build from source:


cd ultralytics-main
pip install -e .  
      

At this point the Ultralytics core is installed, but a few dependencies are still missing. The requirements file for YOLO v8 lives in the very first release. Open the initial v8.0.4 release page and download requirements.txt into ultralytics-main:


pip install -r requirements.txt
      

Run the command above to install all dependencies listed in requirements.txt, which completes the full Ultralytics installation.

The root directory must contain a datasets folder for storing datasets. Run:


mkdir datasets
      

3.2 Downloading a Model

To use a YOLO v8 model, head to the Ultralytics docs, find YOLO v8, and download the .pt pretrained model file you need.

Optional: For easier model-file management, create a .pt folder under ultralytics to store your pretrained model files.

At this point your project structure should look something like:


/ultralytics-main/
├── datasets/
├── ultralytics/
│   ├── assets
│   ├── cfg
│   ├── engine
│   ├── pt
│   │	└── _model_name.pt
│   └── ...
└── ...
      

Part B. Building a Dataset

Assuming you already have your images and annotation data, you need to export them into a format YOLO supports. After exporting, you should have a .txt annotation file corresponding one-to-one with each image file. Now you can start creating a dataset.

Under ultralytics-main/datasets, create a folder with a name of your choosing to hold the data for a single training project. We'll use `data1` as an example:


cd E:\ultralytics-main\datasets
mkdir data1
cd data1
      

Inside that folder, create two folders named train and val, and within each create images and labels folders. train holds the training data and val holds the validation data, with the data stored separately as images and label files. Be sure that when you split the training and validation sets, the image files and annotation files correspond one-to-one.

At this point the project structure should look something like:


/ultralytics-main/
├── datasets/
│   └── data1
│   	│── train
│   	│	├── images
│   	│	└── labels
│   	└── val
│   		├── images
│   		└── labels
├── ultralytics/
│   └── ...
└── ...
      

Part C. Training the Data

1. Writing the Description File

The description file is a .yaml file placed in the dataset path (which should now be /ultralytics-main/datasets/data1/). For different training objectives, look up the corresponding identifier in the official docs, find the template stored in /ultralytics-main/ultralytics/cfg/datasets/, modify it, and save it to your designated path (never edit the template directly—copy it to the target path first, then make your changes).

The categories in the description file must be filled in strictly in order. This information is also exported when you export the annotation files; for example, ISAT stores the category file as classes.txt in the export folder.

2. Training Command / Script

YOLO training can be launched either via command or a Python script. When running the command, make sure the terminal is working from the root directory; the Python script should likewise be placed in the root directory.

For parameter settings, refer to the official docs. Example command:


yolo task=segment mode=train model=./ultralytics/pt/yolov8n-seg.pt data=./datasets/data1/config.yaml workers=1 epochs=50 batch=16
      
A script achieves the exact same result:

from ultralytics import YOLO

# Load model
model = YOLO('ultralytics/pt/yolov8n-seg.pt')
# Train the model
model.train(data='datasets/data1/config.yaml', workers=1, epochs=50, batch=16)
      
And with that, you've completed the full YOLO v8 training workflow.