Instructions to use zeromodels/pvt-medium-224 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/pvt-medium-224 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/pvt-medium-224") - Notebooks
- Google Colab
- Kaggle
File size: 4,081 Bytes
2334c00 9c412ea 2334c00 9c412ea 2334c00 9c412ea 2334c00 9c412ea 2334c00 | 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 83 84 85 86 | ---
pipeline_tag: image-classification
license: apache-2.0
base_model: Zetatech/pvt-medium-224
library_name: zeromodels
tags:
- keras
- zeromodels
- image-classification
- pvt
- backbone
- arxiv:2102.12122
- pytorch
- jax
- tf
---
## ***See [our collection](https://huggingface.co/collections/zeromodels/pvt-and-pvtv2-6a90e9dd0a2b03a982d0b876) for all PVT and PVTv2 versions.***
# Run PVT with Keras 3: JAX, PyTorch, or TensorFlow
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/pvt/) [](https://huggingface.co/collections/zeromodels/pvt-and-pvtv2-6a90e9dd0a2b03a982d0b876)
# zeromodels/pvt-medium-224
Paper: [Pyramid Vision Transformer: A Versatile Backbone for Dense Prediction without Convolutions (arXiv:2102.12122)](https://arxiv.org/abs/2102.12122) · [HF Papers](https://huggingface.co/papers/2102.12122)
PVT is a hierarchical vision transformer: four pyramid stages with spatial-reduction attention over non-overlapping patches and learned position embeddings. Use `PvtImageClassify` for logits or `PvtModel` for tokens / per-stage features via `as_backbone=True`.
- Parameters: ~44.2M
- ImageNet-1k top-1: **81.2%**
For more details on the model, see the upstream [model card](https://huggingface.co/Zetatech/pvt-medium-224).
Pure-**Keras 3** conversion of [`Zetatech/pvt-medium-224`](https://huggingface.co/Zetatech/pvt-medium-224) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
This is an **image-classification / backbone** checkpoint (`PvtImageClassify` / `PvtModel`).
## ✨ Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from zeromodels.models.pvt import PvtImageClassify, PvtModel, PvtImageProcessor
model = PvtImageClassify.from_weights("zeromodels/pvt-medium-224")
processor = PvtImageProcessor.from_weights("zeromodels/pvt-medium-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 = PvtModel.from_weights("zeromodels/pvt-medium-224", as_backbone=True)
features = backbone(pixels, training=False)
```
Normalization is baked into the graph, so pass raw `[0, 255]` pixels. Load any PVT
variant the same way with `from_weights("zeromodels/<variant>")`:
| Variant | ImageNet-1k top-1 | Hub |
|---|---|---|
| `pvt-tiny-224` | 75.1% | [`zeromodels/pvt-tiny-224`](https://huggingface.co/zeromodels/pvt-tiny-224) |
| `pvt-small-224` | 79.8% | [`zeromodels/pvt-small-224`](https://huggingface.co/zeromodels/pvt-small-224) |
| `pvt-medium-224` | 81.2% | [`zeromodels/pvt-medium-224`](https://huggingface.co/zeromodels/pvt-medium-224) |
| `pvt-large-224` | 81.7% | [`zeromodels/pvt-large-224`](https://huggingface.co/zeromodels/pvt-large-224) |
## Tips
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
- `PvtImageClassify` returns class logits; `PvtModel` returns features (`as_backbone=True` for the four-stage pyramid).
- Both the model and its data format (`channels_last` / `channels_first`) are supported and bit-exact.
- See the [docs](https://imvision12.github.io/ZeroModels/pvt/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
- Upstream checkpoints load directly: `PvtImageClassify.from_weights("hf:Zetatech/pvt-medium-224")`.
## Special Thanks
A huge thank you to the PVT authors ([whai362/PVT](https://github.com/whai362/PVT)) and the Hugging Face
community for creating and releasing these models.
License: see the YAML `license` above (matches the upstream checkpoint).
|