Bắt đầu

Xuất Sony IMX500

Sony IMX500 là cảm biến hình ảnh tích hợp bộ tăng tốc AI trên chip dành cho AI biên, được sử dụng trong Raspberry Pi AI Camera: camera tự chạy network và gửi kết quả cùng từng khung hình đến Raspberry Pi. Xuất model Ultralytics YOLO11n hoặc YOLOv8n bằng format="imx" sẽ lượng tử hóa model thành INT8 bằng Model Compression Toolkit (MCT) của Sony, biên dịch model bằng trình chuyển đổi IMX500 và ghi ra một thư mục mang tên model, chẳng hạn yolo11n_imx_model/ cho yolo11n.pt hoặc yolov8n_imx_model/ cho yolov8n.pt, trong đó có packerOut.zip, tức model đã biên dịch mà bạn sao chép sang Raspberry Pi. Các họ model khác, bao gồm YOLO26, không được hỗ trợ; các kích thước lớn hơn cũng không được hỗ trợ, ngoại trừ các model s cho phân loại. Quá trình xuất chạy trên máy tính Linux và không cần camera.

Tổng quan nhanh#

Thuộc tínhChi tiết
Đối số formatimx
Đầu ra<model>_imx_model/, chẳng hạn yolo11n_imx_model/, một thư mục gồm packerOut.zip dành cho camera, model_imx.onnx để kiểm thử trên máy tính và labels.txt, xem Định dạng đầu ra
Chạy trênCảm biến IMX500, chẳng hạn như trong Raspberry Pi AI Camera trên Raspberry Pi 5 hoặc 4 Model B. YOLO() chạy model_imx.onnx trên CPU của máy tính để kiểm tra model đã lượng tử hóa
RuntimeTrên Raspberry Pi: firmware IMX500 (imx500-all) và Application Module Library của Sony. Trên máy tính: ONNX Runtime cùng các toán tử MCT
PrecisionChỉ INT8, được lượng tử hóa bằng phương pháp lượng tử hóa sau huấn luyện MCT trên các ảnh hiệu chuẩn từ data. YOLO11n detection có kích thước 2.3 MB dưới dạng packerOut.zip
Máy exportLinux với Python 3.10 đến 3.12 và Java 17 trở lên. Không hỗ trợ macOS hoặc Windows. Quá trình xuất không cần camera; nếu có, GPU CUDA sẽ chạy bước lượng tử hóa
Export trên cloud

Ultralytics Platform có thể xuất model YOLO11n hoặc YOLOv8n đã huấn luyện sang IMX500, vì vậy bạn không cần môi trường xuất cục bộ.

Bắt đầu nhanh#

Cài đặt package Ultralytics trong môi trường ảo trên máy Linux có Python 3.10, 3.11 hoặc 3.12. Trước tiên, hãy nâng cấp pip: pip từ 24.0 đến 25.0, bao gồm pip 24.0 được python3 -m venv cài vào môi trường mới trên Ubuntu 24.04, không thể phân giải các package IMX:

python3 -m venv imx-env && source imx-env/bin/activate
pip install --upgrade pip
pip install ultralytics

Quá trình xuất cũng cần Java 17 trở lên trên PATH để chạy trình chuyển đổi IMX500. Kiểm tra bằng java --version. Cài đặt bằng sudo apt install openjdk-21-jre trên Ubuntu và Debian 13 trở lên, hoặc openjdk-17-jre trên Debian 12 và Raspberry Pi OS Bookworm; nếu không có Java, quá trình xuất sẽ tự chạy lệnh này. Xem Giới hạn và khắc phục sự cố. Nếu không có sudo, hãy giải nén một kho lưu trữ JDK, chẳng hạn Eclipse Temurin, vào thư mục home rồi thêm thư mục bin vào PATH, như đã thực hiện cho trang này.

Lần xuất IMX đầu tiên của Ultralytics cài đặt Model Compression Toolkit (model-compression-toolkit) của Sony, trình chuyển đổi IMX500 (imx500-converter[pt]) và các dependency của chúng, đồng thời thay matplotlib bằng phiên bản 3.9.4 và networkx bằng phiên bản 3.0 mà các gói này yêu cầu. Quá trình này ghi log Restart runtime or rerun command for updates to take effect nhưng vẫn hoàn tất trong cùng lần chạy. Lần xuất thứ hai trong cùng môi trường không cài đặt gì.

Để cài đặt tất cả các thành phần này trước lần xuất đầu tiên bằng Ultralytics, chẳng hạn trong image container chạy với YOLO_AUTOINSTALL=false, hãy chạy:

pip install "model-compression-toolkit>=2.4.1" "edge-mdt-cl>=1.1.0" "edge-mdt-tpc>=1.2.0" "pydantic<2.12" "imx500-converter[pt]>=3.18.2" "pulp<4"

Với các gói này, lần xuất không cài đặt gì khi đã cài YOLO_AUTOINSTALL=false trên Python 3.11 và 3.12; prediction và validation cũng chạy trong cùng môi trường. Prediction cần model-compression-toolkit, edge-mdt-cl, onnxruntime-extensions, onnx và onnxruntime; trên máy tính chỉ chạy model đã xuất, lần prediction đầu tiên sẽ cài đặt các gói này. Xem Triển khai. Quá trình xuất có các yêu cầu phiên bản sau:

Yêu cầuPhiên bản
PythonTừ 3.10 đến 3.12, đã được kiểm tra qua quá trình export. Các lần export cho trang này đã chạy với 3.10, 3.11 và 3.12; xem Các hạn chế và cách khắc phục sự cố để biết về 3.13
PyTorchQuá trình xuất không kiểm tra phiên bản; môi trường CI của Ultralytics dành cho IMX sử dụng phiên bản 2.9 trở lên và thấp hơn 2.12. Các lần xuất cho trang này chạy với 2.10.0, 2.11.0, 2.14.1 và 2.15.0
model-compression-toolkit2.4.1 trở lên. Tất cả lần xuất cho trang này đều dùng 2.5.1: uni-pytorch 3.19.0 mà imx500-converter[pt] cài đặt là phiên bản cần mct-quantizers 1.6; phiên bản này không được MCT 2.6 mới hơn chấp nhận
imx500-converter[pt]3.18.2 trở lên. Tất cả lần xuất cho trang này đều dùng 3.19.2, cùng với uni-pytorch 3.19.0
edge-mdt-cl, edge-mdt-tpc1.1.0 và 1.2.0 trở lên. Tất cả lần xuất cho trang này đều dùng 1.1.1 và 1.3.0
pydanticThấp hơn 2.12. Các lần xuất cho trang này dùng 2.11.9 và 2.11.10
pulpDưới 4, đã được kiểm tra qua quá trình export: model-compression-toolkit 2.5.1 không hoạt động với PuLP 4. Tất cả các lần export cho trang này đều sử dụng 3.3.2
Java17 trở lên để chạy trình chuyển đổi. Các lần xuất cho trang này dùng Eclipse Temurin 21.0.13
Hệ điều hànhLinux, được kiểm tra trong quá trình xuất. Các lần xuất cho trang này chạy trên Ubuntu 24.04 x86-64

Để xem các phương thức cài đặt khác, hãy tham khảo hướng dẫn cài đặt. Sau đó xuất model Ultralytics YOLO11n:

Export
from ultralytics import YOLO

# Nạp model YOLO11n
model = YOLO("yolo11n.pt")

# Xuất model sang định dạng IMX500 với lượng tử hóa INT8
model.export(format="imx")  # creates 'yolo11n_imx_model/'
# Export a YOLO11n PyTorch model to IMX500 format with INT8 quantization
yolo export model=yolo11n.pt format=imx # creates 'yolo11n_imx_model/'

Trên máy chủ AMD EPYC 9655 dùng chung với GPU NVIDIA RTX PRO 6000 Blackwell, quá trình xuất YOLO11n theo mặc định, không có đối số nào khác, mất 145 đến 458 giây khi các gói đã được cài đặt; lần xuất đầu tiên trong môi trường mới mất 154 đến 457 giây và cũng cài đặt các gói; còn khi ẩn GPU, quá trình xuất chạy trên CPU mất 156 đến 214 giây. Các lần xuất hiệu chuẩn trên 128 ảnh của coco128.yaml mất 370 đến 647 giây. Máy chủ chạy các tác vụ khác, với mức tải trung bình từ 68 đến 685.

Predict và Validate bằng thư mục Ultralytics IMX500 đã xuất sẽ chạy model_imx.onnx trên CPU của máy tính để kiểm tra model đã lượng tử hóa trước khi bạn triển khai model lên Raspberry Pi AI Camera:

Dự đoán
from ultralytics import YOLO

# Nạp model IMX500 đã xuất; Ultralytics chạy model_imx.onnx trên CPU
model = YOLO("yolo11n_imx_model")

# Chạy suy luận
results = model("https://ultralytics.com/images/bus.jpg")
# Run inference with the exported IMX500 model on the CPU
yolo predict model=yolo11n_imx_model source='https://ultralytics.com/images/bus.jpg'
Xác thực
from ultralytics import YOLO

# Tải model IMX500 đã xuất
model = YOLO("yolo11n_imx_model")

# # Đánh giá độ chính xác trên bộ dữ liệu COCO8
metrics = model.val(data="coco8.yaml")
# Validate the exported IMX500 model on the CPU
yolo val model=yolo11n_imx_model data=coco8.yaml

Các tác vụ được hỗ trợ#

Xuất Ultralytics IMX500 hỗ trợ bốn trong bảy tác vụ cho các model nano của YOLO11 và YOLOv8; phân loại cũng được hỗ trợ cho các model s của hai dòng này. Với từng tác vụ, checkpoint YOLO11n và YOLOv8n được xuất ở kích thước ảnh mặc định rồi chạy trên máy chủ xuất:

Tác vụimgsz mặc địnhYOLO11nYOLOv8npackerOut.zip (MB), YOLO11n và YOLOv8n
Phát hiện640✅✅2.3 và 2.2
Phân đoạn640✅✅2.2 và 2.2
Ngữ nghĩa———Không có checkpoint YOLO11 hoặc YOLOv8. Xuất YOLO26 thất bại với IMX export only supported for detection, pose estimation, classification, and segmentation models.
Độ sâu———Không có checkpoint YOLO11 hoặc YOLOv8. Xuất YOLO26 thất bại với IMX export is not supported for depth models.
Phân loại224✅✅2.4 và 2.3
Tư thế640✅✅2.1 và 2.1
OBB—❌❌IMX export only supported for detection, pose estimation, classification, and segmentation models.

Các họ model khác đều thất bại với IMX export only supported for YOLOv8n and YOLO11n models.: đã thử YOLO26 cho từng tác vụ, YOLO12, YOLOv10, YOLOv5nu và các model RT-DETR. Ultralytics nhận diện hai model được hỗ trợ dựa trên số layer và áp dụng các thiết lập MCT được cấu hình riêng cho từng model; do đó, model được huấn luyện từ YOLO11n hoặc YOLOv8n với các class tùy chỉnh của bạn cũng có thể xuất được: một model detection YOLO11n fine-tune từ yolo11n.pt trên 3 class đã xuất thành công. Các model s của hai họ có số layer tương đương và vượt qua bước kiểm tra đó. Chúng không phù hợp cho detection: YOLOv8s thất bại trong bước lượng tử hóa với The model cannot be quantized to meet the specified resource utilization for the following targets: {'weights': 2550540.8}, giới hạn bộ nhớ trọng số mà Ultralytics đặt ra cho detection, segmentation và pose; YOLO11s được lượng tử hóa nhưng sau đó thất bại trong trình chuyển đổi IMX500 với Not enough memory, available: 8.00MB , required: 9.53MB. Classification không có giới hạn này; YOLO11s-cls và YOLOv8s-cls đã xuất thành công và phù hợp, với các file packerOut.zip có kích thước 5.7 và 5.4 MB, sử dụng lần lượt 7.33MB và 6.93MB bộ nhớ. YOLO11m-cls và YOLOv8m-cls có nhiều layer hơn và thất bại với IMX export only supported for YOLOv8n and YOLO11n models.; theo bước kiểm tra layer trong code, các model detection lớn hơn cũng sẽ thất bại, nhưng chưa được chạy thử.

Các tham số xuất model#

Đối sốKiểuMặc địnhMô tả
formatstr'imx'Định dạng đích của model đã xuất, xác định khả năng tương thích với nhiều môi trường triển khai.
imgszint hoặc tuplekích thước checkpointKích thước ảnh đầu vào của model, được cố định trong quá trình xuất: một số nguyên cho ảnh vuông hoặc một tuple (height, width). Nếu không được truyền vào, quá trình xuất dùng kích thước mà checkpoint đã được huấn luyện: 640 cho detect, segment và pose, và 224 cho classify. Xem Kích thước ảnh.
quantizeint hoặc strNoneĐộ chính xác số học. Nếu không đặt, 8, 'int8' và 'w8a8' sẽ tạo model INT8, độ chính xác số học duy nhất được hỗ trợ; xem Độ chính xác số học. Thay thế các flag half/int8 đã lỗi thời.
datastrNoneTệp YAML của dataset chứa ảnh hiệu chuẩn; với phân loại, thay vào đó hãy truyền thư mục dataset hoặc tên dataset tích hợp. Nếu bỏ qua, Ultralytics dùng dataset mặc định nhỏ của tác vụ, chẳng hạn coco8.yaml cho phát hiện. Xem Hiệu chuẩn.
fractionfloat, int hoặc list1.0Tập con hiệu chuẩn: tỷ lệ, số lượng ảnh (số nguyên lớn hơn 1) hoặc danh sách [train, val, test]; mục nhập của tập chia hiệu chuẩn sẽ được sử dụng.
nmsbool, không bắt buộcNoneCác lần xuất detection, segmentation và pose luôn nhúng NMS: None và False ghi log IMX export requires nms=True, setting nms=True.. Model classification từ chối nms=True. Xem Định dạng đầu ra.
conffloatNoneNgưỡng score của NMS được nhúng; mặc định là 0.25 nếu không được đặt. Giá trị này được cố định trong model; xem Ngưỡng trong model.
ioufloatNoneNgưỡng IoU của NMS được nhúng; mặc định là 0.5 nếu không được đặt và được cố định trong model.
max_detint500Số detections mà NMS nhúng trả về, được cố định trong model. Các giá trị lớn hơn 500, là giới hạn của converter, sẽ được giảm xuống mức này.
devicestrNoneThiết bị dùng để lượng tử hóa. Khi không có device hoặc có device=cpu, quá trình export sử dụng GPU CUDA đầu tiên nếu khả dụng và ghi log IMX export uses CUDA if available, setting device=0. Use CUDA_VISIBLE_DEVICES='' for CPU.. Để lượng tử hóa trên CPU của máy tính có GPU, hãy ẩn GPU bằng CUDA_VISIBLE_DEVICES=""; xem Các hạn chế và cách khắc phục sự cố. Trình chuyển đổi IMX500 chạy trên CPU.

Để biết các đối số dùng chung cho mọi định dạng, hãy xem tài liệu chế độ Export.

Precision#

IMX500 chạy các model INT8, vì vậy quá trình xuất luôn lượng tử hóa model bằng MCT:

quantizeKết quả
để trốngINT8.
8, 'int8' hoặc 'w8a8'INT8, giống như khi không đặt; int8=True cũ cũng vậy
16 hoặc 'fp16'Thất bại với quantize=16 (FP16) is not supported; format='imx' supports quantize=8 (INT8). See https://docs.ultralytics.com/modes/export#quantization-options; half=True cũ cũng vậy
32 hoặc 'fp32'Không chạy được với quantize=32 (FP32) is not supported; format='imx' supports quantize=8 (INT8). See https://docs.ultralytics.com/modes/export#quantization-options
'w8a16' hoặc 'w8a32'Thất bại với quantize='w8a16' is not supported; format='imx' supports quantize=8 (INT8). See https://docs.ultralytics.com/modes/export#quantization-options và thông báo tương tự cho 'w8a32'

Ultralytics thực hiện lượng tử hóa sau huấn luyện bằng MCT với thiết lập nền tảng đích IMX500 của edge-mdt-tpc. Các layer trong head detection, segmentation và pose dùng để giải mã bbox và keypoint được giữ ở mức kích hoạt 16-bit; MCT tự tìm kiếm độ chính xác hỗn hợp để chọn độ rộng bit của trọng số sao cho model vừa với bộ nhớ của cảm biến. Quá trình xuất chỉ sử dụng lượng tử hóa sau huấn luyện: lượng tử hóa sau huấn luyện dựa trên gradient (GPTQ) và huấn luyện nhận biết lượng tử hóa của MCT không khả dụng thông qua model.export().

Hiệu chuẩn#

Quá trình xuất lượng tử hóa model bằng phương pháp lượng tử hóa sau huấn luyện của MCT: MCT chạy model trên các ảnh hiệu chuẩn để đo phạm vi của từng activation. Ultralytics truyền cho MCT split val của data, hoặc split do bạn cung cấp. Nếu không có data, quá trình xuất dùng tập dữ liệu mặc định nhỏ của tác vụ và ghi log INT8 export requires a missing 'data' arg for calibration. Using default 'data=coco8.yaml'., chẳng hạn; với detection, tập dữ liệu này có 4 ảnh và quá trình xuất cũng ghi log >300 images recommended for INT8 calibration, found 4 images.. Model classification sử dụng 12 ảnh của imagenet10.

  • Số lượng ảnh: quá trình xuất của Ultralytics sử dụng mọi ảnh trong split: 128 ảnh với coco128.yaml, 64 ảnh với fraction=0.5 và 10 ảnh với fraction=10.
  • Tăng số lượng ảnh chỉ cải thiện đôi chút: trên 500 ảnh COCO trong các benchmark, chạy trên máy chủ xuất, hiệu chuẩn bằng 500 ảnh đầu tiên của COCO train2017 thay vì 4 ảnh mặc định làm thay đổi độ chính xác từ -2.9 đến 2.9 điểm mAP50-95 với conf=0.001 (mỗi tập được xuất một lần); với detection YOLO11n và YOLOv8n, coco128.yaml cùng conf=0.001 lần lượt đạt 38.0 và 36.7. Hãy hiệu chuẩn bằng ảnh từ dữ liệu triển khai của bạn và validation kết quả; xem Triển khai.
  • Thời gian: các ảnh hiệu chuẩn được đưa qua MCT. Trên máy chủ dùng chung, trong các lần chạy đo độ chính xác, việc xuất sáu model detection, segmentation và pose YOLO11n và YOLOv8n mất 150 đến 314 giây với hiệu chuẩn mặc định, và 591 đến 1655 giây với 500 ảnh.

Ngưỡng trong model#

Các lần xuất detection, segmentation và pose kết thúc bằng NMS của model, và IMX500 chạy NMS trên cảm biến; do đó, conf, iou và max_det của quá trình xuất được cố định trong packerOut.zip và model_imx.onnx. Nếu không có conf, quá trình xuất dùng 0.25, ngưỡng score mặc định của prediction. conf được truyền sau đó cho predict hoặc val chỉ có thể loại bỏ thêm detection; xem Triển khai.

Điều này làm giảm độ chính xác mà val báo cáo, vì chỉ số này tính cả các detection có score thấp: trên 500 ảnh COCO trong các benchmark, lần xuất mặc định thấp hơn PyTorch từ 5.5 đến 14.2 điểm mAP50-95; cùng lần xuất đó với conf=0.001 thì thấp hơn từ 1.1 đến 10.6 điểm. Dù sao, các script camera trong Raspberry Pi AI Camera cũng chỉ giữ detection trên 0.4 hoặc 0.55. Để đo độ chính xác của quá trình lượng tử hóa, hãy xuất model Ultralytics YOLO11n thứ hai với conf=0.001 để validation:

Ví dụ
from ultralytics import YOLO

model = YOLO("yolo11n.pt")

# Giữ lại các detection có score từ 0.001 trở lên như khi validation, sau đó chạy validation trên máy chủ xuất
model.export(format="imx", conf=0.001)  # overwrites 'yolo11n_imx_model/'
metrics = YOLO("yolo11n_imx_model").val(data="coco8.yaml")
# Keep detections down to a score of 0.001, as validation does, then validate on the export host
yolo export model=yolo11n.pt format=imx conf=0.001 # overwrites 'yolo11n_imx_model/'
yolo val model=yolo11n_imx_model data=coco8.yaml

Kích thước ảnh#

IMX500 có 8 MB bộ nhớ dành cho model và activation; trình chuyển đổi báo cáo trong model_imx_MemoryReport.json dung lượng bộ nhớ mà model đã biên dịch sử dụng. Bảng liệt kê bộ nhớ đó theo MB cho YOLO11n / YOLOv8n tại mỗi imgsz đã xuất, với hiệu chuẩn mặc định; mỗi kích thước vuông được xuất—từ 256 đến 704 pixel, theo bước 64 pixel—đều được biên dịch cho cả hai model và cả ba tác vụ, còn packerOut.zip nằm trong khoảng 2.1 đến 2.3 MB:

imgszDetectSegmentTư thế
2563.45 / 3.453.38 / 3.493.41 / 3.40
3203.78 / 3.783.71 / 3.823.74 / 3.72
3844.35 / 4.354.28 / 4.384.30 / 4.30
4484.81 / 4.804.77 / 4.884.76 / 4.76
5125.57 / 5.565.49 / 5.595.53 / 5.52
5766.21 / 6.186.29 / 6.406.17 / 6.15
6407.17 / 7.147.18 / 7.287.13 / 7.12
7047.90 / 7.857.79 / 7.897.85 / 7.84
1280Thất bại: #boxes X #classes exceeds the supported limit of 2097120Thất bại, như với detectionThất bại: cần 19.73 / 19.71 MB
(480, 640)Xuất thành côngXuất thành côngXuất thành công
  • 704 pixel chiếm từ 97 đến 99% bộ nhớ theo báo cáo của trình chuyển đổi; với các model segmentation, trình chuyển đổi ghi log ConvFe failed with insufficient memory, trying to run Tiling Advisor trước rồi mới biên dịch model.
  • 1280 pixel: các lần xuất detection và segmentation thất bại trong trình chuyển đổi. Trình chuyển đổi hỗ trợ tối đa 2,097,120 bbox nhân với số class trong NMS của model, trong khi kích thước 1280 pixel tạo ra 33,600 bbox cho 80 class; các lần xuất pose thất bại với Not enough memory, available: 8.00MB , required: 19.73MB (19.71 MB đối với YOLOv8n). Sau đó, quá trình xuất lần lượt thất bại với returned non-zero exit status 3. và 1..
  • Các model classification được biên dịch ở từng kích thước đã xuất: 128, 160, 224, 288, 320, 384, 448, 512 và 640 pixel, sử dụng từ 2.96MB đến 7.28MB bộ nhớ.
  • Độ chính xác ở các kích thước khác chưa được đo cho trang này; hãy validation kích thước bạn chọn trên dữ liệu của mình, xem Triển khai. Các script camera trong Raspberry Pi AI Camera được viết cho kích thước mặc định.

Định dạng đầu ra#

Quá trình xuất ghi một thư mục yolo11n_imx_model/ có kích thước 14.7 MB cho YOLO11n, bên cạnh file .pt; log xuất in kích thước theo MiB dưới dạng (14.0 MB). Chỉ cần packerOut.zip và labels.txt trên Raspberry Pi; model_imx.onnx dùng để kiểm thử trên máy tính. Kích thước file tính theo MB (10^6 byte):

FileKích thước (MB)Nội dung
packerOut.zip2.3Model đã biên dịch dành cho cảm biến IMX500, được sao chép sang Raspberry Pi; tại đó, các công cụ IMX500 chuyển model thành file firmware của camera
labels.txt<0.01Tên các class, mỗi dòng một tên, dùng cho ứng dụng trên camera
model_imx.onnx10.9Model đã lượng tử hóa với các toán tử quantizer MCT và NMS của model; YOLO() chạy model này trên CPU của máy tính, cùng metadata Ultralytics được nhúng bên trong
model_imx.pbtxt1.5Đồ thị của model đã biên dịch dưới dạng văn bản, do trình chuyển đổi ghi ra
dnnParams.xml<0.01Các tensor đầu vào và đầu ra của model đã biên dịch, cũng nằm trong packerOut.zip
model_imx_MemoryReport.json<0.01Bộ nhớ model sử dụng trên cảm biến: 7.17MB trong tổng số 8.00MB đối với YOLO11n detection

model_imx.onnx nhận một đầu vào có tên input với kích thước (batch, 3, 640, 640): ảnh RGB, theo định dạng channels first, dưới dạng float32 được scale về 0-1, tương tự bản export ONNX; các model classification nhận (batch, 3, 224, 224). Kích thước batch không cố định. Các model detection, segmentation và pose kết thúc bằng NMS của model, vì vậy đầu ra là các detections sau NMS, với sức chứa 500, giá trị max_det của bản export. Các kích thước dưới đây áp dụng cho một ảnh và giống nhau đối với YOLO11n và YOLOv8n:

Tác vụĐầu ra
DetectBBox (1, 500, 4) float32, score (1, 500) float32, chỉ số class (1, 500) int32 và số lượng detection (1, 1) int32
SegmentBBox, score và chỉ số class như với detection, tiếp theo là các hệ số mask (1, 500, 32) float32 và prototype mask (1, 32, 160, 160) float32
Phân loại(1, 1000) float32: xác suất cho từng class trong số 1000 class ImageNet
Tư thếBBox, score và chỉ số class như với detection, tiếp theo là 17 keypoint x 3 giá trị (1, 500, 51) float32
  • BBox: các góc x1, y1, x2, y2 tính theo pixel của đầu vào 640x640. Các lần xuất detection cũng trả về số lượng detection hợp lệ; các hàng phía sau là phần đệm. Các lần xuất segmentation và pose không trả về số lượng, vì vậy hãy lọc các hàng theo score.
  • NMS: NMS của model giữ lại các detection có score cao hơn conf và loại bỏ các detection chồng lấn vượt quá iou, với giá trị được đặt khi xuất: mặc định là 0.25 và 0.5. Xem Ngưỡng trong model. nms=False cho ra cùng model; head không dùng NMS của YOLO26 không khả dụng vì YOLO26 không xuất được.
  • Segmentation: nhân 32 hệ số mask của từng detection với các prototype (32, 160, 160) để tạo mask tương ứng, như trong xuất ONNX.
  • Metadata: model_imx.onnx lưu metadata Ultralytics (names, task, imgsz, stride, args) trong metadata ONNX của model; YOLO() đọc metadata này, còn labels.txt chứa tên class dành cho camera.

Trên bus.jpg, các detection của model_imx.onnx được so sánh với detection từ xuất ONNX FP32 của cùng checkpoint, chạy bằng YOLO() với đầu vào 640x640 (224x224 cho classification) trên máy chủ xuất x86-64, mỗi tác vụ dùng một ảnh. Một detection được tính là khớp khi class giống nhau và bbox chồng lấn với IoU lớn hơn 0.5:

Tác vụYOLO11nYOLOv8n
Detect5 trong 5 detection ONNX khớp; 5 detection, bbox lệch không quá 12 px5 trong 5 detection ONNX khớp; 5 detection, bbox lệch không quá 33 px
Segment5 trong 5 detection ONNX khớp; 5 detection, bbox lệch không quá 17 px, IoU mask ≥ 0.844 trong 6 detection ONNX khớp; 4 detection, bbox lệch không quá 50 px, IoU mask ≥ 0.94
Phân loạiCùng class top-1, score top-1 0.57 → 0.62Cùng class top-1, score top-1 0.51 → 0.64
Tư thế4 trong 4 detection ONNX khớp; 4 detection, bbox lệch không quá 5 px, keypoint lệch không quá 28 px4 trong 4 detection ONNX khớp; 4 detection, bbox lệch không quá 13 px, keypoint lệch không quá 29 px

Bảy trong tám model INT8 tìm thấy cùng đối tượng như ONNX; YOLOv8n-seg tìm thấy 4 trong 6 detection ONNX. Sai khác lớn nhất ở một góc bbox là 50 pixel trên ảnh cao 1080 pixel; score INT8 cũng khác ONNX, vì vậy hãy validation model INT8 trên dữ liệu của riêng bạn. Xem Benchmark để biết độ chính xác trên COCO.

Chạy bằng ONNX Runtime#

Để chạy bản xuất Ultralytics IMX500 trong code Python của riêng bạn trên máy tính, hãy nạp model_imx.onnx bằng ONNX Runtime cùng các tùy chọn session của mct-quantizers để đăng ký các toán tử quantizer MCT, giống như Ultralytics thực hiện. Ví dụ này cần các gói được cài đặt trong lần prediction Ultralytics đầu tiên và một ảnh bus.jpg trong thư mục làm việc:

import mct_quantizers as mctq
import numpy as np
import onnxruntime as ort
from edgemdt_cl.pytorch.nms import nms_ort  # noqa: F401, registers the NMS operator of the model
from PIL import Image

# Export first: yolo export model=yolo11n.pt format=imx
options = mctq.get_ort_session_options()  # registers the MCT quantizer operators
options.enable_mem_reuse = False  # as Ultralytics does; without it, some models fail with a buffer shape mismatch
session = ort.InferenceSession("yolo11n_imx_model/model_imx.onnx", options, providers=["CPUExecutionProvider"])
labels = open("yolo11n_imx_model/labels.txt").read().splitlines()

# Letterbox the RGB image to 640x640 with gray padding, channels first, scaled to 0-1
image = Image.open("bus.jpg").convert("RGB")
r = 640 / max(image.size)
w, h = round(image.width * r), round(image.height * r)
canvas = Image.new("RGB", (640, 640), (114, 114, 114))
canvas.paste(image.resize((w, h), Image.BILINEAR), ((640 - w) // 2, (640 - h) // 2))
x = np.asarray(canvas, dtype=np.float32).transpose(2, 0, 1)[None] / 255

boxes, scores, classes, n = session.run(None, {"input": x})
for box, score, c in zip(boxes[0][: n[0, 0]], scores[0], classes[0]):
    x1, y1, x2, y2 = (box - [(640 - w) // 2, (640 - h) // 2] * 2) / r  # back to the original image
    print(f"{labels[c]} {score:.2f} [{x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f}]")

Với YOLO11n, đoạn code này in ra cùng 5 đối tượng trong bus.jpg như YOLO(), nhưng score và góc bbox hơi khác: ví dụ này resize bằng Pillow, trong khi Ultralytics resize bằng OpenCV. Bbox tính theo pixel của đầu vào 640x640 cho đến dòng cuối, nơi chúng được ánh xạ trở lại ảnh.

Triển khai#

YOLO("yolo11n_imx_model") nạp model_imx.onnx từ thư mục rồi chạy bằng ONNX Runtime trên CPU, với các toán tử quantizer MCT của mct-quantizers và toán tử NMS của edge-mdt-cl. Cách này kiểm tra model Ultralytics đã lượng tử hóa trên máy tính trước khi bạn sao chép model sang camera; IMX500 không được sử dụng. Các điểm dưới đây được kiểm thử trên máy chủ xuất x86-64 với các bản sao của một lần xuất YOLO11n:

  • Chỉ dùng CPU: Ultralytics chạy model bằng CPU execution provider của ONNX Runtime, kể cả khi bạn truyền device=0. Các toán tử quantizer MCT khiến quá trình chạy chậm: trên 32 CPU của máy chủ xuất dùng chung, giai đoạn inference của val mất 2032 đến 4078 ms mỗi ảnh đối với tám lần xuất detection YOLO11n và YOLOv8n trong các benchmark, trong khi các lần xuất ONNX FP32 tương ứng mất 18.1 đến 18.5 ms trong cùng lượt chạy. Đây không phải tốc độ trên camera; xem Benchmark.
  • Kích thước đầu vào cố định: model chỉ chạy ở kích thước được export imgsz, mà YOLO() đọc từ metadata, vì vậy predict và val chạy ở kích thước đó, kể cả với bản export hình chữ nhật như imgsz=(480, 640), đồng thời thay thế một imgsz được truyền vào bằng kích thước này; hãy export lại để thay đổi kích thước.
  • Batch: batch size không cố định. Một danh sách gồm ba ảnh trả về ba kết quả, kể cả với batch=3; val cũng chạy với batch=4, đạt 48.1 mAP50-95 trên COCO8 trên máy chủ xuất x86-64, so với 47.1 khi dùng batch=1.
  • Ngưỡng: NMS của model chỉ giữ lại các detection có score cao hơn conf của quá trình xuất. Với giá trị mặc định 0.25, predict dùng conf=0.1 cho ra cùng 5 detection trên bus.jpg như cấu hình mặc định, còn conf=0.5 cho ra 4 detection. Xem Ngưỡng trong model.
  • Tên thư mục: Ultralytics nhận diện định dạng dựa trên _imx_model trong tên thư mục, không phân biệt chữ hoa chữ thường; metadata chỉ được đọc khi tên thư mục kết thúc bằng chuỗi này. Thư mục tên mymodel sẽ thất bại với model='mymodel' is not a supported model format., còn thư mục tên yolo11n_imx_model_v2 được nạp mà không có metadata và trả về kết quả sai nhưng không báo lỗi: tên class class0, class1 và tiếp theo, cùng score lớn hơn 1. Bạn có thể đổi tên thư mục tùy ý, nhưng hãy giữ _imx_model ở cuối, chẳng hạn custom_imx_model.
  • Các tệp cần tải: YOLO() chỉ cần tệp .onnx trong thư mục, với tên bất kỳ; một thư mục chỉ chứa model_imx.onnx được tải cùng với tên lớp và tác vụ của nó. Nó tải tệp .onnx đầu tiên tìm thấy, vì vậy hãy chỉ giữ một tệp trong đó. Tải trực tiếp tệp model_imx.onnx thay vì thư mục của nó sẽ khiến tệp được xử lý như một model ONNX thuần: trên máy tính có GPU CUDA, trước tiên nó cài đặt onnxruntime-gpu, gói này trong môi trường của trang này (1.32.0) đã thay thế protobuf 4.25.5 mà trình chuyển đổi IMX500 ghim phiên bản, bằng phiên bản 7.36.2, sau đó gặp lỗi mct_quantizers:ActivationPOTQuantizer(-1) is not a registered function/op.
  • macOS: trên máy Mac dùng Apple silicon, YOLO() đã tải một thư mục được xuất trên Linux, cài đặt các gói cần thiết và tìm thấy cùng 5 đối tượng trong bus.jpg. Khi xác thực trên COCO8, kết quả đạt 48.9 mAP50-95 với MCT 2.6.2 và mct-quantizers 1.7.0, so với 47.1 trên máy chủ xuất x86-64 với MCT 2.5.1 và mct-quantizers 1.6.0; cả hai đều dùng ONNX Runtime 1.32.0. Bản thân quá trình xuất chỉ chạy trên Linux.

Camera Raspberry Pi AI#

Các bước bên dưới được giữ nguyên từ những phiên bản trước của trang này, được viết với ultralytics 8.3.28 đến 8.3.234. Trang này không có Raspberry Pi AI Camera để thử nghiệm, vì vậy các bước chưa được chạy trên camera. Trên máy tính x86-64, lệnh ở Bước 4 đã cài đặt modlib 1.5.0 của Sony, các import của bốn script đều được phân giải và lớp model của từng script đã tải packerOut.zip cùng labels.txt từ bản xuất Ultralytics được tạo cho trang này; sau đó AiCamera() dừng với ImportError: libcamera module is not available..., như dự kiến khi không có camera. Thư viện mô-đun ứng dụng liệt kê Raspberry Pi OS Bookworm với Python 3.11 và Raspberry Pi OS Trixie với Python 3.13; ghi chú bên dưới nêu bản phát hành mà các bước này được thử nghiệm lần đầu.

Sau khi xuất model Ultralytics YOLO11n sang định dạng IMX500, bạn có thể triển khai model lên Raspberry Pi AI Camera để chạy inference.

Yêu cầu phần cứng#

Đảm bảo bạn có phần cứng sau:

  1. Raspberry Pi 5 hoặc Raspberry Pi 4 Model B
  2. Camera Raspberry Pi AI

Kết nối Raspberry Pi AI Camera với đầu nối MIPI CSI 15 chân trên Raspberry Pi, sau đó bật nguồn Raspberry Pi.

Yêu cầu phần mềm#

Lưu ý

Hướng dẫn này đã được kiểm thử với Raspberry Pi OS Bookworm chạy trên Raspberry Pi 5.

Bước 1: Mở cửa sổ terminal và chạy các lệnh sau để cập nhật phần mềm Raspberry Pi lên phiên bản mới nhất.

sudo apt update && sudo apt full-upgrade

Bước 2: Cài đặt firmware IMX500 cần thiết để vận hành cảm biến IMX500.

sudo apt install imx500-all

Bước 3: Khởi động lại Raspberry Pi để áp dụng các thay đổi.

sudo reboot

Bước 4: Cài đặt thư viện module ứng dụng AITRIOS cho Raspberry Pi

pip install git+https://github.com/SonySemiconductorSolutions/aitrios-rpi-application-module-library.git

Bước 5: Chạy phát hiện đối tượng, ước tính pose, phân loại và phân đoạn YOLO11 bằng các script sau, có trong các ví dụ của thư viện module ứng dụng aitrios-rpi.

Lưu ý

Đảm bảo thay thế các thư mục model_file và labels.txt cho phù hợp với môi trường của bạn trước khi chạy các script này.

Script Python
import numpy as np
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_od_yolo_ultralytics

class YOLO(Model):
    """YOLO model for IMX500 deployment."""

    def __init__(self):
        """Initialize the YOLO model for IMX500 deployment."""
        super().__init__(
            model_file="yolo11n_imx_model/packerOut.zip",  # replace with proper directory
            model_type=MODEL_TYPE.CONVERTED,
            color_format=COLOR_FORMAT.RGB,
            preserve_aspect_ratio=False,
        )

        self.labels = np.genfromtxt(
            "yolo11n_imx_model/labels.txt",  # replace with proper directory
            dtype=str,
            delimiter="\n",
        )

    def post_process(self, output_tensors):
        """Post-process the output tensors for object detection."""
        return pp_od_yolo_ultralytics(output_tensors)

device = AiCamera(frame_rate=16)  # Optimal frame rate for maximum FPS of the YOLO model running on the AI Camera
model = YOLO()
device.deploy(model)

annotator = Annotator()

with device as stream:
    for frame in stream:
        detections = frame.detections[frame.detections.confidence > 0.55]
        labels = [f"{model.labels[class_id]}: {score:0.2f}" for _, score, class_id, _ in detections]

        annotator.annotate_boxes(frame, detections, labels=labels, alpha=0.3, corner_radius=10)
        frame.display()
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_yolo_pose_ultralytics

class YOLOPose(Model):
    """YOLO pose estimation model for IMX500 deployment."""

    def __init__(self):
        """Initialize the YOLO pose estimation model for IMX500 deployment."""
        super().__init__(
            model_file="yolo11n-pose_imx_model/packerOut.zip",  # thay bằng thư mục phù hợp
            model_type=MODEL_TYPE.CONVERTED,
            color_format=COLOR_FORMAT.RGB,
            preserve_aspect_ratio=False,
        )

    def post_process(self, output_tensors):
        """Post-process the output tensors for pose estimation."""
        return pp_yolo_pose_ultralytics(output_tensors)

device = AiCamera(frame_rate=17)  # Tốc độ khung hình tối ưu để đạt FPS tối đa cho model YOLO-pose chạy trên AI Camera
model = YOLOPose()
device.deploy(model)

annotator = Annotator()

with device as stream:
    for frame in stream:
        detections = frame.detections[frame.detections.confidence > 0.4]

        annotator.annotate_keypoints(frame, detections)
        annotator.annotate_boxes(frame, detections, corner_length=20)
        frame.display()
import cv2
import numpy as np
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_cls

class YOLOClassification(Model):
    """YOLO classification model for IMX500 deployment."""

    def __init__(self):
        """Initialize the YOLO classification model for IMX500 deployment."""
        super().__init__(
            model_file="yolo11n-cls_imx_model/packerOut.zip",  # replace with proper directory
            model_type=MODEL_TYPE.CONVERTED,
            color_format=COLOR_FORMAT.RGB,
            preserve_aspect_ratio=False,
        )

        self.labels = np.genfromtxt("yolo11n-cls_imx_model/labels.txt", dtype=str, delimiter="\n")

    def post_process(self, output_tensors):
        """Post-process the output tensors for classification."""
        return pp_cls(output_tensors)

device = AiCamera()
model = YOLOClassification()
device.deploy(model)

annotator = Annotator()

with device as stream:
    for frame in stream:
        for i, label in enumerate([model.labels[id] for id in frame.detections.class_id[:3]]):
            text = f"{i + 1}. {label}: {frame.detections.confidence[i]:.2f}"
            cv2.putText(frame.image, text, (50, 30 + 40 * (i + 1)), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (100, 0, 100), 2)

        frame.display()
import numpy as np
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_yolo_segment_ultralytics

class YOLOSegment(Model):
    """YOLO segmentation model for IMX500 deployment."""

    def __init__(self):
        """Initialize the YOLO segmentation model for IMX500 deployment."""
        super().__init__(
            model_file="yolo11n-seg_imx_model/packerOut.zip",  # replace with proper directory
            model_type=MODEL_TYPE.CONVERTED,
            color_format=COLOR_FORMAT.RGB,
            preserve_aspect_ratio=False,
        )

        self.labels = np.genfromtxt(
            "yolo11n-seg_imx_model/labels.txt",  # replace with proper directory
            dtype=str,
            delimiter="\n",
        )

    def post_process(self, output_tensors):
        """Post-process the output tensors for instance segmentation."""
        return pp_yolo_segment_ultralytics(output_tensors)

device = AiCamera(frame_rate=17)  # Optimal frame rate for maximum FPS of the YOLO-seg model running on the AI Camera
model = YOLOSegment()
device.deploy(model)

annotator = Annotator()

with device as stream:
    for frame in stream:
        detections = frame.detections[frame.detections.confidence > 0.4]

        labels = [f"{model.labels[c]}" for m, c, s, _, _ in detections]
        annotator.annotate_instance_segments(frame, detections)
        annotator.annotate_boxes(frame, detections, labels=labels)
        frame.display()

Hướng dẫn triển khai#

Giới hạn và khắc phục sự cố#

  • pip 24.0 đến 25.0: ResolutionImpossible: trong môi trường mới tạo bằng python3 -m venv trên Ubuntu 24.04, vốn có pip 24.0, quá trình cài đặt các gói IMX dừng với Cannot install imx500-converter>=3.18.2 and imx500-converter[pt]==3.19.2 because these package versions have conflicting dependencies., còn lần xuất đầu tiên, vốn cài đặt các gói đó bằng cùng phiên bản pip, sau đó gặp lỗi No module named 'model_compression_toolkit'. pip 24.2, 24.3.1 và 25.0 cũng dừng theo cách tương tự; pip 23.0.1, 25.1 và 26.3 phân giải được cùng các gói đó. Trước tiên, hãy chạy pip install --upgrade pip như trong Hướng dẫn bắt đầu nhanh.
  • Python 3.13 trở lên: quá trình xuất dừng với IMX export requires Python>=3.10,<3.13. trước khi cài đặt bất kỳ thứ gì. Trình chuyển đổi IMX500 không cài đặt được trên phiên bản này: gói uni-pytorch yêu cầu Python thấp hơn 3.13 và pip dừng với No matching distribution found for ortools==9.9.3963 (from conv-allocator). Bản thân MCT cài đặt được trên Python 3.13: khi bỏ kiểm tra phiên bản Python của quá trình xuất để thử nghiệm, bước lượng tử hóa chạy xong nhưng quá trình xuất sau đó gặp lỗi FileNotFoundError: imxconv-pt not found. Install with: pip install imx500-converter[pt]. Để xuất, hãy dùng Python 3.10 đến 3.12; Python 3.13 hệ thống của Raspberry Pi OS Trixie không thể chạy quy trình này.
  • macOS và Windows: quá trình xuất dừng với Export only supported on Linux. See https://developer.aitrios.sony-semicon.com/en/docs/raspberry-pi-ai-camera/imx500-converter?version=3.17.3&progLang= trên macOS; cùng bước kiểm tra đó cũng khiến quá trình dừng trên Windows, nơi chưa chạy thử. Hãy xuất trên Linux hoặc bằng Ultralytics Platform; YOLO() vẫn có thể chạy thư mục đã xuất trên máy Mac, xem Triển khai.
  • Không có Java: nếu không có java trên PATH, quá trình xuất chạy sudo apt để cài đặt openjdk-21-jre trên Ubuntu và Debian 13 trở lên, hoặc openjdk-17-jre trên Debian 12 và Raspberry Pi OS Bookworm; trên Ubuntu, trước tiên nó ghi log Ultralytics requirement ['openjdk-21-jre'] not found, attempting AutoUpdate...; trên các bản phân phối Linux khác, nó không cài đặt gì. Nếu không có quyền sudo, nó ghi log Command '['sudo', 'apt', 'update']' returned non-zero exit status 1., lượng tử hóa model rồi gặp lỗi trong trình chuyển đổi với java: command not found và returned non-zero exit status 127.. Hãy cài đặt Java 17 trở lên, xem Hướng dẫn bắt đầu nhanh.
  • Tắt tự động cài đặt: khi dùng YOLO_AUTOINSTALL=false và pip install ultralytics thông thường, quá trình xuất ghi log Ultralytics requirements ['model-compression-toolkit>=2.4.1', 'edge-mdt-cl>=1.1.0', 'edge-mdt-tpc>=1.2.0', 'pydantic<2.12', 'imx500-converter[pt]>=3.18.2', 'pulp<4'] not found, AutoUpdate disabled by YOLO_AUTOINSTALL=False rồi gặp lỗi No module named 'model_compression_toolkit'. Hãy cài đặt các gói trước, xem Hướng dẫn bắt đầu nhanh.
  • Model và kích thước khác: các dòng model và kích thước khác được thử nghiệm đều gặp lỗi, phần lớn với IMX export only supported for YOLOv8n and YOLO11n models.; ngoại lệ là tác vụ phân loại, trong đó các model s cũng xuất được, xem Các tác vụ được hỗ trợ.
  • Phân đoạn ngữ nghĩa, ước lượng độ sâu và OBB: model phân đoạn ngữ nghĩa gặp lỗi IMX export only supported for detection, pose estimation, classification, and segmentation models., model độ sâu gặp lỗi IMX export is not supported for depth models., còn model OBB gặp cùng thông báo lỗi như model phân đoạn ngữ nghĩa.
  • batch, dynamic, opset, simplify, optimize và workspace: batch khác 1, dynamic=True, mọi opset, simplify=False, optimize=True và mọi workspace đều gặp lỗi argument 'batch' is not supported for format='imx' cùng thông báo tương tự cho các trường hợp còn lại; các giá trị mặc định hoạt động bình thường. Dù sao thì model đã xuất vẫn chấp nhận mọi kích thước batch, xem Triển khai.
  • nms: model phát hiện, phân đoạn và pose luôn nhúng NMS, còn nms=None hoặc nms=False ghi log IMX export requires nms=True, setting nms=True.. Model phân loại gặp lỗi 'nms=True' is not valid for classification models..
  • device=cpu trên máy tính có GPU: khi GPU CUDA hiển thị, quá trình export với device=cpu sẽ lượng tử hóa trên GPU đầu tiên, giống như khi không có device: MCT 2.5.1 và mct-quantizers 1.6.0 đặt tensor trên GPU bất cứ khi nào PyTorch phát hiện GPU. Để lượng tử hóa trên CPU, hãy ẩn GPU bằng CUDA_VISIBLE_DEVICES=""; khi không có GPU nào hiển thị, quá trình export có và không có device=cpu đều hoàn tất.
  • Kích thước ảnh lớn: ở imgsz=1280, quá trình xuất model phát hiện và phân đoạn gặp lỗi trong trình chuyển đổi với #boxes X #classes exceeds the supported limit of 2097120, còn model pose gặp lỗi với Not enough memory, available: 8.00MB , required: 19.73MB (19.71 MB đối với YOLOv8n); hãy xuất ở kích thước 704 pixel trở xuống, xem Kích thước ảnh.
  • Các lần xuất lặp lại cho kết quả khác nhau: 5 lần xuất YOLO11n với cùng thiết lập mặc định, gồm 3 lần trên GPU và 2 lần trên CPU, tạo ra 5 tệp packerOut.zip khác nhau, có kích thước từ 2,291,836 đến 2,292,214 byte và đạt 30.3 đến 32.1 mAP50-95 trên 500 ảnh COCO trong bộ benchmark. Hãy so sánh các bản xuất trên dữ liệu xác thực của chính bạn thay vì chỉ dựa vào một lần chạy.
  • Thư mục đầu ra: mỗi lần xuất cùng một checkpoint sẽ xóa và ghi lại yolo11n_imx_model/, bất kể imgsz, data hay conf của nó là gì; vì vậy, hãy đổi tên thư mục trước khi xuất biến thể thứ hai và giữ _imx_model ở cuối tên.
  • Thông báo trong log xuất: MCT ghi log OperatorSetNames.DEPTHWISE_CONV is not in model. và, nếu có ít hơn 10 ảnh hiệu chuẩn, ghi log Not enough images in representative dataset to generate 10 data points, only 4 were generated; cả hai đều không làm dừng quá trình xuất.
  • Xuất trên Raspberry Pi: quá trình xuất chỉ kiểm tra Linux và Python 3.10 đến 3.12, vì vậy không dừng trên Raspberry Pi OS Bookworm với Python 3.11, nhưng trường hợp này chưa được chạy thử cho trang; bộ kiểm thử Ultralytics bỏ qua quá trình xuất IMX trên Raspberry Pi vì đã hết bộ nhớ trên Raspberry Pi 5 có 16 GB. Hãy xuất trên một máy tính Linux khác rồi sao chép packerOut.zip và labels.txt sang Raspberry Pi.

Đối với các lỗi khác, hãy xem hướng dẫn về các sự cố thường gặp.

Benchmark#

Trang này không có Raspberry Pi AI Camera để thử nghiệm, vì vậy tốc độ và độ chính xác của các model trên IMX500 chưa được đo lại. Các bảng bên dưới giữ nguyên số đo trên Raspberry Pi AI Camera do nhóm Ultralytics thực hiện cho những phiên bản trước của trang này. Các hàng phát hiện được đo lại và các hàng pose được bổ sung bằng tính năng xuất pose, phát hành lần đầu trong ultralytics 8.3.167; các hàng phân loại được bổ sung cùng tính năng xuất phân loại, phát hành lần đầu trong 8.3.222.

Thời gian inference trên Raspberry Pi AI Camera, tính bằng ms trên mỗi ảnh.

ModelimgszThời gian inference trên AI Camera (ms/ảnh)
YOLOv8n64058.79
YOLO11n64058.82
YOLOv8n-pose64058.79
YOLO11n-pose64062.50
YOLOv8n-cls22433.31
YOLO11n-cls22433.31

Độ chính xác của các model đã xuất trên Raspberry Pi AI Camera.

ModelDữ liệu validationmAP50-95(B)
YOLOv8nCOCO1280.470
YOLO11nCOCO1280.517
YOLOv8n-poseCOCO8-Pose0.687
YOLO11n-poseCOCO8-Pose0.788
ModelDữ liệu validationĐộ chính xác Top-1Độ chính xác Top-5
YOLOv8n-clsImageNet100.250.5
YOLO11n-clsImageNet100.250.417

Kích thước của packerOut.zip tính bằng MB, được ghi nhận với các phiên bản đó.

ModelpackerOut.zip (MB)
YOLOv8n2.1
YOLO11n2.2
YOLOv8n-pose2.0
YOLO11n-pose2.1
YOLOv8n-cls2.3
YOLO11n-cls2.3
  • COCO128, được dùng cho các hàng phát hiện, là 128 ảnh đầu tiên của COCO train2017, trên tập này các model đã được huấn luyện nên giá trị cao hơn so với trên ảnh xác thực: trên máy chủ xuất, các model PyTorch YOLOv8n và YOLO11n đạt lần lượt 0.450 và 0.511 mAP50-95 trên COCO128. Giá trị trên camera của hai model là 0.470 và 0.517, cao hơn các giá trị PyTorch này; conf và dữ liệu hiệu chuẩn của các lần xuất đó không được ghi lại, đồng thời không thể chạy lại trên camera cho trang này, vì vậy chưa xác định được nguyên nhân.
  • ImageNet10, được dùng cho các hàng phân loại, có 12 ảnh xác thực; trên máy chủ xuất, các model PyTorch YOLOv8n-cls và YOLO11n-cls đạt cùng độ chính xác top-1 là 0.25 và top-5 là 0.5, 0.417 như camera. Do đó, các hàng này cho thấy camera khớp với PyTorch trên 12 ảnh, chứ không phản ánh độ chính xác của các model. Trên 102 ảnh xác thực của imagenet100, YOLO11n-cls đạt top-1 40.2% trong PyTorch và 36.3% dưới dạng model_imx.onnx của bản xuất mặc định; YOLOv8n-cls lần lượt đạt 40.2% và 34.3%.
  • COCO8-Pose, được dùng cho các hàng pose, có 4 ảnh xác thực; các model PyTorch YOLOv8n-pose và YOLO11n-pose đạt box mAP50-95 lần lượt là 0.666 và 0.743 trên tập này tại máy chủ xuất.
  • Kích thước: các tệp packerOut.zip của những bản xuất cho trang này được liệt kê trong Các tác vụ được hỗ trợ.

Độ chính xác trên máy chủ xuất#

Bảng so sánh độ chính xác của model_imx.onnx—model đã lượng tử hóa trong bản xuất, được YOLO() chạy trên CPU của máy chủ xuất, một máy chủ AMD EPYC 9655—với model PyTorch và bản xuất ONNX FP32 của model đó. IMX500 chạy phiên bản đã biên dịch của cùng model INT8; độ chính xác trên camera chưa được đo cho trang này.

mAPval 50-95 trên 500 ảnh của COCO val2017; giá trị càng cao càng tốt. Với phân đoạn và pose, đây là độ chính xác của bbox và mask hoặc keypoint. Các cột IMX khác nhau về ảnh hiệu chuẩn và conf của bản xuất; xem Hiệu chuẩn và Các ngưỡng trong model. Giá trị IMX cao nhất của mỗi hàng được in đậm; nếu hòa, cả hai giá trị đều được in đậm.

ModelPyTorchONNX FP32IMX, mặc định (4 ảnh, conf 0.25)IMX, 4 ảnh, conf=0.001IMX, 500 ảnh, conf 0.25IMX, 500 ảnh, conf=0.001
YOLO11n40.340.330.337.433.038.3
YOLO11n-seg bbox40.040.031.637.031.837.0
YOLO11n-seg mask33.233.227.732.128.031.7
YOLO11n-pose bbox72.172.164.769.364.368.4
YOLO11n-pose pose52.152.140.041.540.244.4
YOLOv8n38.638.629.035.529.736.3
YOLOv8n-seg bbox38.038.023.834.323.933.7
YOLOv8n-seg mask31.731.721.329.921.529.8
YOLOv8n-pose bbox71.171.158.566.258.364.9
YOLOv8n-pose pose53.253.241.546.340.543.4
  • ONNX FP32 cho kết quả giống PyTorch ở mọi hàng.
  • conf của bản xuất giải thích phần lớn chênh lệch của bản xuất mặc định, ngoại trừ keypoint của cả hai model pose: conf=0.001 làm độ chính xác tăng từ 1.5 đến 10.5 điểm. Với thiết lập này, model INT8 thấp hơn PyTorch từ 1.1 đến 10.6 điểm; mức chênh lệch lớn nhất là keypoint của YOLO11n-pose.
  • 500 ảnh hiệu chuẩn với conf=0.001 có độ chính xác thấp hơn PyTorch từ 1.5 đến 9.8 điểm.

Được đo bằng ultralytics 8.4.220, model-compression-toolkit 2.5.1, imx500-converter 3.19.2, PyTorch 2.15.0 và ONNX Runtime 1.32.0 (với protobuf 7.36.2) trên Python 3.11 tại batch=1. model_imx.onnx và các model ONNX FP32 chạy với CPU execution provider, ngoại trừ YOLOv8n-seg FP32 chạy với CUDA execution provider; PyTorch chạy trên GPU RTX PRO 6000 với rect=False, ở cùng kích thước đầu vào 640x640 như các model đã xuất. Độ chính xác được đo trên 500 ảnh cuối cùng của COCO val2017 theo thứ tự sắp xếp; với pose, dùng 500 ảnh cuối cùng có người, nên kết quả khác với giá trị trên toàn bộ tập xác thực tại trang model YOLO11. 500 ảnh hiệu chuẩn là 500 ảnh đầu tiên của COCO train2017 theo thứ tự sắp xếp; với pose, dùng 500 ảnh đầu tiên có người. Mỗi cột IMX tương ứng với một lần xuất; các lần xuất lặp lại cho kết quả khác nhau, xem Giới hạn và khắc phục sự cố.

Giới thiệu về Sony IMX500#

Raspberry Pi AI Camera with Sony IMX500 sensor

Cảm biến thị giác thông minh IMX500 của Sony xử lý AI ngay trên cảm biến, nhờ đó camera có thể gửi kết quả inference dưới dạng metadata kèm theo từng khung hình, hoặc chỉ gửi metadata thay vì chỉ gửi hình ảnh. Model Compression Toolkit (MCT) của Sony lượng tử hóa model cho cảm biến; xem bài viết trên blog Ultralytics về MCT. Trình chuyển đổi IMX500 biên dịch model đã lượng tử hóa; trên Raspberry Pi, trình đóng gói trong bộ công cụ imx500-all chuyển packerOut.zip thành tệp firmware mà camera tải.

Sony IMX500 YOLO model deployment workflow

Câu hỏi thường gặp#

  • Không: tính năng xuất IMX500 của Ultralytics chỉ hỗ trợ YOLO11n và YOLOv8n, cùng YOLO11s-cls và YOLOv8s-cls cho tác vụ phân loại; model YOLO26 dùng cho phát hiện, phân đoạn, phân loại hoặc pose sẽ gặp lỗi IMX export only supported for YOLOv8n and YOLO11n models.. Model phân đoạn ngữ nghĩa, độ sâu và OBB gặp lỗi sớm hơn với thông báo tương ứng cho tác vụ đó. Ultralytics sử dụng các thiết lập MCT được thiết kế cho các lớp của hai model này. Hãy huấn luyện hoặc fine-tune model YOLO11n hoặc YOLOv8n trên dữ liệu của bạn để triển khai trên Raspberry Pi AI Camera; xem Các tác vụ được hỗ trợ.

  • Có: YOLO("yolo11n_imx_model") chạy model_imx.onnx đã lượng tử hóa mà bản xuất Ultralytics ghi cạnh packerOut.zip, trên CPU của máy tính Linux hoặc Mac. Nhờ đó, bạn có thể chạy predict và xác thực model INT8 trước khi sao chép model sang camera; xem Triển khai. Cách này kiểm tra quá trình lượng tử hóa, chứ không kiểm tra IMX500: tốc độ và kết quả trên camera chưa được đo cho trang này.

  • Bản xuất IMX500 của Ultralytics dùng INT8 và theo mặc định, NMS chỉ giữ lại các detection có score trên 0.25; val tính cả yếu tố này: trên 500 ảnh COCO tại máy chủ xuất, bản xuất mặc định thấp hơn PyTorch từ 5.5 đến 14.2 điểm mAP50-95, còn bản xuất với conf=0.001 thấp hơn từ 1.1 đến 10.6 điểm; xem Benchmark. Hãy hiệu chuẩn bằng ảnh từ dữ liệu của chính bạn với data, xuất với conf=0.001 để đo mức ảnh hưởng của quá trình lượng tử hóa, và giữ conf mặc định hoặc dùng ngưỡng của ứng dụng trên camera; xem Các ngưỡng trong model.

  • Tính năng xuất IMX500 của Ultralytics chỉ chạy trên Linux với Python 3.10 đến 3.12; trên máy Mac, quá trình này dừng với Export only supported on Linux. See https://developer.aitrios.sony-semicon.com/en/docs/raspberry-pi-ai-camera/imx500-converter?version=3.17.3&progLang=. Trên Raspberry Pi, quá trình không dừng trên Raspberry Pi OS Bookworm với Python 3.11, nhưng trường hợp này chưa được chạy thử cho trang; các bài kiểm thử Ultralytics bỏ qua vì đã hết bộ nhớ trên Raspberry Pi 5 có 16 GB. Hãy xuất trên máy tính Linux hoặc bằng Ultralytics Platform, rồi sao chép packerOut.zip và labels.txt sang Raspberry Pi; xem Giới hạn và khắc phục sự cố.

Bình luận86

Đặt câu hỏi, chia sẻ kết quả hoặc giúp đỡ người khác.

  1. Chad Walsh

    where is the best place to get support on the IMX500. I am running into multiple issues: i. my first yolo11n model built fine and exported to imx500, no problem, but my second model with a LOT more training images build fine but crashed the imx500 export. ii. the output of the imx500 during inference is giving a lot of none outputs between solid recognitions. it seems like there is something interfering with or disrupting the inference outputs (e.g., good output, none, none, none, none, good output, ...). where is the best place to get help with these issues?

    1. Glenn JocherUltralytics

      Please continue the discussion here so the Ultralytics team can help; for the export crash, share the exact export command, full text traceback, and output from yolo checks, and for intermittent None results include a minimal inference script, confidence threshold, and a short reproducible input sample. Note that IMX export uses the calibration dataset specified by data and defaults to the full dataset, so testing a smaller fraction may help isolate resource-related failures.

  2. leeprevostGitHub

    I've made considerable progress by moving conducting this model compression process with a Container using dtcooper/raspberrypi-os:python3.11 after considerable problems with dependencies. Now getting a container most of the way through the process of compressing my yolov11s model and its trained best.pt weights.

    At the end of the process - I get a simple "killed" after the Calculation of quantization parameters step. I see memory spiking close to 100% on top and think I'm hitting OOM with my pi4 8gb.

    root@a5e132f6b333:/app# yolo export model=./models/yolov11/best.pt data='Billfish-Breeds-1/data.yaml' format=imx verbos>
    Ultralytics 8.3.221 🚀 Python-3.11.14 torch-2.9.0+cpu CPU (aarch64)
    WARNING ⚠️ IMX export requires nms=True, setting nms=True.
    YOLO11s summary (fused): 100 layers, 9,413,187 parameters, 0 gradients, 21.3 GFLOPs
    
    PyTorch: starting from 'models/yolov11/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) ((1, 8400, 4>
    IMX: collecting INT8 calibration images from 'data=Billfish-Breeds-1/data.yaml'
    Fast image access ✅ (ping: 0.1±0.0 ms, read: 16.1±2.7 MB/s, size: 16.4 KB)
    Scanning /app/Billfish-Breeds-1/valid/labels.cache... 268 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 268/268 1>
    WARNING ⚠️ IMX: >300 images recommended for INT8 calibration, found 268 images.
    
    IMX: starting export with model_compression_toolkit 2.4.4...
    representative_data_gen generates a batch size of 1 which can be slow for optimization: consider increasing the batch s>
    WARNING:Model Compression Toolkit:OperatorSetNames.DEPTHWISE_CONV is not in model.
    Statistics Collection: 268it [1:01:26, 13.76s/it]
    Calculating quantization parameters: 100%|█████████████████████████████████████████████████████| 294/294 [12:44<00:00, >
    Killed

    Would appreciate any suggestion around this but think it probably pushes me over the edge to order my pi5? Or do I try to train on the yolov8 or yolov11n? I've not had very good success with the nano models. I've convinced myself the tradeoffs to the small is well worth it but that may be incompatible with this process?

    1. Glenn JocherUltralytics

      @leeprevost you’re in the right place for discussion, but the OOM during IMX export is a new issue—please open a new issue for visibility. In the issue, include: the exact export command and full log, yolo checks output (or ultralytics.utils.checks.collect_system_info()), Java version (java --version), and the versions of IMX toolchain (pip freeze | grep -E "imx500|model-compression|sony-custom"). As immediate workarounds: export on a Linux x86_64 machine with more RAM, target YOLO11n/YOLOv8n (the IMX path is tuned for “n” models), and reduce calibration load with fraction (e.g., 0.25). Example:

      yolo export model=best.pt format=imx data=your.yaml imgsz=640 fraction=0.25

      IMX-specific knobs are summarized in the IMX500 export arguments here: Sony IMX500 export guide – Export arguments, and the exporter function requirements here: export_imx reference.

    2. leeprevostGitHub

      a few more questions and I will open an issue:

      1. Note that I was using a model trained on yolov11s rather than n as I've seen large degradation in the number of false positives in my model.
      2. I assume by "full log" you mean the output from the yolo export command with verbose at default (true). In other words, what I posted above?
      3. For some reason, I thought I read int he docs that i had to perform the model compression on the target machine. for me, the ultimate target is RpiZero2 but no way the model will export on that footprint . so, I went to the largest pi I have which is a Rpi4 -- that resulted in the OOM. So, am unsure by your guidance pointing me to the larger x86 linux machine. How will the process know the device limits if I perform it on that?

      Trying to read these guides as best I can. I have not spent much time on the Sony site yet. If you'll point me, I don't want to start an issue that isn't an issue.

    3. Glenn JocherUltralytics(đã chỉnh sửa)

      @leeprevost great progress. IMX export/quantization does not need to run on the target; it cross-compiles for IMX500, so doing it on a larger Linux host is recommended. “Full log” means the complete stdout/stderr from the export run.

      The “No module named 'onnxscript'” failure is a missing dependency. Current Ultralytics installs the IMX toolchain (including imx500-converter and model-compression-toolkit) itself, so upgrade with pip install -U ultralytics and re-run the export rather than pinning old versions by hand. Let’s continue the deep-dive in the issue you opened for traceability.

    4. leeprevostGitHub

      Ok -- @glenn-jocher: am moving this to my opened issue. Still trying this on my pi4 but can move to my dev machine with plenty of RAM + Cuda. Got further but still died with a torch error -- will post there.

    5. Glenn JocherUltralytics

      Thanks—let’s continue in the issue for traceability. On the larger Linux host, try GPU-assisted export to reduce RAM pressure and speed up calibration; if needed, temporarily lower imgsz to validate the pipeline:

      yolo export model=path/to/best.pt format=imx data=path/to/data.yaml device=0 imgsz=640
      # if memory is still tight during calibration
      yolo export model=path/to/best.pt format=imx data=path/to/data.yaml device=0 imgsz=512

      For a concise list of export options and behavior, see the Export mode docs at Ultralytics YOLO — Export.

  3. leeprevostGitHub

    Much thanks for posting this guide. Thank you.

    I am having very solid success running the standard detection models right out of the box on the RpiZero 2 which is my target platform. I'm actually amazed at the power draw (ran detection/streaming for about 175 minutes on a 4400mahr battery using about 60% of its capacity). Also, very solid top/htop scores showing less than 1/8 of CPU utilization. Memory is still such a problem on a rpiz2 but not any more so than what is being used with streaming only on the pi. Still have about 50% of memory left over as I recall. I've got screen shots of top screens if needed.

    But, I need to get a trained model working on my RpiZ2 and am running into problems. As the guide seemed to indicate (or perhaps Sony's), I need to do most of the quantization on my target platform. I assumed that meant my zero. I have a very good model trained with yolov11m or large. I've tried to reduce that to a nano but I'm getting too much loss of MAP scores and too much false positive rates. So, am now trying to get a yolov11s to work. On my quantization process (it was not clear how to do this with a custom model) but am first loading the yolov11s.pt and then loading my best.pt on top of that. Ultralytics successfully loads my data, gives me a warning prompt about my 290 images (< 300 not ideal) and then another about processing speed with 1 batch. The program then goes off the rails with no UI messages. I assume I'm running out of memory on the piz2. So, my next steps seem to be either:

    1. Start over and try with nano model.
    2. Do my quantization on a larger pi (i've got a spare pi4).

    I guess another option would be to spend more time understanding Sony's under the hood tools to optimize those settings?

    Would appreciate some guidance here down the right path.

  4. leeprevostGitHub

    One thing that would be very helpful is to show how to do this on something other than the target platform. i'm trying to get a small detection model to run on a rpi zero2 and hate to have to download all of my training data to the zero to do the quantization.

    Idea: Have a step that allows collection of the "target_platform_capabilities" information using Sony's model compression toolkit you are using under the hood, pickle it, and then use that object to drive the model compression on a larger machine.

    I could probably dig in and try to follow your code and follow the "imx" part of your export process...

  5. bohlebotsGitHub

    Wie schaffe ich es, dass das Modell im Speicher des IMX500 bleibt? Die PICAM wurde ja angepriesen mit der Aussage, dass sie selbst an einem Pi zero-2 mit gleicher Geschwindigkeit läuft und in der Tat, das täte sie, aber das Modell muss jedes Mal neu aufgeladen werden, und das dauert beim Pi Zero ewig, ja selbst mit einem Pi5 dauert es Minuten. Grundsätzlich muss die imx500 aber ein Modell auch bei ausgeschaltetem Strom im Speicher halten können, so dass nach dem Anschalten das letzte Modell direkt zur Verfügung steht. Wie bekomme ich das hin?

    Gruß Roland

  6. Teo-trenyGitHub

    Hello ! When running object detection (step 5), I get the following error :

    Exception in thread Thread-2 (_process_requests_func):
    Traceback (most recent call last):
      File "/home/pi/.pyenv/versions/3.11.9/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
        self.run()
      File "/home/pi/.pyenv/versions/3.11.9/lib/python3.11/threading.py", line 982, in run
        self._target(*self._args, **self._kwargs)
      File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/devices/ai_camera/ai_camera.py", line 193, in _process_requests_func
        callback()
      File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/devices/ai_camera/ai_camera.py", line 207, in _process_requests
        self._parse_request(req)
      File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/devices/ai_camera/ai_camera.py", line 256, in _parse_request
        detections = self.model.post_process(outputs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/pi/Desktop/imx_test/Test_1.py", line 23, in post_process
        return pp_od_yolo_ultralytics(output_tensors)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/models/post_processors/post_processors.py", line 129, in pp_od_yolo_ultralytics
        n_detections = int(output_tensors[3])
                       ^^^^^^^^^^^^^^^^^^^^^^
    TypeError: only length-1 arrays can be converted to Python scalars

    I'm running Python 3.11.9 and installed all the dependencies following the guide. My Raspberry PI is a 3B+ model with Bookworm 64 bits and is up to date.

  7. aytacsekmenGitHub

    In the official IMX500 documentation provided by Sony (https://developer.sony.com/tinyml-23/developer-tools/documentation/imx500-evaluation-kit-user-guide?version=2023-11-28&progLang=), they describe the process of generating the network.fpk and network_info.txt files that will be used to deploy the model to IMX500, using the Packager.sh script. However, when I attempt to apply the same procedure to the packerOut.zip file I created by following the tutorial on https://docs.ultralytics.com/integrations/sony-imx500, I am unable to run the model on the IMX500. Also I couldn't run your implementation because it says that some packages are not found which I believe is related to the version of the OS. Currently I use the Pi OS that is provided by SONY for compatibility issues. I could run some other deep learning models following the steps in the (https://developer.sony.com/tinyml-23/developer-tools/documentation/imx500-evaluation-kit-user-guide?version=2023-11-28&progLang=), but I believe, there must be something different related to the creation of packerOut.zip file.

    Could you assist in resolving this issue with the conversion process? @glenn-jocher

  8. HelloCigarGitHub

    Hello, per picamera2 docs, creating apps with "a camera window embedded into the GUI is through Qt", is there no other way to embed the video feed in other GUI frameworks?

  9. skim-sonyGitHub

    Hi, I followed the steps in this page to convert the yolov8n model with imx500 converter and tested it with raspberry ai camera. But I get 29.5 ms for the inference time with 640x640 input tensor size. So I wonder why my inference time is better than your result (58.82ms). Which version of imx500 converter did you use?

    1. skim-sonyGitHub

      Also, how did you measure the inference time? Did you use imx500.get_kpi_info(metadata) or calculate the elapsed time of picam2.capture_metadata()?

    2. Glenn JocherUltralytics(đã chỉnh sửa)

      @skim-sony congratulations on the faster result! Our documented figure (58.82 ms for YOLO11n, see the Benchmarks) was measured by the Ultralytics team on a Raspberry Pi AI Camera with the imx format. Differences can come from the converter version, firmware, hardware (Pi 5 vs Pi 4) or how the time is measured. Would you mind sharing which converter version and Raspberry Pi model you're using? This could help other community members.

    3. skim-sonyGitHub(đã chỉnh sửa)

      Hi, I have used Pi5 and tried both 3.14.3 and 3.16.1 for imx500-converter. And both produces 29.5ms for inference time. It seems like you also use Pi5, so I wonder why our results are different. I'd like to reproduce your results 58.82 ms to learn what improves the inference time. So it would be helpful if you could share some info how to sync with your environment. Thanks!

    4. Glenn JocherUltralytics(đã chỉnh sửa)

      @skim-sony that's interesting you're seeing better performance! The discrepancy could be due to several factors:

      1. Measurement methodology: end-to-end time (pre/post-processing + inference) differs from model-only inference time
      2. Firmware and converter versions
      3. Image resolution and resizing
      4. Test conditions: background processes, temperature, and power settings

      Our published numbers are in the Benchmarks. If you'd like to share more details about your implementation, the community would certainly benefit.

  10. fraciprianoGitHub

    Hello, I'm trying to run the standard YOLOv8n model on a Raspberry Pi AI Camera. I followed the exemple in the documentation

    from ultralytics import YOLO
    
    # Load a YOLOv8n PyTorch model
    model = YOLO("yolov8n.pt")
    
    # Export the model
    model.export(format="imx", data="coco8.yaml")  # exports with PTQ quantization by default
    
    # Load the exported model
    imx_model = YOLO("yolov8n_imx_model")
    
    # Run inference
    results = imx_model("https://ultralytics.com/images/bus.jpg")

    I got a bunch of warnings during the execution (export_log.txt), but the imx_model seemed to work properly in the end.

    I then packaged it via IMX500 Packager and test it using the imx500_object_detection_demo.py. The Network Firmware gets uploaded, the application starts, but I get no detection. I tried to lower the detection threshold, but it didn't help. Any idea on what could be the problem? Any suggestion would be much appreciated.

    1. Glenn JocherUltralytics

      Thank you for the detailed issue. Let's troubleshoot step by step. First, ensure your Raspberry Pi AI Camera is correctly connected and recognized by running libcamera-hello in the terminal. If the camera works, verify that the labels.txt path in your demo command matches the exported file. You can also try inference on a static image first with imx_model.predict("test.jpg") to isolate live feed issues. For further assistance, please share the full export log and a screenshot of your camera output.

      For additional guidance, refer to the Sony IMX500 and AITRIOS integration blog post which demonstrates successful deployment steps.

    2. fraciprianoGitHub

      Hello @glenn-jocher,

      libcamera-hello works fine as does the imx500_object_detection_demo.py when using the default model ("/usr/share/imx500-models/imx500_network_ssd_mobilenetv2_fpnlite_320x320_pp.rpk").

      There seems to be no problem with the labels.txt file as, if a run the imx500_object_detection_demo.py specifying the path to my label.txt, it works fine.

      The imx_model also works fine before the packaging.

      Here a screenshot of the camera output:

      Screenshot 2025-03-12 123143

      You can find the full export log file in my first post. Do you think any of the errors and/or warnings there could cause any problem with the packaging process via the IMX500-Packager?

    3. Glenn JocherUltralytics

      Thank you for sharing these details. The warnings in your export log about "No BN layers to fold" and quantization parameters are normal during IMX conversion and shouldn't affect packaging. Since your camera feed works with the default model but not your custom export, please verify:

      1. Your imx500-package command uses the exact packerOut.zip from yolov8n_imx_model
      2. The input tensor shape in your exported model matches IMX500 expectations (640x640 by default)

      If issues persist, we recommend trying the IMX500 conversion process with our pretrained YOLOv8n model from https://github.com/ultralytics/assets/releases as a validation step.

    4. fraciprianoGitHub

      Hello @glenn-jocher , thank you for your answer.

      1. Yes, I'm the one specifying the packerOut.zip path when running imx500-package
      2. I think so. Here is the content of the dnnParams.xml file generated by the export function
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <dnnParams>
          <networks>
              <network name="yolov8n_new_imx" ordinal="0" type="">
                  <inputTensors>
                      <inputTensor persistency="0" ordinal="0" name="Placeholder.input.uid1:0" l2Offset="260480" numOfDimensions="3" bitsPerElement="8" shift="0" scale="0.00390625" format="unsigned">
                          <dimensions>
                              <dimension size="3" serializationOrder="2" ordinal="0" padding="0"/>
                              <dimension size="640" serializationOrder="1" ordinal="1" padding="0"/>
                              <dimension size="640" serializationOrder="0" ordinal="2" padding="0"/>
                          </dimensions>
                      </inputTensor>
                  </inputTensors>
                  <outputTensors>
                      <outputTensor ordinal="1" name="transform-83-/MultiClassNMS:0" l2Offset="281984" numOfDimensions="1" bitsPerElement="8" shift="0" scale="0.00390625" format="unsigned">
                          <dimensions>
                              <dimension size="300" serializationOrder="0" ordinal="0" padding="0"/>
                          </dimensions>
                      </outputTensor>
                      <outputTensor ordinal="2" name="transform-84-/MultiClassNMS:0" l2Offset="280960" numOfDimensions="1" bitsPerElement="16" shift="0" scale="1.0" format="signed">
                          <dimensions>
                              <dimension size="300" serializationOrder="0" ordinal="0" padding="0"/>
                          </dimensions>
                      </outputTensor>
                      <outputTensor ordinal="3" name="transform-85-/MultiClassNMS:0" l2Offset="279936" numOfDimensions="1" bitsPerElement="16" shift="0" scale="1.0" format="signed">
                          <dimensions>
                              <dimension size="1" serializationOrder="0" ordinal="0" padding="0"/>
                          </dimensions>
                      </outputTensor>
                      <outputTensor ordinal="0" name="transform-86-/MultiClassNMS:0" l2Offset="260480" numOfDimensions="2" bitsPerElement="16" shift="0" scale="0.03125" format="signed">
                          <dimensions>
                              <dimension size="300" serializationOrder="0" ordinal="0" padding="0"/>
                              <dimension size="4" serializationOrder="1" ordinal="1" padding="0"/>
                          </dimensions>
                      </outputTensor>
                  </outputTensors>
              </network>
          </networks>
          <l2memory totalSize="8388480" coefficientsSize="2604544" reservedMemorySize="1024" networksRuntimeSize="5523456"/>
      </dnnParams>
      

      I downloaded the yolov8n.pt file from the Sep 29, 2024 Release and repeated the process from the beginning. Same result.

      I'm adding here the terminal outputs I get when running the imx500-package: imx500-package_log.txt

    5. Glenn JocherUltralytics(đã chỉnh sửa)

      Thanks for sharing the details. The dnnParams.xml shows correct 640x640 input dimensions. Since the default Mobilenet model works but your YOLOv8 export doesn't, please verify that your output tensor dimensions and ordering match the demo's expectations. YOLO IMX exports have a different output layout from Mobilenet, so the demo's post-processing must match. The deployment section of the IMX500 guide uses the pp_od_yolo_ultralytics post-processor from the AITRIOS module library for Ultralytics YOLO IMX exports.

    6. fraciprianoGitHub

      Okay. So the problem was actually related to the output. The ordering is fine, as the scores and the classes. The problem are the bboxes. The values that I obtain are completely out of scale.

      Example:

      detection label: cup (0.56)
      detection box: (396100, 107520, 0, 0)

      whereas I would expect something like this:

      detection label: cup (0.56)
      detection box: (39, 459, 440, 177)

      I'm not sure how to interpret this results. Is (396100, 107520, 0, 0) supposed to be the raw output of YOLOv8n? Also, in the dnnParams.xml posted above, I see that there is a scale="0.00390625" associated with the component of the output tensor relative to the bboxes. Should I renormalize my output using this factor?

      Thank you for any insight you can provide.

    7. Glenn JocherUltralytics(đã chỉnh sửa)

      The raw IMX500 outputs are quantized and need post-processing. Rather than decoding them by hand, use the pp_od_yolo_ultralytics post-processor shown in the deployment section of the IMX500 guide.

    8. fraciprianoGitHub

      Hello @glenn-jocher, a code snippet would be much appreciated for double-checking. Also, I can't find the documentation you mentioned—could you link it to me, please?

    9. Glenn JocherUltralytics(đã chỉnh sửa)

      The IMX500 outputs are decoded for you by the AITRIOS module library, as shown in the deployment section of the IMX500 guide:

      from modlib.models.post_processors import pp_od_yolo_ultralytics
      
      
      def post_process(self, output_tensors):
          return pp_od_yolo_ultralytics(output_tensors)

      Let us know if this resolves the coordinate scaling issue!

    10. fraciprianoGitHub

      I think there’s been a misunderstanding. I thought there were other changes to be made besides rescaling. Scaling alone cannot be the solution since (396100, 107520, 0, 0) cannot become (39, 459, 440, 177) just by a scalar multiplication.

      Also, I cannot find the "What's Under the Hood?" section anywhere here https://developer.sony.com/imx500. Could you be more precise about where I should look?

    11. Glenn JocherUltralytics(đã chỉnh sửa)

      The "What's Under the Hood?" section refers to our Ultralytics IMX500 documentation, not Sony's site, but it describes the quantization and conversion toolchain, not output decoding. For box decoding use the post-processor from the deployment section:

      from modlib.models.post_processors import pp_od_yolo_ultralytics
      
      
      def post_process(self, output_tensors):
          return pp_od_yolo_ultralytics(output_tensors)
    12. fraciprianoGitHub

      Hi @glenn-jocher , thank you very much for all the support. It finally works! There was no need to rescale the boxes by 0.03125. I was missing the --bbox-normalization flag when launching the script.

      Once I added the flag, everything worked fine.

    13. Glenn JocherUltralytics(đã chỉnh sửa)

      Great to hear you resolved it! For the current deployment workflow, including post-processing of the model outputs, see the IMX500 deployment guide. Happy detecting with your Raspberry Pi setup! 🚀