[Selected] Use YOLOv8 training model and inference pictures under Windows system
Article directory
Preface
Today we will discuss how to build a YOLOv8 environment for training and inference of target detection models. YOLOv8 is a powerful object detection algorithm with high accuracy and efficiency, suitable for various vision tasks. In this article, we will take you through the steps of environment construction, data preparation, model training, and how to use YOLOv8 to perform target detection tasks. Whether you are a computer vision researcher or an engineer, this blog will help you take the first step towards building great object detection applications. let's start!
YOLOv8 portal: https://github.com/ultralytics/ultralytics
1. Download YOLOv8 source code and environment construction
- Use git clone https://github.com/ultralytics/ultralytics.git to download the source code, or directly enter the YOLOv8 portal to download the source code compressed package;
- After decompression, use pycharm to open the source code. If you need to install the GPU version of pytorch, you need to use "#" in the "requirements.txt" file to block "torch>=1.8.0" and "torchvision>=0.9.0";
- Open the pycharm terminal and execute the following installation command:
pip install -r requirements.txt
- If you need to install the GPU version of pytorch, please refer to a blog I wrote before:[Selected] Use pycharm to install the latest pytorch in 2023 under Windows systems
2. Use the COCO data set to train the YOLOv8 model and reason about pictures
- Create a new py file in the root directory, such as "main.py", and enter the following code:
from ultralytics.models import YOLO
if __name__ == '__main__':
# model = YOLO("yolov8n.yaml") # build a new model from scratch
model = YOLO("yolov8n.pt") # load a pretrained model (recommended for training)
model.train(data="coco128.yaml", epochs=3) # train the model
results = model("https://ultralytics.com/images/bus.jpg") # predict on an image
- Run the main.py file. After the model training is completed, "bus.jpg" will be inferred.
Summarize
In this blog, we learned about the environment construction, model training and model testing process of YOLOv8. YOLOv8 is an exciting tool that allows us to continue to explore, innovate, and apply it to real projects to bring more inspiration and change to our world.