─░├žeri─če ge├ž

TFLite, ONNX, CoreML, TensorRT ─░hracat

­čôÜ Bu k─▒lavuz, e─čitilmi┼č bir YOLOv5 ­čÜÇ modelinin PyTorch adresinden ONNX ve TorchScript bi├žimlerine nas─▒l aktar─▒laca─č─▒n─▒ a├ž─▒klamaktad─▒r.

Ba┼člamadan ├ľnce

Repoyu klonlay─▒n ve requirements.txt dosyas─▒n─▒ bir Python>=3.8.0 ortam─▒ dahil olmak ├╝zere PyTorch>=1.8. Modeller ve veri setleri en son YOLOv5 s├╝r├╝m├╝nden otomatik olarak indirilir.

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

─░├žin TensorRT d─▒┼ča aktarma ├Ârne─či (GPU gerektirir) Colab'─▒m─▒za bak─▒n defter ekler b├Âl├╝m├╝. Colab'da A├ž

Formatlar

YOLOv5 ├ž─▒kar─▒m─▒ resmi olarak 11 formatta desteklenmektedir:

­čĺí ProTip: 3 kata kadar CPU h─▒zland─▒rmas─▒ i├žin ONNX veya OpenVINO adresine aktar─▒n. CPU Benchmark'lar─▒na bak─▒n. ­čĺí ─░pucu: 5 kata kadar GPU h─▒zland─▒rmas─▒ i├žin TensorRT adresine aktar─▒n. GPU Benchmark'lar─▒na bak─▒n.

Bi├žim export.py --include Model
PyTorch - yolov5s.pt
TorchScript torchscript yolov5s.torchscript
ONNX onnx yolov5s.onnx
OpenVINO openvino yolov5s_openvino_model/
TensorRT engine yolov5s.engine
CoreML coreml yolov5s.mlmodel
TensorFlow SavedModel saved_model yolov5s_saved_model/
TensorFlow GraphDef pb yolov5s.pb
TensorFlow Lite tflite yolov5s.tflite
TensorFlow Kenar TPU edgetpu yolov5s_edgetpu.tflite
TensorFlow.js tfjs yolov5s_web_model/
PaddlePaddle paddle yolov5s_paddle_model/

├ľl├ž├╝tler

A┼ča─č─▒daki kar┼č─▒la┼čt─▒rmalar YOLOv5 ├Â─čretici notebook ile Colab Pro ├╝zerinde ├žal─▒┼čt─▒r─▒lm─▒┼čt─▒r Colab'da A├ž. ├ço─čaltmak i├žin:

python benchmarks.py --weights yolov5s.pt --imgsz 640 --device 0

Colab Pro V100 GPU

benchmarks: weights=/content/yolov5/yolov5s.pt, imgsz=640, batch_size=1, data=/content/yolov5/data/coco128.yaml, device=0, half=False, test=False
Checking setup...
YOLOv5 ­čÜÇ v6.1-135-g7926afc torch 1.10.0+cu111 CUDA:0 (Tesla V100-SXM2-16GB, 16160MiB)
Setup complete Ôťů (8 CPUs, 51.0 GB RAM, 46.7/166.8 GB disk)

Benchmarks complete (458.07s)
                   Format  mAP@0.5:0.95  Inference time (ms)
0                 PyTorch        0.4623                10.19
1             TorchScript        0.4623                 6.85
2                    ONNX        0.4623                14.63
3                OpenVINO           NaN                  NaN
4                TensorRT        0.4617                 1.89
5                  CoreML           NaN                  NaN
6   TensorFlow SavedModel        0.4623                21.28
7     TensorFlow GraphDef        0.4623                21.22
8         TensorFlow Lite           NaN                  NaN
9     TensorFlow Edge TPU           NaN                  NaN
10          TensorFlow.js           NaN                  NaN

Colab Pro CPU

benchmarks: weights=/content/yolov5/yolov5s.pt, imgsz=640, batch_size=1, data=/content/yolov5/data/coco128.yaml, device=cpu, half=False, test=False
Checking setup...
YOLOv5 ­čÜÇ v6.1-135-g7926afc torch 1.10.0+cu111 CPU
Setup complete Ôťů (8 CPUs, 51.0 GB RAM, 41.5/166.8 GB disk)

Benchmarks complete (241.20s)
                   Format  mAP@0.5:0.95  Inference time (ms)
0                 PyTorch        0.4623               127.61
1             TorchScript        0.4623               131.23
2                    ONNX        0.4623                69.34
3                OpenVINO        0.4623                66.52
4                TensorRT           NaN                  NaN
5                  CoreML           NaN                  NaN
6   TensorFlow SavedModel        0.4623               123.79
7     TensorFlow GraphDef        0.4623               121.57
8         TensorFlow Lite        0.4623               316.61
9     TensorFlow Edge TPU           NaN                  NaN
10          TensorFlow.js           NaN                  NaN

E─čitilmi┼č bir YOLOv5 Modelini D─▒┼ča Aktar─▒n

Bu komut, ├Ânceden e─čitilmi┼č bir YOLOv5s modelini TorchScript ve ONNX bi├žimlerine aktar─▒r. yolov5s.pt mevcut en k├╝├ž├╝k ikinci model olan 'k├╝├ž├╝k' modeldir. Di─čer se├ženekler ┼čunlard─▒r yolov5n.pt, yolov5m.pt, yolov5l.pt ve yolov5x.ptP6 muadilleri ile birlikte, yani yolov5s6.pt veya kendi ├Âzel e─čitim kontrol noktan─▒z, ├Ârn. runs/exp/weights/best.pt. Mevcut t├╝m modellerle ilgili ayr─▒nt─▒lar i├žin l├╝tfen README'ye bak─▒n masa.

python export.py --weights yolov5s.pt --include torchscript onnx

­čĺí ProTip: Ekle --half daha k├╝├ž├╝k dosya boyutlar─▒ i├žin modelleri FP16 yar─▒ hassasiyetinde d─▒┼ča aktarmak

Çıktı:

export: data=data/coco128.yaml, weights=['yolov5s.pt'], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, train=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['torchscript', 'onnx']
YOLOv5 ­čÜÇ v6.2-104-ge3e5122 Python-3.8.0 torch-1.12.1+cu113 CPU

Downloading https://github.com/ultralytics/yolov5/releases/download/v6.2/yolov5s.pt to yolov5s.pt...
100% 14.1M/14.1M [00:00<00:00, 274MB/s]

Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients

PyTorch: starting from yolov5s.pt with output shape (1, 25200, 85) (14.1 MB)

TorchScript: starting export with torch 1.12.1+cu113...
TorchScript: export success Ôťů 1.7s, saved as yolov5s.torchscript (28.1 MB)

ONNX: starting export with onnx 1.12.0...
ONNX: export success Ôťů 2.3s, saved as yolov5s.onnx (28.0 MB)

Export complete (5.5s)
Results saved to /content/yolov5
Detect:          python detect.py --weights yolov5s.onnx
Validate:        python val.py --weights yolov5s.onnx
PyTorch Hub:     model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s.onnx')
Visualize:       https://netron.app/

D─▒┼ča aktar─▒lan 3 model orijinal PyTorch modelinin yan─▒na kaydedilecektir:

YOLO i̇hracat lokasyonlari

D─▒┼ča aktar─▒lan modelleri g├Ârselle┼čtirmek i├žin Netron Viewer ├Ânerilir:

YOLO model g├Ârselle┼čtirme

D─▒┼ča Aktar─▒lan Model Kullan─▒m ├ľrnekleri

detect.py d─▒┼ča aktar─▒lan modeller ├╝zerinde ├ž─▒kar─▒m yapar:

python detect.py --weights yolov5s.pt                 # PyTorch
                           yolov5s.torchscript        # TorchScript
                           yolov5s.onnx               # ONNX Runtime or OpenCV DNN with dnn=True
                           yolov5s_openvino_model     # OpenVINO
                           yolov5s.engine             # TensorRT
                           yolov5s.mlmodel            # CoreML (macOS only)
                           yolov5s_saved_model        # TensorFlow SavedModel
                           yolov5s.pb                 # TensorFlow GraphDef
                           yolov5s.tflite             # TensorFlow Lite
                           yolov5s_edgetpu.tflite     # TensorFlow Edge TPU
                           yolov5s_paddle_model       # PaddlePaddle

val.py d─▒┼ča aktar─▒lan modeller ├╝zerinde do─črulama ├žal─▒┼čt─▒r─▒r:

python val.py --weights yolov5s.pt                 # PyTorch
                        yolov5s.torchscript        # TorchScript
                        yolov5s.onnx               # ONNX Runtime or OpenCV DNN with dnn=True
                        yolov5s_openvino_model     # OpenVINO
                        yolov5s.engine             # TensorRT
                        yolov5s.mlmodel            # CoreML (macOS Only)
                        yolov5s_saved_model        # TensorFlow SavedModel
                        yolov5s.pb                 # TensorFlow GraphDef
                        yolov5s.tflite             # TensorFlow Lite
                        yolov5s_edgetpu.tflite     # TensorFlow Edge TPU
                        yolov5s_paddle_model       # PaddlePaddle

D─▒┼ča aktar─▒lan YOLOv5 modelleri ile PyTorch Hub'─▒ kullan─▒n:

import torch

# Model
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.pt")
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.torchscript ")  # TorchScript
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.onnx")  # ONNX Runtime
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s_openvino_model")  # OpenVINO
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.engine")  # TensorRT
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.mlmodel")  # CoreML (macOS Only)
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s_saved_model")  # TensorFlow SavedModel
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.pb")  # TensorFlow GraphDef
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s.tflite")  # TensorFlow Lite
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s_edgetpu.tflite")  # TensorFlow Edge TPU
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s_paddle_model")  # PaddlePaddle

# Images
img = "https://ultralytics.com/images/zidane.jpg"  # or file, Path, PIL, OpenCV, numpy, list

# Inference
results = model(img)

# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.

OpenCV DNN ├ž─▒kar─▒m─▒

ONNX modelleri ile OpenCV ├ž─▒kar─▒m─▒:

python export.py --weights yolov5s.pt --include onnx

python detect.py --weights yolov5s.onnx --dnn  # detect
python val.py --weights yolov5s.onnx --dnn  # validate

C++ Çıkarım

YOLOv5 D─▒┼ča aktar─▒lan ONNX model ├Ârnekleri ├╝zerinde OpenCV DNN C++ ├ž─▒kar─▒m─▒:

YOLOv5 OpenVINO C++ ├ž─▒kar─▒m ├Ârnekleri:

TensorFlow.js Web Tarayıcı Çıkarsaması

Desteklenen Ortamlar

Ultralytics her biri CUDA, CUDNN gibi temel ba─č─▒ml─▒l─▒klarla ├Ânceden y├╝klenmi┼č bir dizi kullan─▒ma haz─▒r ortam sa─člar, Pythonve PyTorchProjelerinizi ba┼člatmak i├žin.

Proje Durumu

YOLOv5 CI

Bu rozet, t├╝m YOLOv5 GitHub Actions S├╝rekli Entegrasyon (CI) testlerinin ba┼čar─▒yla ge├žti─čini g├Âsterir. Bu CI testleri, YOLOv5 'un i┼člevselli─čini ve performans─▒n─▒ ├že┼čitli temel y├Ânlerden titizlikle kontrol eder: e─čitim, do─črulama, ├ž─▒kar─▒m, d─▒┼ča aktarma ve k─▒yaslamalar. Her 24 saatte bir ve her yeni i┼člemde yap─▒lan testlerle macOS, Windows ve Ubuntu ├╝zerinde tutarl─▒ ve g├╝venilir ├žal─▒┼čma sa─člarlar.



Created 2023-11-12, Updated 2024-06-10
Authors: glenn-jocher (8)

Yorumlar