D-FINE
Detection transformer yang merumuskan ulang regresi box sebagai distribusi probabilitas atas setiap sisi box, lalu menyempurnakannya di sepanjang lapisan decoder. LibreYOLO mendukungnya untuk deteksi dan segmentasi instance.
- Task
- detection, instance segmentation
- Ukuran
- n, s, m, l, x at 640 px
- Instalasi
pip install libreyolo- Tier dukungan
- Inti, sejak v1.1.0. Detektor inti yang dapat dilatih: fitur menyusul tier unggulan dalam gelombang rilis yang sama.
- Proyek upstream
- D-FINE oleh University of Science and Technology of China, Apache-2.0. Makalah, sumber
- Lisensi
- Kode Apache-2.0, bobot Apache-2.0. Penggunaan komersial
Instalasi
D-FINE tidak memerlukan extra opsional. Semua yang diimpornya sudah ada di instalasi dasar.
pip install libreyoloFine-tuning berbasis adapter dengan lora=True adalah pengecualian, dan
memerlukan extra lora.
pip install "libreyolo[lora]"Prediksi
Bobot diunduh dari Hugging Face saat pertama kali dipakai dan disimpan di cache lokal.
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDFINEn.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreDFINEn.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # Sufiks -seg pada nama berkas memilih mask head, jadi argumen task# tidak diperlukan di sini.model = LibreYOLO("LibreDFINEn-seg.pt")result = model(SAMPLE_IMAGE, save=True) print(result.masks.data.shape)Objek Results yang dikembalikan sama dengan yang dikembalikan setiap family,
jadi mengganti detektor cukup lewat perubahan satu baris. Nama berkas dengan
-seg mengarah ke task segmentasi dengan sendirinya, dan result.masks lalu
membawa mask instance berdampingan dengan box. conf dan max_det menyaring
pemilihan query; iou diterima demi keseragaman API tetapi tidak berpengaruh,
karena decoder-nya adalah set predictor tanpa langkah NMS. Lihat
prediksi untuk sumber, streaming dan penanganan hasil.
Varian
Lima ukuran. Semuanya berjalan pada resolusi input yang sama, jadi tabel membedakannya lewat jumlah parameter dan akurasi.
| Checkpoint | Input (piksel) | mAP 50-95 | Parameter (juta) |
|---|---|---|---|
| LibreDFINEl | 640 | 60.0 | 31.24 |
| LibreDFINEm | 640 | 57.8 | 19.59 |
| LibreDFINEn | 640 | 45.8 | 3.78 |
| LibreDFINEs | 640 | 53.4 | 10.32 |
| LibreDFINEx | 640 | 61.4 | 62.62 |
COCO val2017, 500 images. Diukur oleh perangkat benchmark LibreYOLO dan dipublikasikan di Vision Analysis, tempat latensi pada berbagai hardware dan runtime dibandingkan serta rekaman lengkap setiap pengujian tersedia.
Segmentasi memakai ulang backbone, encoder dan decoder deteksi lalu menambahkan
mask head, jadi checkpoint -seg menerima argumen yang sama dengan saudaranya
yang detect. Family RT-DETRv4 di LibreYOLO ditulis sebagai subclass dari wrapper
D-FINE: ia mewarisi jalur decoder ini lalu mengunci daftar task-nya kembali ke
deteksi, karena tidak membawa mask head.
Pelatihan
Pelatihan dimulai dari checkpoint yang dipublikasikan, untuk kedua task.
from libreyolo import LibreYOLO model = LibreYOLO("LibreDFINEn.pt")model.train(data="my-dataset.yaml", epochs=50, imgsz=640, batch=8, lr0=2e-4)libreyolo train model=LibreDFINEn.pt data=my-dataset.yaml \ epochs=50 imgsz=640 batch=8 lr0=2e-4# Melanjutkan dari bobot segmentasi yang dipublikasikan, mask head ikut serta.libreyolo train model=LibreDFINEn-seg.pt data=my-dataset.yaml \ task=segment epochs=50 imgsz=640# Bobot detect tidak membawa mask head, jadi ini transfer eksplisit:# head-nya mulai tanpa pelatihan dan baru berguna setelah dilatih.# Meminta task=segment di sini yang mengizinkan transfer tersebut.libreyolo train model=LibreDFINEn.pt data=my-dataset.yaml \ task=segment epochs=50 imgsz=640from libreyolo import LibreYOLO model = LibreYOLO("LibreDFINEn.pt")model.train(data="my-dataset.yaml", epochs=50, lora=True)libreyolo train model=LibreDFINEn.pt data=my-dataset.yaml \ epochs=50 device=0,1 batch=16Secara default, trainer berjalan selama 132 epoch dengan lr0=2e-4, amp=True dan amp_dtype="float16", batch 16, serta early stopping setelah 50 epoch tanpa peningkatan. libreyolo train memulai dari resep yang sama untuk kedua task: AdamW dengan jadwal cosine datar, weight_decay=1e-4, 2 epoch warmup, pemotongan norma gradien 0.1, dan tanpa augmentasi mosaic, MixUp, HSV maupun affine. Tanpa name=, run-nya masuk ke runs/train/dfine_exp. Bobot deteksi dapat menjadi titik awal pelatihan segmentasi, tetapi hanya melalui transfer eksplisit, karena head mask belum dilatih dan akan menghasilkan mask yang tidak bermakna. Memberikan task=segment ke CLI mengizinkan transfer ini. Jalur Python lebih terbatas: LibreDFINE harus dibuat langsung dengan allow_detect_to_segment_transfer=True, karena factory LibreYOLO() tidak menerima argumen tersebut. Konstruksi langsung tidak mengunduh bobot, sehingga berkas bobot harus sudah ada di disk.
lora=True berlaku untuk deteksi. Pelatihan segment menolaknya dan mengarahkan
ke freeze='backbone', karena mask head belum diuji dengan adapter. Di Apple
silicon trainer memindahkan seluruh proses ke CPU: backward pass dari binned
matmul pada modul Integral memicu kegagalan kompilasi Metal. Inferensi di MPS
tidak terpengaruh.
Lihat pelatihan untuk dataset, augmentasi, multi-GPU dan logger.
Validasi
val() mengembalikan dictionary dengan kunci berupa nama metrik, dan mencetak
hasil per kelas jika verbose dibiarkan aktif.
from libreyolo import LibreYOLO model = LibreYOLO("LibreDFINEn.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])libreyolo val model=LibreDFINEn.pt data=my-dataset.yamlfrom libreyolo import LibreYOLO model = LibreYOLO("LibreDFINEn-seg.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95(M)"]) # maskprint(metrics["metrics/mAP50-95(B)"]) # boxPada checkpoint -seg, kunci metrics/mAP50-95 yang polos berisi skor mask,
dan proses yang sama juga melaporkan box di bawah (B) dan mask di bawah (M)
sehingga keduanya tersedia dari satu kali jalan.
Ekspor
| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Detection | Detection to ONNX: didukung | Detection to TorchScript: didukung | Detection to ExecuTorch: tidak didukung | Detection to TensorRT: didukung | Detection to OpenVINO: didukung | Detection to Paddle: didukung | Detection to MNN: didukung | Detection to RKNN: tidak didukung | Detection to ncnn: tidak didukung | Detection to TFLite: tidak didukung | Detection to CoreML: tidak didukung | Detection to Core AI: didukung |
| Instance segmentation | Instance segmentation to ONNX: didukung | Instance segmentation to TorchScript: didukung | Instance segmentation to ExecuTorch: tidak didukung | Instance segmentation to TensorRT: didukung | Instance segmentation to OpenVINO: didukung | Instance segmentation to Paddle: tidak didukung | Instance segmentation to MNN: tidak didukung | Instance segmentation to RKNN: tidak didukung | Instance segmentation to ncnn: tidak didukung | Instance segmentation to TFLite: tidak didukung | Instance segmentation to CoreML: tidak didukung | Instance segmentation to Core AI: tidak didukung |
Artefak hasil ekspor dimuat kembali lewat LibreYOLO() berdasarkan sufiks
berkasnya, jadi berkas .onnx atau .engine berperilaku seperti checkpoint dan
mengembalikan Results yang sama. Jalur OpenVINO, Paddle, MNN dan Core AI
mengekspor pada kanvas tetap, bukan bentuk dinamis. Ekspor
memuat daftar argumen yang diterima setiap format dan tambahan yang dipakai
beberapa di antaranya.
from libreyolo import LibreYOLO model = LibreYOLO("LibreDFINEn.pt")model.export(format="onnx", imgsz=640)model.export(format="tensorrt", imgsz=640, half=True)libreyolo export model=LibreDFINEn.pt format=onnx imgsz=640libreyolo export model=LibreDFINEn.pt format=tensorrt imgsz=640 half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # Factory memilih rute lewat sufiks berkas, jadi artefak hasil ekspor# dimuat seperti checkpoint biasa dan mengembalikan Results yang sama.model = LibreYOLO("LibreDFINEn.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)Input dan output ONNX
| Tensor | images float32 [batch, 3, height, width] |
|---|---|
| Warna | RGB |
| Penskalaan | piksel / 255 |
| Normalisasi | tidak ada |
| Ubah ukuran | regangkan ke lebar x tinggi (tanpa padding, rasio aspek tidak dipertahankan), Pillow bilinear |
Cara mereproduksi resize bilinear Pillow
LibreYOLO mengubah ukuran dengan filter BILINEAR milik Pillow (Image.resize). Ini bukan OpenCV INTER_LINEAR maupun INTER_AREA: saat memperkecil, Pillow memperlebar filter sebesar faktor pengecilan, dan resize OpenCV mengubah deteksi serta menggeser kotak beberapa piksel. Untuk mereproduksinya tanpa Pillow, ubah ukuran satu sumbu, bulatkan ke 8 bit, lalu ubah ukuran sumbu lainnya dan bulatkan lagi. Per sumbu, misalkan s = in_size / out_size dan f = max(s, 1). Piksel keluaran i berpusat di c = (i + 0.5) * s dan membaca piksel sumber j dari int(c - f + 0.5) sampai int(c + f + 0.5) - 1, dibatasi pada gambar, masing-masing dengan bobot max(0, 1 - |j + 0.5 - c| / f), dibagi jumlah bobot. Pillow bekerja dengan fixed point dan memilih urutan sumbu dari bentuk gambar, sehingga bobot float dapat berbeda satu level pada beberapa piksel. Hal itu tidak mengubah hasil pada pemeriksaan kami.
Square input only. Export rejects a non-square imgsz, and height and width are 640 by default.
Batch size 1 only. The graph declares a dynamic batch axis, but batches of 2 or more fail in 1.7.0.
Divide by 255 after the resize. There is no mean or std normalization.
Detection, ekspor default
| Output | Bentuk | Arti |
|---|---|---|
pred_logits | [batch, queries, nc] | One logit per query and class. Sigmoid is not applied. queries is 300 for every size. |
pred_boxes | [batch, queries, 4] | cx, cy, w, h of each query, normalized 0 to 1 of the input. The input is the whole image stretched, so these are also fractions of the original image. |
Pascapemrosesan
- Apply sigmoid to pred_logits.
- Flatten the [queries, nc] scores and take the top 300 (max_det, 300 by default). For flat index k, the query is k // nc and the class is k % nc. One query can yield several classes.
- Keep the pairs whose score is above the confidence threshold (0.25 by default).
- Convert the query's box to x1 = cx - w / 2, y1 = cy - h / 2, x2 = cx + w / 2, y2 = cy + h / 2. Multiply x by the original image width and y by the original image height.
- There is no NMS and the iou threshold is not used. D-FINE predicts a set of boxes, and export with nms=True raises NotImplementedError.
- LibreYOLO does not clip these boxes, so an edge can sit slightly outside the image.
Instance segmentation, ekspor default
| Output | Bentuk | Arti |
|---|---|---|
pred_logits | [batch, queries, nc] | One logit per query and class. Sigmoid is not applied. queries is 300 for every size. |
pred_boxes | [batch, queries, 4] | cx, cy, w, h of each query, normalized 0 to 1 of the input. The input is the whole image stretched, so these are also fractions of the original image. |
pred_masks | [batch, queries, mask_h, mask_w] | One mask per query, sigmoid already applied. mask_h is height / 4 and mask_w is width / 4, 160 x 160 at 640 x 640. |
Pascapemrosesan
- Apply sigmoid to pred_logits.
- Flatten the [queries, nc] scores and take the top 300 (max_det, 300 by default). For flat index k, the query is k // nc and the class is k % nc. One query can yield several classes.
- Keep the pairs whose score is above the confidence threshold (0.25 by default).
- Convert the query's box to x1 = cx - w / 2, y1 = cy - h / 2, x2 = cx + w / 2, y2 = cy + h / 2. Multiply x by the original image width and y by the original image height.
- For each kept pair, take its query's mask. Resize it with bilinear interpolation and half-pixel centers (align_corners=False, no antialiasing) to height x width, then again to the original image size.
- A pixel belongs to the mask when its value is 0.5 or more.
- Clear every mask pixel outside the box. Pixel (x, y) stays only when x1 <= x < x2 and y1 <= y < y2, in original-image pixels.
- There is no NMS and the iou threshold is not used. D-FINE predicts a set of boxes, and export with nms=True raises NotImplementedError.
- LibreYOLO does not clip the boxes of a .pt predict, so an edge can sit slightly outside the image. Its ONNX backend clips them to the image.
Untuk memeriksa implementasi Anda sendiri, jalankan file yang sama lewat LibreYOLO: LibreYOLO("model.onnx").predict("image.jpg") mengembalikan hasil acuan. Diverifikasi dengan LibreYOLO 1.7.0.
Checkpoint
Semua berkas bobot yang dipublikasikan untuk family ini.
| Berkas | Input (piksel) | Lisensi bobot |
|---|---|---|
| Detection | ||
| LibreDFINEn.pt | 640 | apache-2.0 |
| LibreDFINEs.pt | 640 | apache-2.0 |
| LibreDFINEm.pt | 640 | apache-2.0 |
| LibreDFINEl.pt | 640 | apache-2.0 |
| LibreDFINEx.pt | 640 | apache-2.0 |
| Instance segmentation | ||
| LibreDFINEn-seg.pt | 640 | apache-2.0 |
| LibreDFINEs-seg.pt | 640 | apache-2.0 |
| LibreDFINEm-seg.pt | 640 | apache-2.0 |
| LibreDFINEl-seg.pt | 640 | apache-2.0 |
| LibreDFINEx-seg.pt | 640 | apache-2.0 |
Setiap berkas di atas saat ini tersedia di organisasi LibreYOLO dan diunduh saat pertama kali digunakan.
Lisensi
Periksa lisensi di repositori Hugging Face untuk bobot tertentu yang diunduh. Setiap checkpoint di organisasi LibreYOLO memiliki lisensi, dan lisensinya tidak selalu sama dalam satu family. Repositori tersebut adalah sumber resmi. Ringkasan di bawah menjelaskan ketentuan yang berlaku saat halaman ini terakhir diverifikasi.
Ini adalah deskripsi lisensi yang terlibat, bukan nasihat hukum. Jika jawabannya penting secara komersial, baca sendiri lisensinya dan mintalah nasihat dari penasihat hukum Anda.
- Karya asli
- D-FINE, University of Science and Technology of China
- Lisensi upstream
- Apache-2.0
- Sumber upstream
- github.com/Peterande/D-FINE
- Kode LibreYOLO
- MIT
- Bobot
- Apache-2.0, dipublikasikan ulang di huggingface.co/LibreYOLO
- Interpretasi
- Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code, and weights you train yourself on your own data are yours. The segmentation weights carry a second Apache-2.0 upstream, ArgoHA/D-FINE-seg, under the same terms.
Bobot segmentasi punya upstream kedua: mask decoder, mask matching dan mask loss-nya berasal dari ArgoHA/D-FINE-seg, juga Apache-2.0, dan maintainer-nya menyetujui penggunaan ulang dengan atribusi.
Sitasi
@misc{peng2024dfine,
title={D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement},
author={Yansong Peng and Hebei Li and Peixi Wu and Yueyi Zhang and Xiaoyan Sun and Feng Wu},
year={2024},
eprint={2410.13842},
archivePrefix={arXiv},
primaryClass={cs.CV}
}Disalin dari blok sitasi penulis di github.com/Peterande/D-FINE#citation.