Instructions to use zeromodels/dfine-medium with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/dfine-medium with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/dfine-medium") - Keras
How to use zeromodels/dfine-medium with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/dfine-medium") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from zeromodels/dfine-medium: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/zeromodels/dfine-medium/resolve/main/README.md
- Command line
-
hf download hf://zeromodels/dfine-medium/README.md
-
curl -L -o README.md https://huggingface.co/zeromodels/dfine-medium/resolve/main/README.md
3.88 kB
| pipeline_tag: object-detection | |
| license: apache-2.0 | |
| base_model: ustc-community/dfine-medium-coco | |
| library_name: zeromodels | |
| tags: | |
| - keras | |
| - zeromodels | |
| - d-fine | |
| - dfine | |
| - detr | |
| - object-detection | |
| - arxiv:2410.13842 | |
| - pytorch | |
| - jax | |
| - tf | |
| ## ***See [our collection](https://huggingface.co/collections/zeromodels/d-fine-6a8eaf8bc6d10755c3e14a80) for all versions of D-FINE.*** | |
| # Run D-FINE with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/dfine/) [](https://huggingface.co/collections/zeromodels/d-fine-6a8eaf8bc6d10755c3e14a80) | |
| # zeromodels/dfine-medium | |
| Paper: [D-FINE: Redefine Regression Task of DETRs as Fine-grained Distribution Refinement (arXiv:2410.13842)](https://arxiv.org/abs/2410.13842) · [HF Papers](https://huggingface.co/papers/2410.13842) | |
| 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](https://huggingface.co/ustc-community/dfine-medium-coco). | |
| Pure-**Keras 3** conversion of [`ustc-community/dfine-medium-coco`](https://huggingface.co/ustc-community/dfine-medium-coco) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**. | |
| This is an **object detection** checkpoint (`DFineDetect`) on COCO (HGNetV2-Medium). | |
| ## ✨ Quick start | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from PIL import Image | |
| from zeromodels.models.dfine import DFineDetect, DFineImageProcessor | |
| model = DFineDetect.from_weights("zeromodels/dfine-medium") | |
| processor = DFineImageProcessor.from_weights("zeromodels/dfine-medium") | |
| 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("zeromodels/<variant>")`: | |
| | Variant | Hub | Backbone | | |
| |---|---|---| | |
| | `dfine-nano` | [`zeromodels/dfine-nano`](https://huggingface.co/zeromodels/dfine-nano) | HGNetV2-Nano | | |
| | `dfine-small` | [`zeromodels/dfine-small`](https://huggingface.co/zeromodels/dfine-small) | HGNetV2-Small | | |
| | `dfine-medium` | [`zeromodels/dfine-medium`](https://huggingface.co/zeromodels/dfine-medium) | HGNetV2-Medium | | |
| | `dfine-large` | [`zeromodels/dfine-large`](https://huggingface.co/zeromodels/dfine-large) | HGNetV2-Large | | |
| | `dfine-xlarge` | [`zeromodels/dfine-xlarge`](https://huggingface.co/zeromodels/dfine-xlarge) | HGNetV2-XLarge | | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / zeromodels. | |
| - `DFineImageProcessor` keeps `do_normalize=False` by default (rescaled `[0, 1]` input, matching upstream). | |
| - See [D-FINE docs](https://imvision12.github.io/ZeroModels/dfine/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/). | |
| - Community / upstream safetensors still work via the `hf:` prefix, e.g. `DFineDetect.from_weights("hf:ustc-community/dfine-medium-coco")`. | |
| ## Special Thanks | |
| A huge thank you to the D-FINE authors (USTC community) for creating and releasing these models. | |
| License: Apache 2.0. | |