YOLOv8s Models

Overview

YOLOv8s is a variant of the YOLOv8 (You Only Look Once version 8) family of object detection models, recognized for its advancements in speed, accuracy, and ease of use. Developed by Ultralytics, YOLOv8 represents the latest iteration in the YOLO series, building upon the successes of previous versions such as YOLOv4 and YOLOv5, with a focus on modern deep learning practices and integration with popular frameworks.

Getting Started

Follow these steps to convert the YOLOv8s model from PyTorch format to TorchScript.

  1. Download the PyTorch model:

    You can download the YOLOv8s model from the following link: yolov8s.pt

  2. Clone the YOLOv5 repository:

    The export script needed for conversion is available in the YOLOv5 repository. Clone it using the following command:

    git clone https://github.com/ultralytics/yolov5.git
    
  3. Move the YOLOv8s model:

    Move the yolov8s.pt file to the YOLOv5 source code directory you just cloned.

  4. Export the PyTorch model to TorchScript:

    Use the following command to convert the model from PyTorch format to TorchScript:

    python3 export.py --weights yolov8s.pt --img-size 640 640 --include torchscript
    

How it Works ?

Before you begin, ensure that the NeuroPilot Converter Tool is installed.

Quant8 Conversion Process

The following script demonstrates how to convert the YOLOv8s model to a quantized TFLite format:

  • Data Generation: A generator function creates random input data for calibration.

  • Model Loading: The YOLOv8s model is loaded from a TorchScript file.

  • Quantization: The model is configured for quantization with specified input value ranges.

  • Conversion: The quantized model is converted to TFLite format and saved.

import mtk_converter
import numpy as np

def data_gen():
    for i in range(100):
        yield [np.random.randn(1, 3, 640, 640).astype(np.float32)]

converter = mtk_converter.PyTorchConverter.from_script_module_file(
    'yolov8s.torchscript',  [[1, 3, 640, 640]],
)
converter.quantize = True
converter.input_value_ranges = [(-1.0, 1.0)]
converter.calibration_data_gen = data_gen
_ = converter.convert_to_tflite(output_file='yolov8s_quant.tflite')

FP32 Conversion Process

The following script demonstrates how to convert the YOLOv8s model to a non-quantized (FP32) TFLite format:

  • Data Generation: Similar to the quantization process, a generator function creates random input data for conversion.

  • Model Loading: The YOLOv8s model is loaded from a TorchScript file.

  • Conversion: The model is converted to TFLite format without quantization and saved.

import mtk_converter
import numpy as np

def data_gen():
    for i in range(100):
        yield [np.random.randn(1, 3, 640, 640).astype(np.float32)]

converter = mtk_converter.PyTorchConverter.from_script_module_file(
    'yolov8s.torchscript',  [[1, 3, 640, 640]],
)
converter.input_value_ranges = [(-1.0, 1.0)]
converter.calibration_data_gen = data_gen
_ = converter.convert_to_tflite(output_file='yolov8s.tflite')

Model Details

General Information

Property

Value

Category

Detection

Input Size

640x640

FLOPs (B)

28.6

#Params (M)

11.2

Training Framework

PyTorch

Inference Framework

TFLite

Quant8 Model package

Download

Float32 Model package

Download

Model Properties

Quant8

  • Format: TensorFlow Lite v3

  • Description: Exported by NeuroPilot converter v7.14.1+release

Inputs

Property

Value

Name

input.49

Tensor

int8[1,3,640,640]

Identifier

35

Quantization

Linear

Quantization Range

-1.0039 ≤ 0.0078 * q ≤ 0.9961

Outputs

Property

Value

Name

80

Tensor

int8[1,84,8400]

Identifier

378

Quantization

Linear

Quantization Range

-10.1582 ≤ 2.5395 * (q + 124) ≤ 637.4246

Name

77

Tensor

int8[1,144,80,80]

Identifier

37

Quantization

Linear

Quantization Range

-18.2789 ≤ 0.1115 * (q - 36) ≤ 10.1426

Name

78

Tensor

int8[1,144,40,40]

Identifier

270

Quantization

Linear

Quantization Range

-17.3353 ≤ 0.1008 * (q - 44) ≤ 8.3653

Name

79

Tensor

int8[1,144,20,20]

Identifier

155

Quantization

Linear

Quantization Range

-23.8304 ≤ 0.1288 * (q - 57) ≤ 9.0169

Fp32

  • Format: TensorFlow Lite v3

  • Description: Exported by NeuroPilot converter v7.14.1+release

Inputs

Property

Value

Name

input.49

Tensor

float32[1,3,640,640]

Identifier

145

Outputs

Property

Value

Name

80

Tensor

float32[1,84,8400]

Identifier

78

Name

77

Tensor

float32[1,144,80,80]

Identifier

235

Name

78

Tensor

float32[1,144,40,40]

Identifier

73

Name

79

Tensor

float32[1,144,20,20]

Identifier

343

Performance Benchmarks

YOLOv8s-quant8

Run model (.tflite) 10 times

CPU (Thread:8)

GPU

ARMNN(GpuAcc)

ARMNN(CpuAcc)

Neuron Stable Delegate(APU)

APU(MDLA)

APU(VPU)

G350

1030.54 ms (Thread:4)

1306.24 ms

752.383 ms

730.644 ms

N/A

N/A

112023 ms

G510

360.921 ms

437.340 ms

232.064 ms

178.786 ms

29.564 ms

25.51 ms

N/A

G700

169.113 ms

301.178 ms

162.038 ms

160.934 ms

27.336 ms

17.01 ms

N/A

G1200

170.408 ms

207.360 ms

104.634 ms

88.477 ms

29.590 ms

28.04 ms

N/A

YOLOv8s-fp32

Run model (.tflite) 10 times

CPU (Thread:8)

GPU

ARMNN(GpuAcc)

ARMNN(CpuAcc)

Neuron Stable Delegate(APU)

APU(MDLA)

APU(VPU)

G350

2191.58 ms (Thread:4)

1273.35 ms

1145.45 ms

N/A

N/A

N/A

7729.33 ms

G510

832.005 ms

410.635 ms

373.830 ms

428.679 ms

68.295 ms

70.95 ms

N/A

G700

465.654 ms

284.420 ms

258.681 ms

361.914 ms

49.723 ms

50.04 ms

N/A

G1200

415.078 ms

190.626 ms

164.658 ms

209.437 ms

55.250 ms

55.84 ms

N/A

  • Widespread: CPU only, light workload.

  • Performance: CPU and GPU, medium workload.

  • Ultimate: CPU, GPU, and APUs, heavy workload.

Resources

To preview related documentation about YOLOv8, please visit the Github repository