IMvision12 commited on
Commit
2c3f465
·
verified ·
1 Parent(s): c6e1122

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +81 -0
  2. model.weights.h5 +3 -0
  3. zm_config.json +34 -0
README.md ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: image-classification
3
+ license: apache-2.0
4
+ base_model: microsoft/beit-large-patch16-512
5
+ library_name: zeromodels
6
+ tags:
7
+ - keras
8
+ - zeromodels
9
+ - beit
10
+ - image-classification
11
+ - vit
12
+ - backbone
13
+ - arxiv:2106.08254
14
+ - pytorch
15
+ - jax
16
+ - tf
17
+ ---
18
+
19
+ ## ***See [our collection](https://huggingface.co/collections/zeromodels/beit-6a9352067192fd9fcfcfe6f1) for all versions of BEiT.***
20
+
21
+ # Run BEiT with Keras 3: JAX, PyTorch, or TensorFlow
22
+
23
+ [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-black?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-BEiT-blue)](https://imvision12.github.io/ZeroModels/beit/) [![Collection](https://img.shields.io/badge/HF-BEiT%20collection-yellow)](https://huggingface.co/collections/zeromodels/beit-6a9352067192fd9fcfcfe6f1)
24
+
25
+ # zeromodels/beit-large-patch16-512
26
+
27
+ Paper: [BEiT: BERT Pre-Training of Image Transformers (arXiv:2106.08254)](https://arxiv.org/abs/2106.08254) · [HF Papers](https://huggingface.co/papers/2106.08254)
28
+
29
+ BEiT is a ViT-family vision transformer with a per-layer relative position bias, a learnable layer scale on each residual branch, and mean pooling of the patch tokens. Large backbone fine-tuned on ImageNet-1k at 512x512 (1000 classes).
30
+
31
+ For more details on the model, please go to Microsoft's original [model card](https://huggingface.co/microsoft/beit-large-patch16-512).
32
+
33
+ Pure-**Keras 3** conversion of [`microsoft/beit-large-patch16-512`](https://huggingface.co/microsoft/beit-large-patch16-512) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
34
+
35
+ This is a **image classification** checkpoint (`BeitImageClassify`).
36
+
37
+ ## ✨ Quick start
38
+
39
+ ```python
40
+ import os
41
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
42
+
43
+ import keras
44
+ import numpy as np
45
+ from PIL import Image
46
+ from zeromodels.models.beit import BeitImageClassify
47
+
48
+ model = BeitImageClassify.from_weights("zeromodels/beit-large-patch16-512")
49
+
50
+ image = Image.open("your_image.jpg").convert("RGB").resize((512, 512))
51
+ pixels = np.asarray(image, "float32")[None] # raw [0, 255]; normalization is inside the model
52
+ logits = model(pixels, training=False)
53
+ print("top-1 class id:", int(keras.ops.convert_to_numpy(logits)[0].argmax()))
54
+ ```
55
+
56
+ Load any BEiT variant the same way with `from_weights("zeromodels/<variant>")`:
57
+
58
+ | Variant | Hub | Task |
59
+ |---|---|---|
60
+ | `beit-base-patch16-224` | [`zeromodels/beit-base-patch16-224`](https://huggingface.co/zeromodels/beit-base-patch16-224) | image classification |
61
+ | `beit-large-patch16-224` | [`zeromodels/beit-large-patch16-224`](https://huggingface.co/zeromodels/beit-large-patch16-224) | image classification |
62
+ | `beit-large-patch16-512` | [`zeromodels/beit-large-patch16-512`](https://huggingface.co/zeromodels/beit-large-patch16-512) | image classification |
63
+ | `beit-base-patch16-224-pt22k-ft22k` | [`zeromodels/beit-base-patch16-224-pt22k-ft22k`](https://huggingface.co/zeromodels/beit-base-patch16-224-pt22k-ft22k) | image classification |
64
+ | `beit-large-patch16-224-pt22k-ft22k` | [`zeromodels/beit-large-patch16-224-pt22k-ft22k`](https://huggingface.co/zeromodels/beit-large-patch16-224-pt22k-ft22k) | image classification |
65
+ | `beit-base-finetuned-ade-640-640` | [`zeromodels/beit-base-finetuned-ade-640-640`](https://huggingface.co/zeromodels/beit-base-finetuned-ade-640-640) | semantic segmentation |
66
+ | `beit-large-finetuned-ade-640-640` | [`zeromodels/beit-large-finetuned-ade-640-640`](https://huggingface.co/zeromodels/beit-large-finetuned-ade-640-640) | semantic segmentation |
67
+
68
+ ## Tips
69
+
70
+ - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
71
+ - Normalization (0.5/0.5) is baked into the model, so pass raw `[0, 255]` pixels.
72
+ - Classification uses `BeitImageClassify`; semantic segmentation uses `BeitSemanticSegment` and returns logits at a quarter of the input resolution (upsample the `argmax` map to the input size).
73
+ - `BeitModel.from_weights(..., as_backbone=True)` returns the per-block token sequences for feature extraction.
74
+ - See [BEiT docs](https://imvision12.github.io/ZeroModels/beit/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
75
+ - Community / upstream safetensors still work via the `hf:` prefix, e.g. `BeitImageClassify.from_weights("hf:microsoft/beit-large-patch16-512")`.
76
+
77
+ ## Special Thanks
78
+
79
+ A huge thank you to the Microsoft Research BEiT authors for creating and releasing these models.
80
+
81
+ License: Apache 2.0.
model.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fccf87cb9bbca625552b0bb3459e5a6e8b2b99207a4a4c91784a23fa58cf436
3
+ size 1223582304
zm_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "zeromodels",
3
+ "zeromodels_version": "1.2.7",
4
+ "model_module": "zeromodels.models.beit",
5
+ "model_class": "BeitImageClassify",
6
+ "variant": "beit-large-patch16-512",
7
+ "weights": "model.weights.h5",
8
+ "schema_version": 2,
9
+ "model_type": "beit",
10
+ "vision_config": {
11
+ "hidden_size": 1024,
12
+ "num_hidden_layers": 24,
13
+ "num_attention_heads": 16,
14
+ "intermediate_size": 4096,
15
+ "image_size": 512,
16
+ "patch_size": 16,
17
+ "num_channels": 3,
18
+ "layer_scale_init_value": 0.1,
19
+ "layer_norm_eps": 1e-12,
20
+ "num_classes": 1000,
21
+ "out_indices": [
22
+ 3,
23
+ 5,
24
+ 7,
25
+ 11
26
+ ],
27
+ "pool_scales": [
28
+ 1,
29
+ 2,
30
+ 3,
31
+ 6
32
+ ]
33
+ }
34
+ }