A Step-by-Step Guide to Running YOLOv8 on Windows

New Terra
4 min readSep 21, 2023

--

Part 1

Introduction

YOLO (You Only Look Once) is a popular real-time object detection algorithm that has evolved over the years. YOLOv8 is one of the latest iterations of this algorithm, known for its speed and accuracy. In this article, we will walk you through the process of setting up YOLOv8 on a Windows machine step by step.

Step 1: Preparing Your Environment

The first step in running YOLOv8 on Windows is to set up a dedicated environment. We will use Anaconda for this purpose. Open your Anaconda terminal or command prompt and follow these commands:

# Create a new environment named YOLOv8Env
conda create -n YOLOv8Env
# Activate the new environment
conda activate YOLOv8Env
# Install Ultralytics version 8.0.0
pip install ultralytics==8.0.0

Note: I chose to name the environment YOLOv8Env, you can name it whatever you want.

Step 2: Installing PyTorch

YOLOv8 relies on PyTorch as its deep learning framework. Ensure you have PyTorch installed by running the following commands:

# Launch the Python interpreter
python
# Check if PyTorch is available
import torch
exit()

If PyTorch is not available, you can visit the [PyTorch website](https://pytorch.org) to download and install the stable version for your system. Make sure to follow the installation instructions specific to your configuration.

https://pytorch.org/ Pick the stable version. | Run that in anaconda prompt
# install using
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

Step 3: Running YOLOv8

Now that you have set up your environment and installed the necessary dependencies, you can run YOLOv8. Here’s an example of running YOLOv8 on an image:

Before running the following code this is the image.jpg
# Navigate to the folder containing YOLOv8-related files
cd path_to_your_YOLOv8_folder
# Run YOLOv8 to detect objects in an image
yolo task=detect mode=predict model=yolov8n.pt source=image.jpg
D:\Folder\YOLOv8\Implementation\runs\detect\predict This is the output of the prediction after we run it.

This command will download the YOLOv8 model if it’s not already available and perform object detection on the specified image. You will see the detection results in the console output.

Step 4: Viewing the Results

After running YOLOv8, you can find the results of the object detection task in the “runs/detect/predict” folder within your YOLOv8 project directory. The detected objects will be outlined in the image, and a summary of the detection will be displayed in the console.

(YOLOv8Env) D:\GitHub\YOLOv8\Implementation>yolo task=detect mode=predict model=yolov8n.pt source=image.jpg
Ultralytics YOLOv8.0.0 Python-3.10.7 torch-2.0.1+cpu CPU
Downloading https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt to yolov8n.pt...
100%|██████████████████████████████████████████████████████████████████████████| 6.23M/6.23M [00:00<00:00, 29.4MB/s]

Fusing layers...
YOLOv8n summary: 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs
image 1/1 D:\GitHub\YOLOv8\Implementation\image.jpg: 448x640 10 persons, 1 bus, 2 traffic lights, 2 backpacks, 2 handbags, 108.1ms
Speed: 1.0ms pre-process, 108.1ms inference, 2.5ms postprocess per image at shape (1, 3, 640, 640)
Results saved to runs\detect\predict

Step 5: Trying YOLOv8 on Videos

You can also use YOLOv8 to detect objects in videos. Here’s an example:

Prediction for the Demo video
# Run YOLOv8 to detect objects in a video
yolo task=detect mode=predict model=yolov8n.pt source=demo.mp4

Running this command will create a second prediction folder under the “runs” directory, where you will find the processed video with object detection annotations.

under the runs, folder will give me a second prediction folder, that is where the new video will be.

Conclusion

Congratulations! You’ve successfully set up and run YOLOv8 on your Windows machine. This powerful object detection algorithm can be used for a wide range of applications, from image analysis to video processing. Experiment with different datasets and configurations to explore it’s full potential.

For a visual demonstration of YOLOv8 in action, check out the following videos:

Demo video
After the prediction is ran

Happy object detection with YOLOv8!

If you want to know more about me, feel free to connect with me on LinkedIn

--

--

New Terra

I'm Pat Guillen, founder of New Terra. Exploring new frontiers in gaming and real-world challenges