IMvision12 commited on
Commit
a0e08fd
·
verified ·
1 Parent(s): 5e2864a

docs: Unsloth-style KerasFormers model card for dfine-medium

Browse files
Files changed (1) hide show
  1. README.md +67 -6
README.md CHANGED
@@ -1,21 +1,82 @@
1
  ---
2
  pipeline_tag: object-detection
3
  license: apache-2.0
 
4
  library_name: kerasformers
5
  tags:
6
  - keras
7
  - kerasformers
 
8
  - dfine
9
- - tf
10
- - jax
 
11
  - pytorch
 
 
12
  ---
13
 
14
- # dfine-medium (Keras 3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- Pure-Keras 3 weights for [kerasformers](https://github.com/IMvision12/KerasFormers), mirrored from the GitHub release. Apache 2.0.
 
 
17
 
18
  ```python
19
- from kerasformers.models.dfine import DFineDetect
20
- model = DFineDetect.from_weights("dfine-medium")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  pipeline_tag: object-detection
3
  license: apache-2.0
4
+ base_model: ustc-community/dfine-medium-coco
5
  library_name: kerasformers
6
  tags:
7
  - keras
8
  - kerasformers
9
+ - d-fine
10
  - dfine
11
+ - detr
12
+ - object-detection
13
+ - arxiv:2410.13842
14
  - pytorch
15
+ - jax
16
+ - tf
17
  ---
18
 
19
+ ## ***See [our collection](https://huggingface.co/collections/kerasformers/d-fine-6a69d56d4bee59c3f582ebf0) for all versions of D-FINE.***
20
+
21
+ # Run D-FINE with Keras 3: JAX, PyTorch, or TensorFlow
22
+
23
+ [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-D--FINE-blue)](https://imvision12.github.io/KerasFormers/dfine/) [![Collection](https://img.shields.io/badge/HF-D--FINE%20collection-yellow)](https://huggingface.co/collections/kerasformers/d-fine-6a69d56d4bee59c3f582ebf0)
24
+
25
+ # kerasformers/dfine-medium
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
+
29
+ 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.
30
+
31
+ For more details on the model, please go to the upstream [model card](https://huggingface.co/ustc-community/dfine-medium-coco).
32
+
33
+ Pure-**Keras 3** conversion of [`ustc-community/dfine-medium-coco`](https://huggingface.co/ustc-community/dfine-medium-coco) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
34
 
35
+ This is an **object detection** checkpoint (`DFineDetect`) on COCO (HGNetV2-Medium).
36
+
37
+ ## ✨ Quick start
38
 
39
  ```python
40
+ import os
41
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
42
+
43
+ from PIL import Image
44
+ from kerasformers.models.dfine import DFineDetect, DFineImageProcessor
45
+
46
+ model = DFineDetect.from_weights("kerasformers/dfine-medium")
47
+ processor = DFineImageProcessor()
48
+
49
+ image = Image.open("your_image.jpg").convert("RGB")
50
+ inputs = processor(image)
51
+ output = model(inputs["pixel_values"], training=False)
52
+ results = processor.post_process_object_detection(
53
+ output, threshold=0.5, target_sizes=[(image.height, image.width)]
54
+ )[0]
55
+ for score, name, box in zip(
56
+ results["scores"], results["label_names"], results["boxes"]
57
+ ):
58
+ print(f"{name}: {float(score):.3f} {box}")
59
  ```
60
+
61
+ Load any D-FINE variant the same way with `from_weights("kerasformers/<variant>")`:
62
+
63
+ | Variant | Hub | Backbone |
64
+ |---|---|---|
65
+ | `dfine-nano` | [`kerasformers/dfine-nano`](https://huggingface.co/kerasformers/dfine-nano) | HGNetV2-Nano |
66
+ | `dfine-small` | [`kerasformers/dfine-small`](https://huggingface.co/kerasformers/dfine-small) | HGNetV2-Small |
67
+ | `dfine-medium` | [`kerasformers/dfine-medium`](https://huggingface.co/kerasformers/dfine-medium) | HGNetV2-Medium |
68
+ | `dfine-large` | [`kerasformers/dfine-large`](https://huggingface.co/kerasformers/dfine-large) | HGNetV2-Large |
69
+ | `dfine-xlarge` | [`kerasformers/dfine-xlarge`](https://huggingface.co/kerasformers/dfine-xlarge) | HGNetV2-XLarge |
70
+
71
+ ## Tips
72
+
73
+ - Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
74
+ - `DFineImageProcessor` keeps `do_normalize=False` by default (rescaled `[0, 1]` input, matching upstream).
75
+ - See [D-FINE docs](https://imvision12.github.io/KerasFormers/dfine/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
76
+ - Community / upstream safetensors still work via the `hf:` prefix, e.g. `DFineDetect.from_weights("hf:ustc-community/dfine-medium-coco")`.
77
+
78
+ ## Special Thanks
79
+
80
+ A huge thank you to the D-FINE authors (USTC community) for creating and releasing these models.
81
+
82
+ License: Apache 2.0.