Instructions to use zeromodels/levit-192 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/levit-192 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/levit-192") - Keras
How to use zeromodels/levit-192 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/levit-192") - Notebooks
- Google Colab
- Kaggle
File size: 4,145 Bytes
e16cac3 28af9ef e16cac3 28af9ef e16cac3 28af9ef e16cac3 28af9ef e16cac3 28af9ef e16cac3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | ---
pipeline_tag: image-classification
license: apache-2.0
base_model: facebook/levit-192
library_name: zeromodels
tags:
- keras
- zeromodels
- image-classification
- vit
- backbone
- levit
- arxiv:2104.01136
- pytorch
- jax
- tf
---
## ***See [our collection](https://huggingface.co/collections/zeromodels/levit-6a937f8760837c24b7a51d25) for all versions of LeViT.***
# Run LeViT with Keras 3: JAX, PyTorch, or TensorFlow
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/classification_backbones/) [](https://huggingface.co/collections/zeromodels/levit-6a937f8760837c24b7a51d25)
# zeromodels/levit-192
Paper: [LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference (arXiv:2104.01136)](https://arxiv.org/abs/2104.01136) · [HF Papers](https://huggingface.co/papers/2104.01136)
LeViT is a hybrid convolution/transformer image classifier built for fast inference: a four-layer conv stem downsamples the image 16x, then three attention stages (each adding a learnable 2D relative-position bias) run over the tokens, with a BatchNorm fused into every linear layer and Hardswish activations. The released checkpoints are distilled - a second classification head is averaged with the first at inference. Wider LeViT (hidden sizes 192/288/384).
For more details on the model, please go to Meta's original [model card](https://huggingface.co/facebook/levit-192).
Pure-**Keras 3** conversion of [`facebook/levit-192`](https://huggingface.co/facebook/levit-192) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
## ✨ Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from zeromodels.models.levit import LevitImageClassify, LevitModel, LevitImageProcessor
model = LevitImageClassify.from_weights("zeromodels/levit-192")
processor = LevitImageProcessor.from_weights("zeromodels/levit-192")
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 = LevitModel.from_weights("zeromodels/levit-192")
features = backbone(pixels, training=False)
```
Load any LeViT variant the same way with `from_weights("zeromodels/<variant>")`:
| Variant | Hub |
|---|---|
| `levit-128S` | [`zeromodels/levit-128S`](https://huggingface.co/zeromodels/levit-128S) |
| `levit-128` | [`zeromodels/levit-128`](https://huggingface.co/zeromodels/levit-128) |
| `levit-192` | [`zeromodels/levit-192`](https://huggingface.co/zeromodels/levit-192) |
| `levit-256` | [`zeromodels/levit-256`](https://huggingface.co/zeromodels/levit-256) |
| `levit-384` | [`zeromodels/levit-384`](https://huggingface.co/zeromodels/levit-384) |
## Tips
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
- ImageNet normalization is baked into the model, so pass raw `[0, 255]` pixels.
- Preprocess by resizing the shortest edge to 256 and center-cropping 224 (shown above) to match the reference; a plain `resize((224, 224))` is close and also works.
- `LevitImageClassify` averages the two distillation heads internally; `LevitModel.from_weights(...)` gives the backbone (the final token sequence, no head).
- See [Classification backbones](https://imvision12.github.io/ZeroModels/classification_backbones/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `LevitImageClassify.from_weights("hf:facebook/levit-192")`.
## Special Thanks
A huge thank you to the Meta AI LeViT authors for creating and releasing these models.
License: Apache 2.0.
|