Instructions to use zeromodels/dfine-xlarge with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/dfine-xlarge 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-xlarge") - Keras
How to use zeromodels/dfine-xlarge 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-xlarge") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +17 -17
- kf_config.json → zm_config.json +77 -77
- kf_preprocessor.json → zm_preprocessor.json +26 -26
README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
pipeline_tag: object-detection
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: ustc-community/dfine-xlarge-coco
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
-
-
|
| 9 |
- d-fine
|
| 10 |
- dfine
|
| 11 |
- detr
|
|
@@ -16,13 +16,13 @@ tags:
|
|
| 16 |
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 20 |
|
| 21 |
# Run D-FINE with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
|
| 23 |
-
[](https://arxiv.org/abs/2410.13842) · [HF Papers](https://huggingface.co/papers/2410.13842)
|
| 28 |
|
|
@@ -30,7 +30,7 @@ D-FINE is a real-time detector built on the RT-DETR recipe: an HGNetV2 backbone,
|
|
| 30 |
|
| 31 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/ustc-community/dfine-xlarge-coco).
|
| 32 |
|
| 33 |
-
Pure-**Keras 3** conversion of [`ustc-community/dfine-xlarge-coco`](https://huggingface.co/ustc-community/dfine-xlarge-coco) for [
|
| 34 |
|
| 35 |
This is an **object detection** checkpoint (`DFineDetect`) on COCO (HGNetV2-XLarge).
|
| 36 |
|
|
@@ -41,10 +41,10 @@ import os
|
|
| 41 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 42 |
|
| 43 |
from PIL import Image
|
| 44 |
-
from
|
| 45 |
|
| 46 |
-
model = DFineDetect.from_weights("
|
| 47 |
-
processor = DFineImageProcessor.from_weights("
|
| 48 |
|
| 49 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 50 |
inputs = processor(image)
|
|
@@ -58,21 +58,21 @@ for score, name, box in zip(
|
|
| 58 |
print(f"{name}: {float(score):.3f} {box}")
|
| 59 |
```
|
| 60 |
|
| 61 |
-
Load any D-FINE variant the same way with `from_weights("
|
| 62 |
|
| 63 |
| Variant | Hub | Backbone |
|
| 64 |
|---|---|---|
|
| 65 |
-
| `dfine-nano` | [`
|
| 66 |
-
| `dfine-small` | [`
|
| 67 |
-
| `dfine-medium` | [`
|
| 68 |
-
| `dfine-large` | [`
|
| 69 |
-
| `dfine-xlarge` | [`
|
| 70 |
|
| 71 |
## Tips
|
| 72 |
|
| 73 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 74 |
- `DFineImageProcessor` keeps `do_normalize=False` by default (rescaled `[0, 1]` input, matching upstream).
|
| 75 |
-
- See [D-FINE docs](https://imvision12.github.io/
|
| 76 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `DFineDetect.from_weights("hf:ustc-community/dfine-xlarge-coco")`.
|
| 77 |
|
| 78 |
## Special Thanks
|
|
|
|
| 2 |
pipeline_tag: object-detection
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: ustc-community/dfine-xlarge-coco
|
| 5 |
+
library_name: zeromodels
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
- d-fine
|
| 10 |
- dfine
|
| 11 |
- detr
|
|
|
|
| 16 |
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/d-fine-6a69d56d4bee59c3f582ebf0) for all versions of D-FINE.***
|
| 20 |
|
| 21 |
# Run D-FINE with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
|
| 23 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/dfine/) [](https://huggingface.co/collections/zeromodels/d-fine-6a69d56d4bee59c3f582ebf0)
|
| 24 |
|
| 25 |
+
# zeromodels/dfine-xlarge
|
| 26 |
|
| 27 |
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)
|
| 28 |
|
|
|
|
| 30 |
|
| 31 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/ustc-community/dfine-xlarge-coco).
|
| 32 |
|
| 33 |
+
Pure-**Keras 3** conversion of [`ustc-community/dfine-xlarge-coco`](https://huggingface.co/ustc-community/dfine-xlarge-coco) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 34 |
|
| 35 |
This is an **object detection** checkpoint (`DFineDetect`) on COCO (HGNetV2-XLarge).
|
| 36 |
|
|
|
|
| 41 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 42 |
|
| 43 |
from PIL import Image
|
| 44 |
+
from zeromodels.models.dfine import DFineDetect, DFineImageProcessor
|
| 45 |
|
| 46 |
+
model = DFineDetect.from_weights("zeromodels/dfine-xlarge")
|
| 47 |
+
processor = DFineImageProcessor.from_weights("zeromodels/dfine-xlarge")
|
| 48 |
|
| 49 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 50 |
inputs = processor(image)
|
|
|
|
| 58 |
print(f"{name}: {float(score):.3f} {box}")
|
| 59 |
```
|
| 60 |
|
| 61 |
+
Load any D-FINE variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 62 |
|
| 63 |
| Variant | Hub | Backbone |
|
| 64 |
|---|---|---|
|
| 65 |
+
| `dfine-nano` | [`zeromodels/dfine-nano`](https://huggingface.co/zeromodels/dfine-nano) | HGNetV2-Nano |
|
| 66 |
+
| `dfine-small` | [`zeromodels/dfine-small`](https://huggingface.co/zeromodels/dfine-small) | HGNetV2-Small |
|
| 67 |
+
| `dfine-medium` | [`zeromodels/dfine-medium`](https://huggingface.co/zeromodels/dfine-medium) | HGNetV2-Medium |
|
| 68 |
+
| `dfine-large` | [`zeromodels/dfine-large`](https://huggingface.co/zeromodels/dfine-large) | HGNetV2-Large |
|
| 69 |
+
| `dfine-xlarge` | [`zeromodels/dfine-xlarge`](https://huggingface.co/zeromodels/dfine-xlarge) | HGNetV2-XLarge |
|
| 70 |
|
| 71 |
## Tips
|
| 72 |
|
| 73 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 74 |
- `DFineImageProcessor` keeps `do_normalize=False` by default (rescaled `[0, 1]` input, matching upstream).
|
| 75 |
+
- See [D-FINE docs](https://imvision12.github.io/ZeroModels/dfine/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 76 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `DFineDetect.from_weights("hf:ustc-community/dfine-xlarge-coco")`.
|
| 77 |
|
| 78 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,78 +1,78 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "DFineDetect",
|
| 6 |
-
"variant": "dfine-xlarge",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "d_fine",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"stem_channels": [
|
| 13 |
-
3,
|
| 14 |
-
32,
|
| 15 |
-
64
|
| 16 |
-
],
|
| 17 |
-
"stage_in_channels": [
|
| 18 |
-
64,
|
| 19 |
-
128,
|
| 20 |
-
512,
|
| 21 |
-
1024
|
| 22 |
-
],
|
| 23 |
-
"stage_mid_channels": [
|
| 24 |
-
64,
|
| 25 |
-
128,
|
| 26 |
-
256,
|
| 27 |
-
512
|
| 28 |
-
],
|
| 29 |
-
"stage_out_channels": [
|
| 30 |
-
128,
|
| 31 |
-
512,
|
| 32 |
-
1024,
|
| 33 |
-
2048
|
| 34 |
-
],
|
| 35 |
-
"stage_num_blocks": [
|
| 36 |
-
1,
|
| 37 |
-
2,
|
| 38 |
-
5,
|
| 39 |
-
2
|
| 40 |
-
],
|
| 41 |
-
"stage_numb_of_layers": [
|
| 42 |
-
6,
|
| 43 |
-
6,
|
| 44 |
-
6,
|
| 45 |
-
6
|
| 46 |
-
],
|
| 47 |
-
"use_lab": false,
|
| 48 |
-
"encoder_in_channels": [
|
| 49 |
-
512,
|
| 50 |
-
1024,
|
| 51 |
-
2048
|
| 52 |
-
],
|
| 53 |
-
"encoder_hidden_dim": 384,
|
| 54 |
-
"encoder_ffn_dim": 2048,
|
| 55 |
-
"encode_proj_layers": [
|
| 56 |
-
2
|
| 57 |
-
],
|
| 58 |
-
"hidden_expansion": 1.0,
|
| 59 |
-
"ccfm_num_blocks": 3,
|
| 60 |
-
"hidden_dim": 256,
|
| 61 |
-
"decoder_num_layers": 6,
|
| 62 |
-
"decoder_ffn_dim": 1024,
|
| 63 |
-
"decoder_n_points": [
|
| 64 |
-
3,
|
| 65 |
-
6,
|
| 66 |
-
3
|
| 67 |
-
],
|
| 68 |
-
"num_feature_levels": 3,
|
| 69 |
-
"feat_strides": [
|
| 70 |
-
8,
|
| 71 |
-
16,
|
| 72 |
-
32
|
| 73 |
-
],
|
| 74 |
-
"num_classes": 80,
|
| 75 |
-
"num_queries": 300,
|
| 76 |
-
"image_size": 640
|
| 77 |
-
}
|
| 78 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.dfine",
|
| 5 |
+
"model_class": "DFineDetect",
|
| 6 |
+
"variant": "dfine-xlarge",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "d_fine",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"stem_channels": [
|
| 13 |
+
3,
|
| 14 |
+
32,
|
| 15 |
+
64
|
| 16 |
+
],
|
| 17 |
+
"stage_in_channels": [
|
| 18 |
+
64,
|
| 19 |
+
128,
|
| 20 |
+
512,
|
| 21 |
+
1024
|
| 22 |
+
],
|
| 23 |
+
"stage_mid_channels": [
|
| 24 |
+
64,
|
| 25 |
+
128,
|
| 26 |
+
256,
|
| 27 |
+
512
|
| 28 |
+
],
|
| 29 |
+
"stage_out_channels": [
|
| 30 |
+
128,
|
| 31 |
+
512,
|
| 32 |
+
1024,
|
| 33 |
+
2048
|
| 34 |
+
],
|
| 35 |
+
"stage_num_blocks": [
|
| 36 |
+
1,
|
| 37 |
+
2,
|
| 38 |
+
5,
|
| 39 |
+
2
|
| 40 |
+
],
|
| 41 |
+
"stage_numb_of_layers": [
|
| 42 |
+
6,
|
| 43 |
+
6,
|
| 44 |
+
6,
|
| 45 |
+
6
|
| 46 |
+
],
|
| 47 |
+
"use_lab": false,
|
| 48 |
+
"encoder_in_channels": [
|
| 49 |
+
512,
|
| 50 |
+
1024,
|
| 51 |
+
2048
|
| 52 |
+
],
|
| 53 |
+
"encoder_hidden_dim": 384,
|
| 54 |
+
"encoder_ffn_dim": 2048,
|
| 55 |
+
"encode_proj_layers": [
|
| 56 |
+
2
|
| 57 |
+
],
|
| 58 |
+
"hidden_expansion": 1.0,
|
| 59 |
+
"ccfm_num_blocks": 3,
|
| 60 |
+
"hidden_dim": 256,
|
| 61 |
+
"decoder_num_layers": 6,
|
| 62 |
+
"decoder_ffn_dim": 1024,
|
| 63 |
+
"decoder_n_points": [
|
| 64 |
+
3,
|
| 65 |
+
6,
|
| 66 |
+
3
|
| 67 |
+
],
|
| 68 |
+
"num_feature_levels": 3,
|
| 69 |
+
"feat_strides": [
|
| 70 |
+
8,
|
| 71 |
+
16,
|
| 72 |
+
32
|
| 73 |
+
],
|
| 74 |
+
"num_classes": 80,
|
| 75 |
+
"num_queries": 300,
|
| 76 |
+
"image_size": 640
|
| 77 |
+
}
|
| 78 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,27 +1,27 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "DFineImageProcessor",
|
| 6 |
-
"variant": "dfine-xlarge",
|
| 7 |
-
"size": {
|
| 8 |
-
"height": 640,
|
| 9 |
-
"width": 640
|
| 10 |
-
},
|
| 11 |
-
"resample": "bilinear",
|
| 12 |
-
"do_rescale": true,
|
| 13 |
-
"rescale_factor": 0.00392156862745098,
|
| 14 |
-
"do_normalize": false,
|
| 15 |
-
"image_mean": [
|
| 16 |
-
0.485,
|
| 17 |
-
0.456,
|
| 18 |
-
0.406
|
| 19 |
-
],
|
| 20 |
-
"image_std": [
|
| 21 |
-
0.229,
|
| 22 |
-
0.224,
|
| 23 |
-
0.225
|
| 24 |
-
],
|
| 25 |
-
"return_tensor": true,
|
| 26 |
-
"data_format": null
|
| 27 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.1.3",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.dfine",
|
| 5 |
+
"preprocessor_class": "DFineImageProcessor",
|
| 6 |
+
"variant": "dfine-xlarge",
|
| 7 |
+
"size": {
|
| 8 |
+
"height": 640,
|
| 9 |
+
"width": 640
|
| 10 |
+
},
|
| 11 |
+
"resample": "bilinear",
|
| 12 |
+
"do_rescale": true,
|
| 13 |
+
"rescale_factor": 0.00392156862745098,
|
| 14 |
+
"do_normalize": false,
|
| 15 |
+
"image_mean": [
|
| 16 |
+
0.485,
|
| 17 |
+
0.456,
|
| 18 |
+
0.406
|
| 19 |
+
],
|
| 20 |
+
"image_std": [
|
| 21 |
+
0.229,
|
| 22 |
+
0.224,
|
| 23 |
+
0.225
|
| 24 |
+
],
|
| 25 |
+
"return_tensor": true,
|
| 26 |
+
"data_format": null
|
| 27 |
}
|