See our collection for all versions of D-FINE.

Run D-FINE with Keras 3: JAX, PyTorch, or TensorFlow

GitHub Docs Collection

kerasformers/dfine-xlarge

Paper: D-FINE: Redefine Regression Task of DETRs as Fine-grained Distribution Refinement (arXiv:2410.13842) · HF Papers

D-FINE is a real-time detector built on the RT-DETR recipe: an HGNetV2 backbone, a hybrid encoder, and a deformable decoder with 300 queries. It is NMS-free. Boxes are regressed via Fine-grained Distribution Refinement: each decoder layer predicts a distribution over discrete offset bins and accumulates refinements across layers.

For more details on the model, please go to the upstream model card.

Pure-Keras 3 conversion of ustc-community/dfine-xlarge-coco for kerasformers. One implementation runs unmodified on TensorFlow / Torch / JAX.

This is an object detection checkpoint (DFineDetect) on COCO (HGNetV2-XLarge).

✨ Quick start

import os
os.environ["KERAS_BACKEND"] = "torch"  # or "jax" / "tensorflow"

from PIL import Image
from kerasformers.models.dfine import DFineDetect, DFineImageProcessor

model = DFineDetect.from_weights("kerasformers/dfine-xlarge")
processor = DFineImageProcessor.from_weights("kerasformers/dfine-xlarge")

image = Image.open("your_image.jpg").convert("RGB")
inputs = processor(image)
output = model(inputs["pixel_values"], training=False)
results = processor.post_process_object_detection(
    output, threshold=0.5, target_sizes=[(image.height, image.width)]
)[0]
for score, name, box in zip(
    results["scores"], results["label_names"], results["boxes"]
):
    print(f"{name}: {float(score):.3f} {box}")

Load any D-FINE variant the same way with from_weights("kerasformers/<variant>"):

Variant Hub Backbone
dfine-nano kerasformers/dfine-nano HGNetV2-Nano
dfine-small kerasformers/dfine-small HGNetV2-Small
dfine-medium kerasformers/dfine-medium HGNetV2-Medium
dfine-large kerasformers/dfine-large HGNetV2-Large
dfine-xlarge kerasformers/dfine-xlarge HGNetV2-XLarge

Tips

  • Set KERAS_BACKEND before importing Keras / kerasformers.
  • DFineImageProcessor keeps do_normalize=False by default (rescaled [0, 1] input, matching upstream).
  • See D-FINE docs and Loading Weights.
  • Community / upstream safetensors still work via the hf: prefix, e.g. DFineDetect.from_weights("hf:ustc-community/dfine-xlarge-coco").

Special Thanks

A huge thank you to the D-FINE authors (USTC community) for creating and releasing these models.

License: Apache 2.0.

Downloads last month
21
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for kerasformers/dfine-xlarge

Finetuned
(2)
this model

Collection including kerasformers/dfine-xlarge

Paper for kerasformers/dfine-xlarge