yolov8m / README.md
zhengrongzhang's picture
update for regression test (#5)
e0810ef verified
metadata
license: apache-2.0
tags:
  - RyzenAI
  - object-detection
  - vision
  - YOLO
  - Pytorch
datasets:
  - COCO
metrics:
  - mAP

YOLOv8m model trained on COCO

YOLOv8m is the medium version of YOLOv8 model trained on COCO object detection (118k annotated images) at resolution 640x640. It was released in https://github.com/ultralytics/ultralytics.

We develop a modified version that could be supported by AMD Ryzen AI.

Model description

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. YOLOv8 is designed to be fast, accurate, and easy to use, making it an excellent choice for a wide range of object detection and tracking, instance segmentation, image classification and pose estimation tasks.

Intended uses & limitations

You can use the raw model for object detection. See the model hub to look for all available YOLOv8 models.

How to use

Installation

Follow Ryzen AI Installation to prepare the environment for Ryzen AI. Run the following script to install pre-requisites for this model.

pip install -r requirements.txt 

Data Preparation (optional: for accuracy evaluation)

The dataset MSCOCO2017 contains 118287 images for training and 5000 images for validation.

Download COCO dataset and create/mount directories in your code like this:

└── yolov8m
    └── datasets
        └── coco
              β”œβ”€β”€ annotations
              |   β”œβ”€β”€ instances_val2017.json
              |   └── ...
              β”œβ”€β”€ labels
              |   β”œβ”€β”€ val2017
              |   |   β”œβ”€β”€ 000000000139.txt
              |       β”œβ”€β”€ 000000000285.txt
              |       └── ...
              β”œβ”€β”€ images
              |   β”œβ”€β”€ val2017
              |   |   β”œβ”€β”€ 000000000139.jpg
              |       β”œβ”€β”€ 000000000285.jpg
              └── val2017.txt
  1. put the val2017 image folder under images directory or use a softlink
  2. the labels folder and val2017.txt above are generate by general_json2yolo.py
  3. modify the coco.yaml like this:
path: /path/to/your/datasets/coco  # dataset root dir
train: train2017.txt  # train images (relative to 'path') 118287 images
val: val2017.txt  # val images (relative to 'path') 5000 images

Test & Evaluation

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,
    )
  • Run inference for a single image
python infer_onnx.py --onnx_model ./yolov8m.onnx -i /Path/To/Your/Image --ipu --provider_config /Path/To/Your/Provider_config

Note: vaip_config.json is located at the setup package of Ryzen AI (refer to Installation)

  • Test accuracy of the quantized model
python eval_onnx.py --onnx_model ./yolov8m.onnx --ipu --provider_config /Path/To/Your/Provider_config

Performance

Metric Accuracy on IPU
[email protected]:0.95 0.486
@software{yolov8_ultralytics,
  author = {Glenn Jocher and Ayush Chaurasia and Jing Qiu},
  title = {Ultralytics YOLOv8},
  version = {8.0.0},
  year = {2023},
  url = {https://github.com/ultralytics/ultralytics},
  orcid = {0000-0001-5950-6979, 0000-0002-7603-6750, 0000-0003-3783-7069},
  license = {AGPL-3.0}
}