Instructions to use zeromodels/beit-base-patch16-224 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/beit-base-patch16-224 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/beit-base-patch16-224") - Keras
How to use zeromodels/beit-base-patch16-224 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/beit-base-patch16-224") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from zeromodels/beit-base-patch16-224: direct link, hf CLI and curl.
- Browser
- Download file 4.79 kB
-
https://huggingface.co/zeromodels/beit-base-patch16-224/resolve/main/README.md
- Command line
-
hf download hf://zeromodels/beit-base-patch16-224/README.md
-
curl -L -o README.md https://huggingface.co/zeromodels/beit-base-patch16-224/resolve/main/README.md
4.79 kB
| pipeline_tag: image-classification | |
| license: apache-2.0 | |
| base_model: microsoft/beit-base-patch16-224 | |
| library_name: zeromodels | |
| tags: | |
| - keras | |
| - zeromodels | |
| - beit | |
| - image-classification | |
| - vit | |
| - backbone | |
| - arxiv:2106.08254 | |
| - pytorch | |
| - jax | |
| - tf | |
| ## ***See [our collection](https://huggingface.co/collections/zeromodels/beit-6a9352067192fd9fcfcfe6f1) for all versions of BEiT.*** | |
| # Run BEiT with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/beit/) [](https://huggingface.co/collections/zeromodels/beit-6a9352067192fd9fcfcfe6f1) | |
| # zeromodels/beit-base-patch16-224 | |
| 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) | |
| 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. Base backbone pretrained on ImageNet-22k and fine-tuned on ImageNet-1k (1000 classes). | |
| For more details on the model, please go to Microsoft's original [model card](https://huggingface.co/microsoft/beit-base-patch16-224). | |
| Pure-**Keras 3** conversion of [`microsoft/beit-base-patch16-224`](https://huggingface.co/microsoft/beit-base-patch16-224) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**. | |
| This is a **image classification** checkpoint (`BeitImageClassify`). | |
| ## ✨ Quick start | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from PIL import Image | |
| from zeromodels.models.beit import BeitImageClassify, BeitModel, BeitImageProcessor | |
| model = BeitImageClassify.from_weights("zeromodels/beit-base-patch16-224") | |
| processor = BeitImageProcessor.from_weights("zeromodels/beit-base-patch16-224") | |
| image = Image.open("your_image.jpg").convert("RGB") | |
| pixels = processor(image) # resize + normalize (normalization lives in the processor) | |
| logits = model(pixels, training=False) | |
| print(logits.shape) # (1, num_classes) | |
| # Feature extraction: the backbone without the classifier head | |
| backbone = BeitModel.from_weights("zeromodels/beit-base-patch16-224", as_backbone=True) | |
| features = backbone(pixels, training=False) | |
| ``` | |
| Load any BEiT variant the same way with `from_weights("zeromodels/<variant>")`: | |
| | Variant | Hub | Task | | |
| |---|---|---| | |
| | `beit-base-patch16-224` | [`zeromodels/beit-base-patch16-224`](https://huggingface.co/zeromodels/beit-base-patch16-224) | image classification | | |
| | `beit-large-patch16-224` | [`zeromodels/beit-large-patch16-224`](https://huggingface.co/zeromodels/beit-large-patch16-224) | image classification | | |
| | `beit-large-patch16-512` | [`zeromodels/beit-large-patch16-512`](https://huggingface.co/zeromodels/beit-large-patch16-512) | image classification | | |
| | `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 | | |
| | `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 | | |
| | `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 | | |
| | `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 | | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / zeromodels. | |
| - Normalization (0.5/0.5) is baked into the model, so pass raw `[0, 255]` pixels. | |
| - 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). | |
| - `BeitModel.from_weights(..., as_backbone=True)` returns the per-block token sequences for feature extraction. | |
| - See [BEiT docs](https://imvision12.github.io/ZeroModels/beit/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/). | |
| - Community / upstream safetensors still work via the `hf:` prefix, e.g. `BeitImageClassify.from_weights("hf:microsoft/beit-base-patch16-224")`. | |
| ## Special Thanks | |
| A huge thank you to the Microsoft Research BEiT authors for creating and releasing these models. | |
| License: Apache 2.0. | |