YOLO-NAS

Một detector tích chập có backbone và neck được tạo ra từ quá trình tìm kiếm kiến trúc của Deci.AI, xây dựng bằng các block RepVGG nhận biết lượng tử hóa. Trọng số thuộc Deci.AI, chỉ được cấp phép cho mục đích phi thương mại và LibreYOLO không công bố trọng số nào.

Tác vụ
detection, pose, oriented boxes
Kích thước
s, m, l at 640 px
Cài đặt
pip install libreyolo
Bậc hỗ trợ
Cốt lõi, từ v1.1.0. Các bộ phát hiện cốt lõi có thể huấn luyện: tính năng theo sau các mô hình chủ lực trong cùng đợt phát hành.
Thượng nguồn
YOLO-NAS của Deci.AI, Deci.AI proprietary, non-commercial. Bài báo, mã nguồn
Giấy phép
Mã nguồn Apache-2.0, trọng số Deci.AI proprietary, non-commercial. Sử dụng thương mại

Cài đặt

YOLO-NAS không cần extra ngoài gói cơ sở.

bash
pip install libreyolo

Dự đoán

Tên checkpoint chưa có trên đĩa được lấy từ CDN công khai của Deci, không phải từ tổ chức LibreYOLO vì nơi đó không lưu trữ trọng số nào của họ này. Trước khi truyền tệp, thư viện in các điều khoản giấy phép của Deci một lần cho mỗi tiến trình; trước khi mở tệp đã tải, SHA-256 của tệp được kiểm tra với giá trị đã ghim. Những gì các điều khoản cho phép được nêu trong giấy phép.

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE # Tên chưa có trên đĩa được lấy từ CDN của Deci. Trước tiên, bản tải# in các điều khoản giấy phép của Deci; nhận tệp đồng nghĩa chấp nhận chúng.model = LibreYOLO("LibreYOLONASs.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes:    print(box.cls, box.conf, box.xyxy)
CLI
libreyolo predict model=LibreYOLONASs.pt save=True \  source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg
Pose
from libreyolo import LibreYOLO, SAMPLE_IMAGE # Hậu tố -pose chọn head tư thế và tập trọng số riêng.model = LibreYOLO("LibreYOLONASs-pose.pt")result = model(SAMPLE_IMAGE) print(result.keypoints.xy)

Đối tượng Results trả về là loại mà mọi họ đều trả về, nên việc đổi sang detector khác chỉ cần sửa một dòng. conf đặt ngưỡng độ tin cậy và iou đặt ngưỡng NMS. Xem dự đoán để biết về nguồn, streaming và xử lý kết quả.

Tác vụ hộp xoay trả về result.obb. Đồ thị OBB đã công bố dùng khung ảnh 1024 pixel và bộ nhãn 18 lớp đối tượng đã ghi.

Các biến thể

Phát hiện và tư thế dùng cùng kiến trúc với các head khác nhau, đồng thời nhận cùng các đối số. Các kích thước trong bảng bên dưới dành cho phát hiện; tư thế được công bố ở các kích thước đó và thêm một kích thước nhỏ hơn. Head tư thế dự đoán tập keypoint COCO.

CheckpointĐầu vào (px)mAP 50-95Tham số (M)
LibreYOLONASl64056.366.98
LibreYOLONASm64055.451.18
LibreYOLONASs64051.819.05

COCO val2017, 500 images. Được đo bằng bộ benchmark LibreYOLO và công bố trên Vision Analysis, nơi so sánh độ trễ giữa các phần cứng và runtime, đồng thời lưu trữ đầy đủ bản ghi của từng lần chạy.

Huấn luyện

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreYOLONASs.pt")model.train(data="my-dataset.yaml", epochs=100, imgsz=640, batch=16)
CLI
libreyolo train model=LibreYOLONASs.pt data=my-dataset.yaml \  epochs=100 imgsz=640 batch=16
Huấn luyện từ đầu
from libreyolo import LibreYOLONAS # Không dùng checkpoint Deci nào: mô hình bắt đầu từ trọng số ngẫu nhiên,# nên kết quả của lượt chạy chỉ bắt nguồn từ dữ liệu của bạn.model = LibreYOLONAS(None, size="s")model.train(data="my-dataset.yaml", imgsz=640, batch=16)

Khi bạn bỏ qua epochs, lr0 và amp, chúng được phân giải theo từng tác vụ, vì vậy lượt chạy tư thế bắt đầu với giá trị mặc định khác lượt chạy phát hiện. Optimizer mặc định là AdamW. Số lớp lấy từ YAML tập dữ liệu và head được xây dựng lại cho số lớp đó trước epoch đầu tiên; trên head tư thế, số keypoint được xử lý tương tự, nên checkpoint tư thế COCO có thể tinh chỉnh sang skeleton có kích thước khác.

Tinh chỉnh bắt đầu từ trọng số của Deci, là đối tượng được giấy phép của Deci bao quát. Huấn luyện từ mô hình khởi tạo ngẫu nhiên hoàn toàn không liên quan đến checkpoint Deci, và đó là snippet thứ ba ở trên.

Xem huấn luyện để biết về tập dữ liệu, tăng cường dữ liệu, multi-GPU và logger.

Phát hiện mặc định dùng amp=True với amp_dtype="float16"; huấn luyện hộp xoay vẫn dùng amp=False. Head OBB hỗ trợ huấn luyện, dự đoán và đánh giá, dùng augmentation lật/HSV và chọn checkpoint theo metrics/mAP50-95(OBB). load_detect_weights_for_obb() khởi tạo nó từ trọng số phát hiện.

Đánh giá

val() trả về từ điển các khóa metrics/ bao gồm precision, recall, mAP 50 và mAP 50-95, được đo trên bất kỳ tập dữ liệu nào theo định dạng bạn đã huấn luyện.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreYOLONASs.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])
CLI
libreyolo val model=LibreYOLONASs.pt data=my-dataset.yaml
Trên COCO
# YAML COCO đi kèm chứa script tải xuống nhúng sẵn, nên cần quyền rõ ràng# trừ khi tập dữ liệu đã có cục bộ.libreyolo val model=LibreYOLONASl.pt data=coco.yaml imgsz=640 \  allow_download_scripts=True

Xuất

Tác vụONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
DetectionDetection to ONNX: được hỗ trợDetection to TorchScript: được hỗ trợDetection to ExecuTorch: được hỗ trợDetection to TensorRT: được hỗ trợDetection to OpenVINO: được hỗ trợDetection to Paddle: được hỗ trợDetection to MNN: được hỗ trợDetection to RKNN: được hỗ trợDetection to ncnn: được hỗ trợDetection to TFLite: được hỗ trợDetection to CoreML: không được hỗ trợDetection to Core AI: được hỗ trợ
PosePose to ONNX: được hỗ trợPose to TorchScript: được hỗ trợPose to ExecuTorch: được hỗ trợPose to TensorRT: được hỗ trợPose to OpenVINO: được hỗ trợPose to Paddle: được hỗ trợPose to MNN: không được hỗ trợPose to RKNN: không được hỗ trợPose to ncnn: được hỗ trợPose to TFLite: không được hỗ trợPose to CoreML: không được hỗ trợPose to Core AI: không được hỗ trợ
Oriented boxesOriented boxes to ONNX: được hỗ trợOriented boxes to TorchScript: được hỗ trợOriented boxes to ExecuTorch: được hỗ trợOriented boxes to TensorRT: được hỗ trợOriented boxes to OpenVINO: được hỗ trợOriented boxes to Paddle: không được hỗ trợOriented boxes to MNN: không được hỗ trợOriented boxes to RKNN: không được hỗ trợOriented boxes to ncnn: được hỗ trợOriented boxes to TFLite: không được hỗ trợOriented boxes to CoreML: không được hỗ trợOriented boxes to Core AI: không được hỗ trợ

Artifact đã xuất được tải lại qua LibreYOLO() dựa trên hậu tố tệp, vì vậy tệp .onnx hoặc .engine hoạt động như checkpoint và trả về cùng Results. Cũng hỗ trợ chạy đồ thị trong runtime độc lập không cài LibreYOLO, nhưng khi đó bạn phải tự viết bước tiền xử lý và hậu xử lý. Mỗi định dạng cài một extra khác nhau và nhận một số đối số riêng. Cả hai đều được trình bày trên trang của định dạng đó.

Bản xuất là một bản sao khác của cùng trọng số trong container khác. Việc xuất checkpoint Deci không thay đổi nguồn gốc trọng số hay giấy phép áp dụng cho chúng.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreYOLONASs.pt")model.export(format="onnx", imgsz=640)
CLI
libreyolo export model=LibreYOLONASs.pt format=onnx imgsz=640
Dùng tệp đã xuất
from libreyolo import LibreYOLO, SAMPLE_IMAGE # Factory định tuyến theo hậu tố tệp, nên artifact đã xuất được tải# như mọi checkpoint và trả về cùng đối tượng Results.model = LibreYOLO("LibreYOLONASs.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)

Đầu vào và đầu ra ONNX

LibreYOLONAS detect

Tensorimages float32 [batch, 3, height, width]
MàuRGB
Chuẩn hóa tỉ lệpixel / 255
Chuẩn hóakhông có
Đổi kích thướccustom, Pillow bilinear
Cách tái tạo phép đổi kích thước bilinear của Pillow

LibreYOLO đổi kích thước bằng bộ lọc BILINEAR của Pillow (Image.resize). Đó không phải OpenCV INTER_LINEAR hay INTER_AREA: khi thu nhỏ, Pillow nới rộng bộ lọc theo hệ số thu nhỏ, còn các phép đổi kích thước của OpenCV làm thay đổi kết quả phát hiện và dịch các hộp đi vài pixel. Để tái tạo mà không dùng Pillow, hãy đổi kích thước một trục, làm tròn về 8 bit, rồi đổi kích thước trục còn lại và làm tròn lần nữa. Với mỗi trục, đặt s = in_size / out_size và f = max(s, 1). Pixel đầu ra i có tâm c = (i + 0.5) * s và đọc các pixel nguồn j từ int(c - f + 0.5) đến int(c + f + 0.5) - 1, giới hạn trong ảnh, mỗi pixel có trọng số max(0, 1 - |j + 0.5 - c| / f), chia cho tổng các trọng số. Pillow tính bằng dấu phẩy cố định và chọn thứ tự trục theo hình dạng ảnh, nên trọng số dấu phẩy động có thể lệch một mức ở vài pixel. Điều đó không làm thay đổi kết quả trong các kiểm tra của chúng tôi.

Square input only. Export rejects a non-square imgsz, and height equals width, 640 by default.

The image is not scaled to fill the canvas. The longest side goes to R = min(636, height, width), so 636 at 640 x 640.

Scale by r = min(R / h, R / w) and resize to (round(w * r), round(h * r)). The rounding is Python round, so an exact .5 goes to the even neighbor.

Paste the resized image onto a canvas filled with 114 at left = (width - new_w) // 2 and top = (height - new_h) // 2.

On the test image, cv2.resize with INTER_LINEAR loses two of the eight detections, and INTER_AREA moves boxes by up to 1.4 px.

Divide by 255 after the resize. There is no mean or std normalization.

Detection, xuất mặc định
Đầu raHình dạngÝ nghĩa
pred_logits[batch, anchors, 4]Boxes, despite the name. x1, y1, x2, y2 in input-canvas pixels. anchors is the cell count over strides 8, 16 and 32, 8400 at 640 x 640.
pred_boxes[batch, anchors, nc]Class scores, despite the name. Sigmoid already applied. 80 classes for the COCO checkpoints.

Hậu xử lý

  1. The output names are swapped relative to their content. Read boxes from pred_logits and scores from pred_boxes, or tell them apart by the last dimension (4 for boxes).
  2. Take the best class per anchor: score = max over classes, class = argmax. One anchor yields at most one detection.
  3. Keep anchors whose score is strictly above the confidence threshold (0.25 by default).
  4. Keep the 1000 highest scoring candidates.
  5. Map boxes back to the original image: subtract left from x and top from y, divide by r, clip to the image. Drop boxes left with zero width or height.
  6. Run NMS per class with IoU 0.45 and keep at most 300 detections.
  7. nms=True is not available for this family: export raises NotImplementedError.

LibreYOLONAS pose

Tensorimages float32 [batch, 3, height, width]
MàuBGR
Chuẩn hóa tỉ lệpixel / 255
Chuẩn hóakhông có
Đổi kích thướccustom, Pillow bilinear
Cách tái tạo phép đổi kích thước bilinear của Pillow

LibreYOLO đổi kích thước bằng bộ lọc BILINEAR của Pillow (Image.resize). Đó không phải OpenCV INTER_LINEAR hay INTER_AREA: khi thu nhỏ, Pillow nới rộng bộ lọc theo hệ số thu nhỏ, còn các phép đổi kích thước của OpenCV làm thay đổi kết quả phát hiện và dịch các hộp đi vài pixel. Để tái tạo mà không dùng Pillow, hãy đổi kích thước một trục, làm tròn về 8 bit, rồi đổi kích thước trục còn lại và làm tròn lần nữa. Với mỗi trục, đặt s = in_size / out_size và f = max(s, 1). Pixel đầu ra i có tâm c = (i + 0.5) * s và đọc các pixel nguồn j từ int(c - f + 0.5) đến int(c + f + 0.5) - 1, giới hạn trong ảnh, mỗi pixel có trọng số max(0, 1 - |j + 0.5 - c| / f), chia cho tổng các trọng số. Pillow tính bằng dấu phẩy cố định và chọn thứ tự trục theo hình dạng ảnh, nên trọng số dấu phẩy động có thể lệch một mức ở vài pixel. Điều đó không làm thay đổi kết quả trong các kiểm tra của chúng tôi.

Square input only. Export rejects a non-square imgsz, and height equals width, 640 by default.

Channels are BGR, unlike detection. Pad value and position also differ from detection.

The longest side goes to R = min(640, height, width), so it fills the canvas.

Scale by r = min(R / h, R / w) and resize to (round(w * r), round(h * r)). The rounding is Python round, so an exact .5 goes to the even neighbor.

Paste the resized image in the top-left corner of a canvas filled with 127. All padding is on the bottom and the right.

On the test image, cv2.resize with INTER_LINEAR or INTER_AREA moves boxes by up to 5 px and keypoints by more than 10 px.

Divide by 255 after the resize. There is no mean or std normalization.

Pose, xuất mặc định
Đầu raHình dạngÝ nghĩa
boxes[batch, anchors, 4]Person boxes as x1, y1, x2, y2 in input-canvas pixels. anchors is the cell count over strides 8, 16 and 32, 8400 at 640 x 640.
scores[batch, anchors, nc]Class scores, sigmoid already applied. nc is 1 (person) for the COCO pose checkpoints.
keypoints_xy[batch, anchors, num_keypoints, 2]Keypoint x, y in input-canvas pixels. num_keypoints is 17 (COCO order) for the COCO pose checkpoints.
keypoints_conf[batch, anchors, num_keypoints]Per-keypoint visibility score, sigmoid already applied.

Hậu xử lý

  1. Take the best class per anchor: score = max over classes, class = argmax. With one class this is just the person score.
  2. Keep anchors whose score is at or above the confidence threshold (0.25 by default). This is >=, not > as in detection.
  3. Keep the 1000 highest scoring candidates.
  4. Map boxes and keypoints back to the original image: divide x and y by r. The image sits in the top-left corner, so there is no pad offset to subtract.
  5. Clip boxes to the image and drop boxes left with zero width or height. Keypoints are not clipped and can fall outside the image.
  6. Run NMS per class with IoU 0.45 and keep at most 300 detections. Keep each survivor's keypoints as (x, y, keypoints_conf).
  7. nms=True is not available for this family: export raises NotImplementedError.

LibreYOLONAS obb

Tensorimages float32 [batch, 3, height, width]
MàuBGR
Chuẩn hóa tỉ lệpixel / 255
Chuẩn hóakhông có
Đổi kích thướccustom, bilinear

Square input only. Export rejects a non-square imgsz, and height equals width, 1024 by default.

Channels are BGR, unlike detection. The resize filter and the pad position also differ from detection.

The longest side goes to R = min(1024, height, width), so it fills the canvas.

Scale by r = min(R / h, R / w) and resize to (round(w * r), round(h * r)). The rounding is Python round, so an exact .5 goes to the even neighbor.

The resize is cv2.resize with INTER_LINEAR, not Pillow as in detection and pose. It is skipped when the image already has that size. On the test image, Pillow's filter here changes the detection count.

Paste the resized image in the top-left corner of a canvas filled with 114. All padding is on the bottom and the right.

Divide by 255 after the resize. There is no mean or std normalization.

Oriented boxes, xuất mặc định
Đầu raHình dạngÝ nghĩa
boxes[batch, anchors, 5]Rotated boxes as cx, cy, w, h, angle. cx, cy, w and h are in input-canvas pixels. The angle is in radians. The graph computes it as (sigmoid(logit) - 0.25) x pi, so it lies between -pi/4 and 3pi/4 and is not wrapped yet. The w side points along (cos angle, sin angle) in image coordinates, y down. anchors is the cell count over strides 8, 16 and 32, 21504 at 1024 x 1024.
scores[batch, anchors, nc]Class scores, sigmoid already applied. 18 classes (DOTA 2.0) for the published checkpoints.

Hậu xử lý

  1. Take the best class per anchor: score = max over classes, class = argmax. One anchor yields at most one detection.
  2. Keep anchors whose score is at or above the confidence threshold (0.25 by default). This is >=, not > as in detection.
  3. Keep the 1000 highest scoring candidates.
  4. Map boxes back to the original image: divide cx, cy, w and h by r. The image sits in the top-left corner, so there is no pad offset, and the angle does not change.
  5. Clip cx to 0 to the image width and cy to 0 to the image height. w and h are not clipped. Drop boxes with w or h at or below 0.
  6. Put the long side first: if h > w, swap w and h and add pi/2 to the angle. Then wrap the angle to [-pi/2, pi/2) with angle = ((angle + pi/2) mod pi) - pi/2.
  7. Run greedy NMS per class on exact rotated-box IoU (polygon intersection area over union, for example cv2.rotatedRectangleIntersection) with IoU 0.45, and keep at most 300 detections. LibreYOLO does not use upstream's matrix soft-NMS.
  8. LibreYOLO also reports an axis-aligned box per detection. With ex = abs(cos angle) * w / 2 + abs(sin angle) * h / 2 and ey = abs(sin angle) * w / 2 + abs(cos angle) * h / 2, it is cx - ex, cy - ey, cx + ex, cy + ey, clipped to the image.
  9. nms=True is not available for this family: export raises NotImplementedError.

Để kiểm tra bản triển khai của bạn, hãy chạy cùng tệp đó qua LibreYOLO: LibreYOLO("model.onnx").predict("image.jpg") trả về kết quả tham chiếu. Đã kiểm chứng với LibreYOLO 1.7.0.

Checkpoint

Không có tệp nào để liệt kê. Giấy phép của Deci cấm phân phối lại, nên tổ chức LibreYOLO không công bố trọng số YOLO-NAS và bản tải được phân giải ở nơi khác: tên có dạng LibreYOLONAS<size>.pt, LibreYOLONAS<size>-pose.pt cho tư thế, hoặc LibreYOLONAS<size>-obb.pt (s, m, l) cho hộp xoay, ánh xạ đến đối tượng tương ứng trên CDN công khai của Deci.

Chỉ các checkpoint có SHA-256 được thư viện ghim mới có thể lấy theo cách đó. Mọi tệp khác đều bị từ chối an toàn thay vì mở pickle bên thứ ba chưa xác minh, và phải được tải thủ công rồi truyền dưới dạng đường dẫn. Tệp đã có trên đĩa được tải từ đường dẫn, không tải xuống và không qua cổng checksum. Điều này bao gồm tệp .pth của Deci theo tên gốc mà trình tải nhận diện.

Giấy phép

Hãy kiểm tra giấy phép trong repo Hugging Face của trọng số cụ thể mà bạn tải xuống. Mỗi checkpoint trong tổ chức LibreYOLO đều có giấy phép riêng và giấy phép có thể khác nhau trong cùng một họ. Repo đó là nguồn có thẩm quyền; phần tóm tắt dưới đây mô tả các điều khoản áp dụng khi trang này được kiểm chứng lần gần nhất.

Đây là phần mô tả các giấy phép liên quan, không phải tư vấn pháp lý. Nếu câu trả lời có ý nghĩa về mặt thương mại, hãy tự đọc các giấy phép và tham khảo cố vấn của riêng bạn.

Công trình gốc
YOLO-NAS, Deci.AI
Giấy phép thượng nguồn
Deci.AI proprietary, non-commercial
Nguồn thượng nguồn
github.com/Deci-AI/super-gradients
Mã nguồn LibreYOLO
MIT
Trọng số
Deci.AI proprietary, non-commercial, do tác giả phân phối. LibreYOLO không lưu trữ hoặc sao chép chúng.
Diễn giải
Two licenses apply here and they are not the same. The SuperGradients source this port follows is Apache-2.0 and LibreYOLO's own implementation is MIT, so nothing restricts the architecture or the training code. Deci's published checkpoints are a different matter: the YOLO-NAS license grants a revocable, non-transferable right to use them and nothing more. It forbids redistribution and sublicensing, forbids offering them as a managed or remote service, restricts modification and reverse engineering, and rules out commercial use, including any model running in a production environment, unless you hold a separate agreement with Deci. LibreYOLO therefore does not mirror them, and prints those terms once before the download starts. Weights trained from a randomly initialized model on your own data derive from no Deci checkpoint.

LibreYOLO không lưu trữ hay tạo bản sao các trọng số này: tổ chức Hugging Face LibreYOLO không có gì cho họ này. Mọi bản tự động tải đều đi đến CDN công khai của Deci, in các điều khoản của Deci một lần cho mỗi tiến trình trước khi bắt đầu và được kiểm tra với SHA-256 đã ghim trước khi mở tệp.

Huấn luyện từ mô hình khởi tạo ngẫu nhiên là phương án thay thế. Kiến trúc theo Apache-2.0 ở thượng nguồn và MIT tại đây, nên mô hình được huấn luyện theo cách đó trên dữ liệu của bạn không bắt nguồn từ checkpoint Deci nào.

Trích dẫn

YOLO-NAS được phát hành mà không có bài báo. Mục bên dưới là trích dẫn mà tác giả yêu cầu, bao quát SuperGradients, thư viện phân phối mô hình.

@misc{supergradients,
  doi = {10.5281/ZENODO.7789328},
  url = {https://zenodo.org/record/7789328},
  author = {Aharon,  Shay and {Louis-Dupont} and {Ofri Masad} and Yurkova,  Kate and {Lotem Fridman} and {Lkdci} and Khvedchenya,  Eugene and Rubin,  Ran and Bagrov,  Natan and Tymchenko,  Borys and Keren,  Tomer and Zhilko,  Alexander and {Eran-Deci}},
  title = {Super-Gradients},
  publisher = {GitHub},
  journal = {GitHub repository},
  year = {2021},
}

Được sao chép từ khối trích dẫn của tác giả tại github.com/Deci-AI/super-gradients#citing.

Đã kiểm chứng với LibreYOLO v1.6.0. Các bảng hỗ trợ, checkpoint và số liệu benchmark trên trang này được tạo từ thư viện đã phát hành và trọng số đã công bố, không phải viết thủ công.