Tutorial: Yolov8 in PyTorch

Tutorial: YOLO v8 in PyTorch

https://docs.ultralytics.com/quickstart/#install-ultralytics

Ultralytics YOLOv8 is a cutting-edge, state-of-the-art (SOTA) model that builds upon the success of previous YOLO versions and introduces new features and improvements to further boost performance and flexibility. Y

img

Documentation and Github

See the YOLOv8 Docs for full documentation on training, validation, prediction and deployment.

Also, you can visit the github repository: https://github.com/ultralytics/ultralytics


Installation of Yolov8

Ultralytics provides various installation methods including pip, conda, and Docker. Install YOLOv8 via the ultralytics pip package for the latest stable release or by cloning the Ultralytics GitHub repository for the most up-to-date version.

Requirement

Install necessary packages such as Python, Numpy, PyTorch, CUDA and more

For installations of requirements, read for more detail instructions

  • Python >=3.8

  • PyTorch>=1.8

  • opencv-python>=4.6.0

  • matplotlib>=3.3.0

1)Install Yolov8 via pip package

First, create a new environment for YOLOv8 in Anaconda Prompt.

  • e.g. $myENV$ = yolov8

You can also make an exact copy of the existing environment by creating a clone

  • If you already have an environment named py39, clone it as yolov8

Activate the environment and Install YOLOv8 with pip to get stable packages.

Also, install the latest ONNX

2)Install Yolov8 via pip package(numpy 1.26 ver.)

If There is an OpenCV DLL issue, follow the setup intructions below to configure your environment

(The DLL issue might be caused by an incompatible Numpy version[your numpy ver. numpy 2.x])

Check for YOLO Installation

After the installation, you can check the saved source code and libs of YOLOv8 in the local folder :

\USER\anaconda3\envs\yolov8\Lib\site-packages\ultralytics

Now, lets run simple prediction examples to check the YOLO installation.

In Anaconda Prompt, activate yolov8 environment.

Then, move directory to the working directory. Here, the result images will be saved.

  • Example: C:\Users\ykkim\source\repos\DLIP\yolov8\

Run a Detection Example

In the Anaconda prompt, type the following command to predict a simple image.

The result will be saved in the project folder \runs\detect\predict\

Example: C:\Users\ykkim\source\repos\DLIP\yolov8\runs\detect\predict\

Run a Segmentation Example

Predict a YouTube video using a pretrained segmentation model at image size 320:

The result will be saved in the project folder \runs\segment\predict\


Using YOLOv8 with Python : Example Codes

In the project folder, create a new python code file

  • Project Folder: \source\repos\DLIP\yolov8\

  • Activate yolov8 environment in Anaconda Prompt

A list of useful commands for YOLOv8

Example: Detection Inference

Read Doc of Prediction with YOLO for more examples

Download the dataset file and save in the project folder

You can download the COCO pretrained models such as YOLOv8n and more.

https://docs.ultralytics.com/datasets/detect/coco/

Inference one image

Create a new python source file in the project folder

  • Yolo8-Inference-Ex1.py

Inference of multiple images

Create a new python source file in the project folder

  • Yolo8-Inference-Ex2.py

For multiple input source images, you can copy bus.jpg as bus2.jpg.

Inference on Webcam stream

Create a new python source file in the project folder

  • Yolo8-Inference-Webcam-Ex3.py

Example: Train

Last updated

Was this helpful?