YOLOv9
1回の処理で密なボックスグリッドにスコアを付け、NMSで重複を除く1段畳み込み検出器です。LibreYOLOには3つのバリアントがあり、そのうち1つはNMSステップを持ちません。
- タスク
- detection
- サイズ
- yolo9: t, s, m, c at 640 px; yolo9_p2: t, s at 640 px
- インストール
pip install libreyolo- サポートティア
- フラッグシップ、v1.0.0以降。機能はまずここで設計され、GPUで完全に検証されます。
- ライセンス
- コード:MIT、重み:MIT。商用利用
インストール
YOLOv9には基本パッケージ以外の追加パッケージは不要です。
pip install libreyolo推論
重みは初回使用時にHugging Faceからダウンロードされ、ローカルにキャッシュされます。
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreYOLO9s.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreYOLO9s.pt save=True \ source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpgfrom libreyolo import LibreYOLO, SAMPLE_IMAGE # 同じ呼び出しで異なるチェックポイントを使用 エンドツーエンドヘッドが# 高スコアの予測を返すため NMS は実行されず iou は無視されるmodel = LibreYOLO("LibreYOLO9E2Es.pt")result = model(SAMPLE_IMAGE, conf=0.25, max_det=300) print(len(result.boxes))返されるResultsオブジェクトはすべてのファミリーに共通するため、別の検出器への切り替えは1行の変更で済みます。基本モデルとstride 4モデルでは、confが信頼度のしきい値、iouがNMSのしきい値を設定します。エンドツーエンドモデルはNMSを実行せずiouを無視するため、confとmax_detで出力が決まります。ソース、ストリーミング、結果の処理については推論を参照してください。
バリアント
3つのバリアントがバックボーンを共有します。3つすべてが検出専用で、同じ引数を受け取ります。
基本モデルは3つの特徴スケールで予測し、NMSで重複するボックスを除去します。
エンドツーエンドモデルはそのヘッドを維持し、隣に1対1マッチングの分岐を追加します。推論では1対1の分岐だけを読み取り、高スコアの予測を取得するため、NMSは実行されません。デプロイ先のランタイムにNMS演算子がない場合に選択してください。
stride 4モデルはバックボーンのさらに上位の1レベルを表に出し、そこまでネックを拡張し、3つではなく4つのスケールで予測します。追加のスケールは少数のピクセルしか占めない物体向けです。公開されている唯一のチェックポイントは航空画像で学習されています。基本検出チェックポイントを転移できます。バックボーンとネックは変更せずに読み込まれ、3つの学習済みヘッドタワーは1スロット上にずれ、stride 4タワーはランダム初期化から開始します。
| チェックポイント | 入力(px) | mAP 50-95 | パラメータ(M) |
|---|---|---|---|
| LibreYOLO9c | 640 | 56.4 | 25.5 |
| LibreYOLO9m | 640 | 55.3 | 20.12 |
| LibreYOLO9s | 640 | 55.9 | 7.2 |
| LibreYOLO9t | 640 | 41.8 | 2.04 |
COCO val2017, 500 images。LibreYOLOベンチマークハーネスで測定し、Vision Analysisで公開しています。そこではハードウェアおよびランタイム別のレイテンシを比較でき、完全な実行記録も確認できます。
学習
from libreyolo import LibreYOLO model = LibreYOLO("LibreYOLO9s.pt")model.train(data="my-dataset.yaml", epochs=100, imgsz=640, batch=16)libreyolo train model=LibreYOLO9s.pt data=my-dataset.yaml \ epochs=100 imgsz=640 batch=16from libreyolo import LibreYOLO9P2 # stride 4 バリアントには固有の COCO チェックポイントがないため# 基本検出モデルを指定 バックボーンとネックはそのまま読み込み# stride 4 ヘッドタワーはランダム初期化で開始model = LibreYOLO9P2(None, size="s")model.train(data="my-dataset.yaml", epochs=100, pretrained="LibreYOLO9s.pt")pretrainedによって実行の開始点が決まります。同じモデルとサイズの公開済みチェックポイントを読み込むにはTrueを渡し、それ以外の場合は名前またはパスを渡してください。形状が一致しないテンソルは拒否されずにスキップされ、読み込んだ数が実行ログに記録されます。そのため、異なるクラス数で学習したチェックポイントも開始点として使えます。
stride 4モデルには固有の公開済みCOCOチェックポイントがないため、そこでTrueを指定すると存在しないファイルに解決され、ダウンロードに失敗します。代わりに基本検出チェックポイントを指定してください。
データセット、データ拡張、マルチGPU、ロガーについては学習を参照してください。
基本モデルは、主ヘッドの隣でPGI補助分岐を学習できます。この分岐は学習専用で、推論とエクスポートでは主ヘッドを使います。開始時の重みがPGIテンソルを持つ場合、またはゼロから学習する場合に、実行はこの分岐を付けます。公開されている基本チェックポイントはPGIテンソルを持たないため、それらからのファインチューニングは主ヘッドだけを学習し、その旨をログに記録します。それでもaux_weight=0.25を指定するとその損失の重みで新しい分岐を付け、aux_weight=0は分岐を無効のままにします。再開した実行は、チェックポイントのPGI構成を維持します。mとcのサイズでは、分岐はアップストリームと同じ構成です:入力画像に対する2つ目のバックボーン(その各ステージをCBFuseが主バックボーンのCBLinearタップと合算)と独自のヘッドからなり、80クラスで学習専用のパラメータは12.8Mと25.7Mです。エンドツーエンドモデルとstride 4モデルにはPGI分岐がありません。
3つのバリアントはすべて、各オプティマイザーステップの前に勾配のL2ノルムを10でクリップします。clip_max_norm=0でクリッピングを無効にできます。ラベル割り当ては、float16のautocast下でもアンカーをfp32でスコアリングします。max_labels=300は学習画像あたりに保持するボックス数の上限で、それを超えたボックスは一度だけの警告とともに破棄されます。割り当てのメモリは上限ではなく、各画像の実際のボックスに従います。SGDのモーメンタムは3エポックで0.8から0.937にウォームアップします。letterbox_pad=Noneはチェックポイントに記録された設定を継承します。記録のない重みはtopleftを使い、新しい公式変換にはcenterが記録されます。
YOLO9とYOLOXのMosaicは、最大20回の抽出でアノテーション付きの画像を優先します。YOLO9のMixUpも同じ方針を使います。MixUpはデフォルトで無効です(mixup_prob=0)。有効にすると、MultimediaTechLab/YOLOと同様に、混合比率を[0, 1]上の一様分布であるBeta(1, 1)から抽出します。RGB以外の入力プロファイルについてはイベントヒストグラムを参照してください。
検証
val()は、学習に使用した形式の任意のデータセットで測定した適合率、再現率、mAP 50、mAP 50-95を含むmetrics/キーの辞書を返します。
from libreyolo import LibreYOLO model = LibreYOLO("LibreYOLO9s.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])libreyolo val model=LibreYOLO9s.pt data=my-dataset.yaml# 同梱の COCO yaml はダウンロードスクリプトを内包するため# データセットがローカルにない場合は明示的な許可が必要libreyolo val model=LibreYOLO9c.pt data=coco.yaml imgsz=640 \ allow_download_scripts=Trueエクスポート
| タスク | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Detection | Detection to ONNX:対応 | Detection to TorchScript:対応 | Detection to ExecuTorch:対応 | Detection to TensorRT:対応 | Detection to OpenVINO:対応 | Detection to Paddle:対応 | Detection to MNN:対応 | Detection to RKNN:非対応 | Detection to ncnn:対応 | Detection to TFLite:非対応 | Detection to CoreML:非対応 | Detection to Core AI:対応 |
チェックマークは3つすべてのバリアントに適用されます。差がある場合、マトリクスには3つのうち最も弱いものが示されます。
エクスポートした成果物は、ファイルサフィックスに基づいてLibreYOLO()から再度読み込めます。そのため、.onnxまたは.engineファイルはチェックポイントと同様に動作し、同じResultsを返します。LibreYOLOをインストールせず、単独のランタイムでグラフを実行することもサポートされますが、その場合は前処理と後処理を自分で実装する必要があります。
基本検出モデルでは、その後処理部分をグラフ内に移動できます。ONNXエクスポートでnms=Trueを指定すると抑制がモデル内部に組み込まれ、最初の出力は固定された(1, max_det, 6)テンソルになります。各行はx1, y1, x2, y2, score, classで、検出数を超える部分はゼロでパディングされます。このグラフはバッチ1で、動的軸を持ちません。エンドツーエンドモデルとstride 4モデルはこのフラグを受け付けません。
各形式では異なる追加パッケージをインストールし、それぞれ固有の引数をいくつか受け取ります。どちらも該当する形式のページに記載されています。
from libreyolo import LibreYOLO model = LibreYOLO("LibreYOLO9s.pt")model.export(format="onnx", imgsz=640)libreyolo export model=LibreYOLO9s.pt format=onnx imgsz=640libreyolo export model=LibreYOLO9s.pt format=onnx nms=True \ conf=0.25 iou=0.45 max_det=300from libreyolo import LibreYOLO, SAMPLE_IMAGE # ファクトリーはファイルサフィックスで振り分けるためエクスポート成果物も# 任意のチェックポイントと同様に読み込まれ同じ Results オブジェクトを返すmodel = LibreYOLO("LibreYOLO9s.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)TFLite INT8では、キャリブレーションデータとint8=Trueを使います。
ONNX の入力と出力
LibreYOLO9
| テンソル | images float32 [batch, 3, height, width] |
|---|---|
| 色 | RGB |
| スケーリング | ピクセル値 / 255 |
| 正規化 | なし |
| リサイズ | letterbox, bilinear, パディング値 114, パディング位置はメタデータキー letterbox_pad から取得 |
Scale by r = min(height / h, width / w), resize to (int(w * r), int(h * r)) and paste onto a canvas filled with 114.
Paste position comes from the letterbox_pad metadata key: topleft puts the image in the top-left corner, center splits the padding on both sides. A missing key means topleft.
Detection、デフォルトのエクスポート
| 出力 | 形状 | 意味 |
|---|---|---|
output | [batch, 4 + nc, anchors] | Rows 0 to 3 are x1, y1, x2, y2 in input-canvas pixels. Rows 4 onward are per-class scores, sigmoid already applied. anchors is the cell count over strides 8, 16 and 32, 8400 at 640 x 640. |
後処理
- Transpose to [anchors, 4 + nc].
- Keep every (anchor, class) pair whose score is above the confidence threshold (0.25 by default). One anchor can yield several classes.
- Run NMS per class with IoU 0.45 and keep at most 300 detections.
- Map boxes back to the original image: subtract the pad offset, divide by r, clip to the image.
- Drop boxes whose width or height is 0 after clipping.
Detection、nms=True
| 出力 | 形状 | 意味 |
|---|---|---|
output | [1, max_det, 6] | Rows are x1, y1, x2, y2, score, class in input-canvas pixels, zero-padded past the detection count. Confidence, IoU and max_det are baked in and recorded as nms_conf, nms_iou and max_det metadata. |
raw | [1, 4 + nc, anchors] | The same tensor as the default export's output, before suppression. |
後処理
- Drop rows whose score is 0 or below your threshold.
- Map boxes back to the original image: subtract the pad offset, divide by r, clip to the image.
LibreYOLO9E2E
| テンソル | images float32 [batch, 3, height, width] |
|---|---|
| 色 | RGB |
| スケーリング | ピクセル値 / 255 |
| 正規化 | なし |
| リサイズ | letterbox, bilinear, パディング値 114, パディング位置はメタデータキー letterbox_pad から取得 |
Scale by r = min(height / h, width / w), resize to (int(w * r), int(h * r)) and paste onto a canvas filled with 114.
Paste position comes from the letterbox_pad metadata key: topleft puts the image in the top-left corner, center splits the padding on both sides. A missing key means topleft.
This model has no nms=True export. The exporter raises NotImplementedError, so only the default export below exists.
Detection、デフォルトのエクスポート
| 出力 | 形状 | 意味 |
|---|---|---|
output | [batch, 4 + nc, anchors] | Predictions of the one-to-one head only. Rows 0 to 3 are x1, y1, x2, y2 in input-canvas pixels. Rows 4 onward are per-class scores, sigmoid already applied. anchors is the cell count over strides 8, 16 and 32, 8400 at 640 x 640. |
後処理
- Transpose to [anchors, 4 + nc].
- Flatten the [anchors, nc] scores into one list of anchors x nc (anchor, class) pairs. Pair i belongs to anchor i / nc (integer division) and class i % nc.
- Keep the 300 highest-scoring pairs (max_det), highest first. One anchor can yield several classes.
- Of those, keep the pairs whose score is above the confidence threshold (0.25 by default).
- Do not run NMS. The one-to-one head is trained to fire once per object, and LibreYOLO ignores the iou setting for this model.
- Map boxes back to the original image: subtract the pad offset, divide by r, clip to the image.
- Drop boxes whose width or height is 0 after clipping.
LibreYOLO9P2
| テンソル | images float32 [batch, 3, height, width] |
|---|---|
| 色 | RGB |
| スケーリング | ピクセル値 / 255 |
| 正規化 | なし |
| リサイズ | letterbox, bilinear, パディング値 114, パディング位置はメタデータキー letterbox_pad から取得 |
Scale by r = min(height / h, width / w), resize to (int(w * r), int(h * r)) and paste onto a canvas filled with 114.
Paste position comes from the letterbox_pad metadata key: topleft puts the image in the top-left corner, center splits the padding on both sides. A missing key means topleft.
This model has no nms=True export. The exporter raises NotImplementedError, so only the default export below exists.
Detection、デフォルトのエクスポート
| 出力 | 形状 | 意味 |
|---|---|---|
output | [batch, 4 + nc, anchors] | Rows 0 to 3 are x1, y1, x2, y2 in input-canvas pixels. Rows 4 onward are per-class scores, sigmoid already applied. anchors is the cell count over strides 4, 8, 16 and 32, 34000 at 640 x 640. nc is 10 for LibreYOLO9P2s-visdrone. |
後処理
- Transpose to [anchors, 4 + nc].
- Keep every (anchor, class) pair whose score is above the confidence threshold (0.25 by default). One anchor can yield several classes.
- Run NMS per class with IoU 0.45 and keep at most 300 detections.
- Map boxes back to the original image: subtract the pad offset, divide by r, clip to the image.
- Drop boxes whose width or height is 0 after clipping.
自分の実装を確認するには、同じファイルを LibreYOLO で実行します。LibreYOLO("model.onnx").predict("image.jpg") が基準となる結果を返します。 LibreYOLO 1.7.0 で検証済み。
チェックポイント
このファミリーで公開されているすべての重みファイルです。
| ファイル | 入力(px) | 重みのライセンス |
|---|---|---|
| Detection | ||
| LibreYOLO9t.pt | 640 | mit |
| LibreYOLO9s.pt | 640 | mit |
| LibreYOLO9m.pt | 640 | mit |
| LibreYOLO9c.pt | 640 | mit |
| LibreYOLO9E2Et.pt | 640 | mit |
| LibreYOLO9E2Es.pt | 640 | mit |
| LibreYOLO9E2Em.pt | 640 | mit |
| LibreYOLO9E2Ec.pt | 640 | mit |
| LibreYOLO9P2s-visdrone.pt | cc-by-nc-sa-3.0 | |
上記のすべてのファイルは現在LibreYOLO orgにあり、初回使用時にダウンロードされます。
ライセンス
ダウンロードする特定の重みについて、Hugging Faceリポジトリのライセンスを確認してください。LibreYOLO orgの各チェックポイントにはライセンスが付与されており、同じファミリー内でも常に同一とは限りません。そのリポジトリが正式な情報源です。以下の概要は、このページを最後に検証した時点で適用されていた内容を示します。
これは関連するライセンスの説明であり、法的助言ではありません。商用上重要な場合は、自分でライセンスを読み、専門家の助言を受けてください。
- 原著作物
- YOLOv9, MultimediaTechLab
- アップストリームのライセンス
- MIT
- アップストリームのソース
- github.com/MultimediaTechLab/YOLO
- LibreYOLOのコード
- MIT
- 重み
- MIT、huggingface.co/LibreYOLOで再公開
- 解釈
- MIT is a permissive license, so these weights can be used in commercial and closed-source products. The one standing obligation is to keep the license text and the copyright notice, Kin-Yiu Wong and Hao-Tang Tsui, with any copy you redistribute. It places no condition on your own application code, and a model you train yourself on your own data is yours. Two things are worth knowing beyond that. The code is ported from the authors' MIT re-release of YOLOv9, MultimediaTechLab/YOLO at commit c4cb5f6f, not the GPL-3.0 repository that carries the same model, so the permissive terms come from the source LibreYOLO actually derives from. And one checkpoint in this family is not MIT: the weight repository of the stride-4 VisDrone model, LibreYOLO9P2s-visdrone.pt, declares CC BY-NC-SA 3.0, which rules out commercial use and requires share-alike on derivatives.
3つのバリアントのコードはすべて、MultimediaTechLab/YOLOのコミットc4cb5f6f(MIT)から移植しています。エンドツーエンドモデルの1対1予測器は、Yiqun ChenによるDATE(Apache-2.0)の設計に従っており、DATEのコードを一切コピーせずにLibreYOLO向けに実装しています。stride 4レベルはLibreYOLOのコードです。
stride 4の航空画像用チェックポイントはVisDroneのクラスを予測します。重みのリポジトリに記録された、公開元のライセンス宣言を確認してください。
引用
@inproceedings{wang2024yolov9,
title={{YOLOv9}: Learning What You Want to Learn Using Programmable Gradient Information},
author={Wang, Chien-Yao and Yeh, I-Hau and Liao, Hong-Yuan Mark},
year={2024},
booktitle={Proceedings of the European Conference on Computer Vision (ECCV)},
}著者によるgithub.com/MultimediaTechLab/YOLO#citationsの引用ブロックからコピーしています。