Welcome to this guide on utilizing the YOLOv8m model, specifically tailored for object detection tasks. With the power of Ryzen AI, you can quickly set up this state-of-the-art model for your AI projects. In this tutorial, we will walk you through the installation process, data preparation, evaluation, and troubleshooting tips.
What is YOLOv8m?
YOLOv8m is a medium version of the YOLOv8 object detection model trained on the COCO dataset, featuring 118k annotated images processed at a resolution of 640×640. This model excels in tasks like object detection, instance segmentation, image classification, and pose estimation, making it an incredibly versatile tool for a wide range of applications.
Installation
Before diving into using the model, you’ll need to set up your environment. Here’s how you can do it:
- Follow the Ryzen AI Installation guide to start preparing your environment.
- Run the following script to install the required prerequisites:
bash
pip install -r requirements.txt
Data Preparation (Optional for Accuracy Evaluation)
For optimal performance, it is beneficial to prepare the dataset correctly. The MSCOCO2017 dataset consists of 118,287 training images and 5,000 validation images. Here’s how to set it up:
Download the COCO dataset and create the following directories in your project:
yolov8m/
├── datasets/
└── coco/
├── annotations/
├── instances_val2017.json
└── ...
├── labels/
├── val2017/
├── 000000000139.txt
└── ...
├── images/
├── val2017/
├── 000000000139.jpg
└── ...
└── val2017.txt
- Ensure to place the val2017 image folder in the images directory or use a softlink.
- Generate the labels folder and val2017.txt using
general_json2yolo.py. - Modify the coco.yaml configuration file to reflect your dataset’s structure.
markdownpath: pathtoyourdatasetscoco
train: train2017.txt # train images (relative to path) 118287 images
val: val2017.txt # val images (relative to path) 5000 images
Test & Evaluation
To evaluate the model’s performance, follow these steps:
- Use the code snippet below from
infer_onnx.pyto conduct inference:
python
args = make_parser().parse_args()
source = args.image_path
dataset = LoadImages(source, imgsz=imgsz, stride=32, auto=False, transforms=None, vid_stride=1)
onnx_weight = args.model
onnx_model = onnxruntime.InferenceSession(onnx_weight)
for batch in dataset:
path, im, im0s, vid_cap, s = batch
im = preprocess(im)
if len(im.shape) == 3:
im = im[None]
outputs = onnx_model.run(None, {onnx_model.get_inputs()[0].name: im.permute(0, 2, 3, 1).cpu().numpy()})
outputs = [torch.tensor(item).permute(0, 3, 1, 2) for item in outputs]
preds = post_process(outputs)
preds = non_max_suppression(preds, 0.25, 0.7, agnostic=False, max_det=300, classes=None)
plot_images(im, *output_to_target(preds, max_det=15), source, fname=args.output_path, names=names)
- To run inference for a single image, use:
python infer_onnx.py --onnx_model .yolov8m.onnx -i PathToYourImage --ipu --provider_config PathToYourProvider_config
Note: The vaip_config.json file can be found in the setup package of Ryzen AI (refer to the Installation section for details).
Performance Metrics
Upon successfully conducting your evaluation, you may check the results. Here is a summary of the performance metrics:
| Metric | Accuracy on IPU |
|---|---|
| AP@0.50 | 0.486 |
Troubleshooting
If you encounter issues during installation or while running the model, here are a few troubleshooting tips:
- Ensure that you have the correct format for your dataset directories and files.
- Double-check your Python environment and library installations; missing packages can lead to unexpected errors.
- If the ONNX model fails to load, confirm that the model path is correct and that the file exists.
- For additional insights, updates, or if you wish to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
In summary, the YOLOv8m model leverages the power of Ryzen AI to enhance object detection capabilities. By installing the prerequisites, preparing your data, and correctly utilizing evaluation scripts, you can harness the full potential of this cutting-edge model.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
