Skip to content

NEW - YOLOv8 ๐Ÿš€ in PyTorch > ONNX > CoreML > TFLite

License

Notifications You must be signed in to change notification settings

Nota-NetsPresso/ModelZoo-YOLOv8

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NetsPresso Tutorial for YOLOv8 Compressrion

Order of the tutorial

0. Sign up
1. Install
2. Convert yolov8 to _torchfx.pt
3. Model Compression with NetsPresso API Package
4. Fine-tuning the compressed Model

0. Sign up

To get started with the NetsPresso Python package, you will need to sign up at NetsPresso.

1. Install

git clone https://github.com/Nota-NetsPresso/ultralytics_nota
cd ultralytics_nota
pip install -e .

2. Convert YOLOv8 to _torchfx.pt

Executing the following code creates 'model_fx.pt' and 'netspresso_head_meta.json'.

from ultralytics import YOLO

model = YOLO('yolov8.pt') # load a pretrained model (recommended for training)

model.export_netspresso() # Through this code, 'model_fx.pt' and 'netspresso_head_meta.json' are created.

3. Model Compression with NetsPresso API Package

Upload & compress your 'model_torchfx.pt' by using NetsPresso API Package

3_1. Install NetsPresso API Package

pip install netspresso

3_2. Upload & Compress

First, import the packages and set a NetsPresso username and password.

from netspresso.compressor import ModelCompressor, Task, Framework, CompressionMethod, RecommendationMethod


EMAIL = "YOUR_EMAIL"
PASSWORD = "YOUR_PASSWORD"
compressor = ModelCompressor(email=EMAIL, password=PASSWORD)

Second, upload 'model_fx.pt', which is the model converted to torchfx in step 2, with the following code.

# Upload Model
UPLOAD_MODEL_NAME = "yolov8_model"
TASK = Task.OBJECT_DETECTION
FRAMEWORK = Framework.PYTORCH
UPLOAD_MODEL_PATH = "./model_fx.pt"
INPUT_SHAPES = [{"batch": 1, "channel": 3, "dimension": [640, 640]}]
model = compressor.upload_model(
    model_name=UPLOAD_MODEL_NAME,
    task=TASK,
    framework=FRAMEWORK,
    file_path=UPLOAD_MODEL_PATH,
    input_shapes=INPUT_SHAPES,
)

Finally, you can compress the uploaded model with the desired options through the following code.

# Recommendation Compression
COMPRESSED_MODEL_NAME = "test_l2norm"
COMPRESSION_METHOD = CompressionMethod.PR_L2
RECOMMENDATION_METHOD = RecommendationMethod.SLAMP
RECOMMENDATION_RATIO = 0.6
OUTPUT_PATH = "./compressed_model.pt"
compressed_model = compressor.recommendation_compression(
    model_id=model.model_id,
    model_name=COMPRESSED_MODEL_NAME,
    compression_method=COMPRESSION_METHOD,
    recommendation_method=RECOMMENDATION_METHOD,
    recommendation_ratio=RECOMMENDATION_RATIO,
    output_path=OUTPUT_PATH,
)
Click to check 'Full Upload&Compress Code'
pip install netspresso
from netspresso.compressor import ModelCompressor, Task, Framework, CompressionMethod, RecommendationMethod


EMAIL = "YOUR_EMAIL"
PASSWORD = "YOUR_PASSWORD"
compressor = ModelCompressor(email=EMAIL, password=PASSWORD)

# Upload Model
UPLOAD_MODEL_NAME = "yolov8_model"
TASK = Task.OBJECT_DETECTION
FRAMEWORK = Framework.PYTORCH
UPLOAD_MODEL_PATH = "./model_fx.pt"
INPUT_SHAPES = [{"batch": 1, "channel": 3, "dimension": [640, 640]}]
model = compressor.upload_model(
    model_name=UPLOAD_MODEL_NAME,
    task=TASK,
    framework=FRAMEWORK,
    file_path=UPLOAD_MODEL_PATH,
    input_shapes=INPUT_SHAPES,
)

# Recommendation Compression
COMPRESSED_MODEL_NAME = "test_l2norm"
COMPRESSION_METHOD = CompressionMethod.PR_L2
RECOMMENDATION_METHOD = RecommendationMethod.SLAMP
RECOMMENDATION_RATIO = 0.6
OUTPUT_PATH = "./compressed_model.pt"
compressed_model = compressor.recommendation_compression(
    model_id=model.model_id,
    model_name=COMPRESSED_MODEL_NAME,
    compression_method=COMPRESSION_METHOD,
    recommendation_method=RECOMMENDATION_METHOD,
    recommendation_ratio=RECOMMENDATION_RATIO,
    output_path=OUTPUT_PATH,
)

More commands can be found in the official NetsPresso Python Package docs: https://nota-netspresso.github.io/PyNetsPresso-docs
Alternatively, you can do the same as above through the GUI on our website: https://console.netspresso.ai/models

4. Fine-tuning the compressed Model

The compressed model can be retrained with the following code.
In the location of '/ultralytics_nota/compressed_model.pt', enter the path to the compressed model obtained in step 3.
In the location of '/ultralytics_nota/netspresso_head_meta.json', enter the path of 'netspresso_head_meta' obtained in step 2.
In place of 'detect_retraining', enter '[classify, detect, segment, pose]_retraining'. In the last option, enter the path to the yaml where you have entered the settings required for training.

from ultralytics import YOLO_netspresso

model = YOLO_netspresso('/ultralytics_nota/compressed_model.pt', '/ultralytics_nota/netspresso_head_meta.json', 'detect_retraining', '/ultralytics_nota/new_args.yaml')

model.train(data='coco128.yaml', epochs=100, imgsz=640)
metrics = model.val(data='coco128.yaml')

# If you want to do iterative pruning, you can get model_fx.pt and netspresso_head_meta.json files through the following code. You can proceed again from step 3 with the obtained file.
model.export_netspresso()

If you want to do iterative pruning with a retrained pt file, you can get model_fx.pt and netspresso_head_meta.json files through the following code. You can proceed again from step 3 with the obtained file.

from ultralytics import export_netspresso

export_netspresso("compressed_and_retrained_model.pt") # Through this code, 'model_fx.pt' and 'netspresso_head_meta.json' are created.

Contact

Join our Discussion Forum for providing feedback or sharing your use cases, and if you want to talk more with Nota, please contact us here.
Or you can also do it via email(contact@nota.ai) or phone(+82 2-555-8659)!



English | ็ฎ€ไฝ“ไธญๆ–‡

Ultralytics CI YOLOv8 Citation Docker Pulls
Run on Gradient Open In Colab Open In Kaggle

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.

We hope that the resources here will help you get the most out of YOLOv8. Please browse the YOLOv8 Docs for details, raise an issue on GitHub for support, and join our Discord community for questions and discussions!

To request an Enterprise License please complete the form at Ultralytics Licensing.

Documentation

See below for a quickstart installation and usage example, and see the YOLOv8 Docs for full documentation on training, validation, prediction and deployment.

Install

Pip install the ultralytics package including all requirements in a Python>=3.7 environment with PyTorch>=1.7.

pip install ultralytics
Usage

CLI

YOLOv8 may be used directly in the Command Line Interface (CLI) with a yolo command:

yolo predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg'

yolo can be used for a variety of tasks and modes and accepts additional arguments, i.e. imgsz=640. See the YOLOv8 CLI Docs for examples.

Python

YOLOv8 may also be used directly in a Python environment, and accepts the same arguments as in the CLI example above:

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)

# Use the model
model.train(data="coco128.yaml", epochs=3)  # train the model
metrics = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
path = model.export(format="onnx")  # export the model to ONNX format

Models download automatically from the latest Ultralytics release. See YOLOv8 Python Docs for more examples.

Models

All YOLOv8 pretrained models are available here. Detect, Segment and Pose models are pretrained on the COCO dataset, while Classify models are pretrained on the ImageNet dataset.

Models download automatically from the latest Ultralytics release on first use.

Detection

See Detection Docs for usage examples with these models.

Model size
(pixels)
mAPval
50-95
Speed
CPU ONNX
(ms)
Speed
A100 TensorRT
(ms)
params
(M)
FLOPs
(B)
YOLOv8n 640 37.3 80.4 0.99 3.2 8.7
YOLOv8s 640 44.9 128.4 1.20 11.2 28.6
YOLOv8m 640 50.2 234.7 1.83 25.9 78.9
YOLOv8l 640 52.9 375.2 2.39 43.7 165.2
YOLOv8x 640 53.9 479.1 3.53 68.2 257.8
  • mAPval values are for single-model single-scale on COCO val2017 dataset.
    Reproduce by yolo val detect data=coco.yaml device=0
  • Speed averaged over COCO val images using an Amazon EC2 P4d instance.
    Reproduce by yolo val detect data=coco128.yaml batch=1 device=0|cpu
Segmentation

See Segmentation Docs for usage examples with these models.

Model size
(pixels)
mAPbox
50-95
mAPmask
50-95
Speed
CPU ONNX
(ms)
Speed
A100 TensorRT
(ms)
params
(M)
FLOPs
(B)
YOLOv8n-seg 640 36.7 30.5 96.1 1.21 3.4 12.6
YOLOv8s-seg 640 44.6 36.8 155.7 1.47 11.8 42.6
YOLOv8m-seg 640 49.9 40.8 317.0 2.18 27.3 110.2
YOLOv8l-seg 640 52.3 42.6 572.4 2.79 46.0 220.5
YOLOv8x-seg 640 53.4 43.4 712.1 4.02 71.8 344.1
  • mAPval values are for single-model single-scale on COCO val2017 dataset.
    Reproduce by yolo val segment data=coco.yaml device=0
  • Speed averaged over COCO val images using an Amazon EC2 P4d instance.
    Reproduce by yolo val segment data=coco128-seg.yaml batch=1 device=0|cpu
Classification

See Classification Docs for usage examples with these models.

Model size
(pixels)
acc
top1
acc
top5
Speed
CPU ONNX
(ms)
Speed
A100 TensorRT
(ms)
params
(M)
FLOPs
(B) at 640
YOLOv8n-cls 224 66.6 87.0 12.9 0.31 2.7 4.3
YOLOv8s-cls 224 72.3 91.1 23.4 0.35 6.4 13.5
YOLOv8m-cls 224 76.4 93.2 85.4 0.62 17.0 42.7
YOLOv8l-cls 224 78.0 94.1 163.0 0.87 37.5 99.7
YOLOv8x-cls 224 78.4 94.3 232.0 1.01 57.4 154.8
  • acc values are model accuracies on the ImageNet dataset validation set.
    Reproduce by yolo val classify data=path/to/ImageNet device=0
  • Speed averaged over ImageNet val images using an Amazon EC2 P4d instance.
    Reproduce by yolo val classify data=path/to/ImageNet batch=1 device=0|cpu
Pose

See Pose Docs for usage examples with these models.

Model size
(pixels)
mAPpose
50-95
mAPpose
50
Speed
CPU ONNX
(ms)
Speed
A100 TensorRT
(ms)
params
(M)
FLOPs
(B)
YOLOv8n-pose 640 50.4 80.1 131.8 1.18 3.3 9.2
YOLOv8s-pose 640 60.0 86.2 233.2 1.42 11.6 30.2
YOLOv8m-pose 640 65.0 88.8 456.3 2.00 26.4 81.0
YOLOv8l-pose 640 67.6 90.0 784.5 2.59 44.4 168.6
YOLOv8x-pose 640 69.2 90.2 1607.1 3.73 69.4 263.2
YOLOv8x-pose-p6 1280 71.6 91.2 4088.7 10.04 99.1 1066.4
  • mAPval values are for single-model single-scale on COCO Keypoints val2017 dataset.
    Reproduce by yolo val pose data=coco-pose.yaml device=0
  • Speed averaged over COCO val images using an Amazon EC2 P4d instance.
    Reproduce by yolo val pose data=coco8-pose.yaml batch=1 device=0|cpu

Integrations




Roboflow ClearML โญ NEW Comet โญ NEW Neural Magic โญ NEW
Label and export your custom datasets directly to YOLOv8 for training with Roboflow Automatically track, visualize and even remotely train YOLOv8 using ClearML (open-source!) Free forever, Comet lets you save YOLOv8 models, resume training, and interactively visualize and debug predictions Run YOLOv8 inference up to 6x faster with Neural Magic DeepSparse

Ultralytics HUB

Experience seamless AI with Ultralytics HUB โญ, the all-in-one solution for data visualization, YOLOv5 and YOLOv8 ๐Ÿš€ model training and deployment, without any coding. Transform images into actionable insights and bring your AI visions to life with ease using our cutting-edge platform and user-friendly Ultralytics App. Start your journey for Free now!

Contribute

We love your input! YOLOv5 and YOLOv8 would not be possible without help from our community. Please see our Contributing Guide to get started, and fill out our Survey to send us feedback on your experience. Thank you ๐Ÿ™ to all our contributors!

License

YOLOv8 is available under two different licenses:

  • AGPL-3.0 License: See LICENSE file for details.
  • Enterprise License: Provides greater flexibility for commercial product development without the open-source requirements of AGPL-3.0. Typical use cases are embedding Ultralytics software and AI models in commercial products and applications. Request an Enterprise License at Ultralytics Licensing.

Contact

For YOLOv8 bug reports and feature requests please visit GitHub Issues, and join our Discord community for questions and discussions!


About

NEW - YOLOv8 ๐Ÿš€ in PyTorch > ONNX > CoreML > TFLite

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.4%
  • Other 0.6%