IMvision12 commited on
Commit
64c32fc
·
verified ·
1 Parent(s): 500acf5

Add kf_preprocessor.json; load processor via from_weights

Browse files
Files changed (2) hide show
  1. README.md +75 -72
  2. kf_preprocessor.json +23 -0
README.md CHANGED
@@ -1,72 +1,75 @@
1
- ---
2
- pipeline_tag: image-feature-extraction
3
- license: apache-2.0
4
- library_name: kerasformers
5
- tags:
6
- - keras
7
- - kerasformers
8
- - dino
9
- - feature-extraction
10
- - vision
11
- - arxiv:2104.14294
12
- - pytorch
13
- - jax
14
- - tf
15
- ---
16
-
17
- ## ***See [our collection](https://huggingface.co/collections/kerasformers/dino-v1-v2-v3-6a6a94f8281a2f373f70e769) for all versions of DINO.***
18
-
19
- # Run DINO with Keras 3: JAX, PyTorch, or TensorFlow
20
-
21
- [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-DINO-blue)](https://imvision12.github.io/KerasFormers/dino/) [![Collection](https://img.shields.io/badge/HF-DINO%20collection-yellow)](https://huggingface.co/collections/kerasformers/dino-v1-v2-v3-6a6a94f8281a2f373f70e769)
22
-
23
- # kerasformers/dino_resnet50
24
-
25
- Paper: [Emerging Properties in Self-Supervised Vision Transformers (arXiv:2104.14294)](https://arxiv.org/abs/2104.14294) · [HF Papers](https://huggingface.co/papers/2104.14294)
26
-
27
- DINO is self-supervised: a student and teacher match across crops of the same image with no labels. The resulting features are semantic for free. These checkpoints are backbones that return tokens / feature maps.
28
-
29
- Pure-**Keras 3** port for [kerasformers](https://github.com/IMvision12/KerasFormers), converted from the official upstream release. One implementation runs unmodified on **TensorFlow / Torch / JAX**.
30
-
31
- This is a **self-supervised backbone** (`DinoResNetModel`), not a task head.
32
-
33
- ## ✨ Quick start
34
-
35
- ```python
36
- import os
37
- os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
38
-
39
- import numpy as np
40
- from PIL import Image
41
- from kerasformers.models.dino import DinoResNetModel
42
-
43
- model = DinoResNetModel.from_weights("kerasformers/dino_resnet50", image_size=448)
44
- image = Image.open("your_image.jpg").convert("RGB")
45
- x = np.asarray(image.resize((448, 448)))[None].astype("float32")
46
- tokens = model(x, training=False)
47
- print(tokens.shape)
48
- ```
49
-
50
- Load any DINO variant the same way with `from_weights("kerasformers/<variant>")`:
51
-
52
- | Variant | Hub | Backbone |
53
- |---|---|---|
54
- | `dino_vits16` | [`kerasformers/dino_vits16`](https://huggingface.co/kerasformers/dino_vits16) | ViT-S/16 |
55
- | `dino_vits8` | [`kerasformers/dino_vits8`](https://huggingface.co/kerasformers/dino_vits8) | ViT-S/8 |
56
- | `dino_vitb16` | [`kerasformers/dino_vitb16`](https://huggingface.co/kerasformers/dino_vitb16) | ViT-B/16 |
57
- | `dino_vitb8` | [`kerasformers/dino_vitb8`](https://huggingface.co/kerasformers/dino_vitb8) | ViT-B/8 |
58
- | `dino_resnet50` | [`kerasformers/dino_resnet50`](https://huggingface.co/kerasformers/dino_resnet50) | ResNet-50 |
59
-
60
- ## Tips
61
-
62
- - Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
63
- - Feed raw `[0, 255]` pixels; normalization happens inside by default.
64
- - `dino_resnet50` was converted from torch.hub `facebookresearch/dino`.
65
- - See [DINO docs]({DOCS_URL}) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
66
- - Community / upstream weights: See the KerasFormers docs for upstream conversion notes.
67
-
68
- ## Special Thanks
69
-
70
- A huge thank you to the Facebook AI Research DINO authors for creating and releasing these models.
71
-
72
- License: Apache 2.0.
 
 
 
 
1
+ ---
2
+ pipeline_tag: image-feature-extraction
3
+ license: apache-2.0
4
+ library_name: kerasformers
5
+ tags:
6
+ - keras
7
+ - kerasformers
8
+ - dino
9
+ - feature-extraction
10
+ - vision
11
+ - arxiv:2104.14294
12
+ - pytorch
13
+ - jax
14
+ - tf
15
+ ---
16
+
17
+ ## ***See [our collection](https://huggingface.co/collections/kerasformers/dino-v1-v2-v3-6a6a94f8281a2f373f70e769) for all versions of DINO.***
18
+
19
+ # Run DINO with Keras 3: JAX, PyTorch, or TensorFlow
20
+
21
+ [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-DINO-blue)](https://imvision12.github.io/KerasFormers/dino/) [![Collection](https://img.shields.io/badge/HF-DINO%20collection-yellow)](https://huggingface.co/collections/kerasformers/dino-v1-v2-v3-6a6a94f8281a2f373f70e769)
22
+
23
+ # kerasformers/dino_resnet50
24
+
25
+ Paper: [Emerging Properties in Self-Supervised Vision Transformers (arXiv:2104.14294)](https://arxiv.org/abs/2104.14294) · [HF Papers](https://huggingface.co/papers/2104.14294)
26
+
27
+ DINO is self-supervised: a student and teacher match across crops of the same image with no labels. The resulting features are semantic for free. These checkpoints are backbones that return tokens / feature maps.
28
+
29
+ Pure-**Keras 3** port for [kerasformers](https://github.com/IMvision12/KerasFormers), converted from the official upstream release. One implementation runs unmodified on **TensorFlow / Torch / JAX**.
30
+
31
+ This is a **self-supervised backbone** (`DinoResNetModel`), not a task head.
32
+
33
+ ## ✨ Quick start
34
+
35
+ ```python
36
+ import os
37
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
38
+
39
+ from kerasformers.models.dino import DinoResNetModel, DinoImageProcessor
40
+
41
+ # The processor resizes + ImageNet-normalizes, so build the model with
42
+ # include_normalization=False (it would otherwise normalize a second time).
43
+ model = DinoResNetModel.from_weights(
44
+ "kerasformers/dino_resnet50", include_normalization=False
45
+ )
46
+ processor = DinoImageProcessor.from_weights("kerasformers/dino_resnet50")
47
+
48
+ pixel_values = processor("your_image.jpg")["pixel_values"]
49
+ features = model(pixel_values, training=False)
50
+ print(pixel_values.shape, features.shape)
51
+ ```
52
+
53
+ Load any DINO variant the same way with `from_weights("kerasformers/<variant>")`:
54
+
55
+ | Variant | Hub | Backbone |
56
+ |---|---|---|
57
+ | `dino_vits16` | [`kerasformers/dino_vits16`](https://huggingface.co/kerasformers/dino_vits16) | ViT-S/16 |
58
+ | `dino_vits8` | [`kerasformers/dino_vits8`](https://huggingface.co/kerasformers/dino_vits8) | ViT-S/8 |
59
+ | `dino_vitb16` | [`kerasformers/dino_vitb16`](https://huggingface.co/kerasformers/dino_vitb16) | ViT-B/16 |
60
+ | `dino_vitb8` | [`kerasformers/dino_vitb8`](https://huggingface.co/kerasformers/dino_vitb8) | ViT-B/8 |
61
+ | `dino_resnet50` | [`kerasformers/dino_resnet50`](https://huggingface.co/kerasformers/dino_resnet50) | ResNet-50 |
62
+
63
+ ## Tips
64
+
65
+ - Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
66
+ - The processor normalizes; pair it with `include_normalization=False`. To skip it, feed raw `[0, 255]` pixels and keep the default `include_normalization=True`.
67
+ - `dino_resnet50` was converted from torch.hub `facebookresearch/dino`.
68
+ - See [DINO docs](https://imvision12.github.io/KerasFormers/dino/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
69
+ - Community / upstream weights: See the KerasFormers docs for upstream conversion notes.
70
+
71
+ ## Special Thanks
72
+
73
+ A huge thank you to the Facebook AI Research DINO authors for creating and releasing these models.
74
+
75
+ License: Apache 2.0.
kf_preprocessor.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "kerasformers",
3
+ "kerasformers_version": "1.2.1",
4
+ "preprocessor_module": "kerasformers.models.dino",
5
+ "preprocessor_class": "DinoImageProcessor",
6
+ "variant": "dino_resnet50",
7
+ "image_resolution": 224,
8
+ "model_type": "dino_resnet",
9
+ "resize_size": 256,
10
+ "mean": [
11
+ 0.48500001430511475,
12
+ 0.4560000002384186,
13
+ 0.4059999883174896
14
+ ],
15
+ "std": [
16
+ 0.2290000021457672,
17
+ 0.2240000069141388,
18
+ 0.22499999403953552
19
+ ],
20
+ "do_normalize": true,
21
+ "do_resize": true,
22
+ "data_format": "channels_last"
23
+ }