Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.44k stars 4.16k forks source link

Official Support βœ… for Ultralytics YOLOv8 NCNN export #4846

Open glenn-jocher opened 1 year ago

glenn-jocher commented 1 year ago

I have great news πŸ˜ƒ! I've recently added official support for Ultralytics YOLOv8 NCNN export βœ… in PR https://github.com/ultralytics/ultralytics/pull/3529 with the help of @nihui which is part of ultralytics==8.0.129. NCNN works for all tasks including Detect, Segment, Pose and Classify.

You can now export with CLI:

yolo export model=yolov8n.pt format=ncnn

or Python:

from ultralytics import YOLO

# Create a model
model = YOLO('yolov8n.pt')

# Export the model to NCNN with arguments
model.export(format='ncnn', half=True, imgsz=640)

Output is a yolov8n_ncnn_model/ directory containing model.bin, model.param and metadata.yaml, along with extra PNNX files. For details see https://github.com/pnnx/pnnx README.

To get this update:

Please let us know if NCNN export is working correctly for you, and don't hesitate to report any other issues you find or feature requests you may have. Happy training with YOLOv8 πŸš€!

superbayes commented 1 year ago

@nihui @triple-Mu How to use the officially exported yolov8-model file to complete inference tasks, using ncnn in c++? the tasks including Detect, Segment, Pose and Classify. could you provide code examples?

superbayes commented 1 year ago

i have seen this link,but not try code demo

13185742215 commented 1 year ago

could you provide an example for yolov8-pose inference on ncnn in python?

glenn-jocher commented 1 year ago

@13185742215 yes you can simply do this:

pip install ultralytics

yolo export format=ncnn model=yolov8n-pose.pt
yolo predict model=yolov8n-pose_ncnn_model source=path/to/image.jpg

The NCNN exported YOLOv8 models can be used just like a PyTorch model with the ultralytics package. See https://docs.ultralytics.com/modes/predict/ for other ways to run inference.

trlsmax commented 1 year ago

Hope there are examples of ncnn in c++.

palevi67 commented 1 year ago

I see there is no yolov8.cpp in the examples folder, it would be nice an example that uses utralitics export tool models. I have found some examples in the internet, but none of them are working with ultralitics export models!

wkt commented 1 year ago

@palevi67 @trlsmax try https://github.com/wkt/YoloMobile

nihui commented 2 months ago

yolov8 example https://github.com/Tencent/ncnn/pull/5506