Instructions to use zeromodels/levit-192 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/levit-192 with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/levit-192") - Notebooks
- Google Colab
- Kaggle
See our collection for all versions of LeViT.
Run LeViT with Keras 3: JAX, PyTorch, or TensorFlow
zeromodels/levit-192
Paper: LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference (arXiv:2104.01136) · HF Papers
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.
Pure-Keras 3 conversion of facebook/levit-192 for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.
✨ Quick start
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 |
levit-128 |
zeromodels/levit-128 |
levit-192 |
zeromodels/levit-192 |
levit-256 |
zeromodels/levit-256 |
levit-384 |
zeromodels/levit-384 |
Tips
- Set
KERAS_BACKENDbefore 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. LevitImageClassifyaverages the two distillation heads internally;LevitModel.from_weights(...)gives the backbone (the final token sequence, no head).- See Classification backbones and 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.
Model tree for zeromodels/levit-192
Base model
facebook/levit-192