--- 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 [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-black?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-PVT-blue)](https://imvision12.github.io/ZeroModels/pvt/) [![Collection](https://img.shields.io/badge/HF-PVT%20collection-yellow)](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 import numpy as np from zeromodels.models.pvt import PvtImageClassify, PvtModel model = PvtImageClassify.from_weights("zeromodels/pvt-medium-224") backbone = PvtModel.from_weights("zeromodels/pvt-medium-224", as_backbone=True) image = Image.open("your_image.jpg").convert("RGB").resize((224, 224)) x = np.asarray(image, dtype="float32")[None] # (1, H, W, 3), raw [0, 255] print(model(x).shape) # (1, num_classes) feats = backbone(x) print(len(feats), [tuple(f.shape) for f in feats]) # 4-stage feature pyramid ``` Normalization is baked into the graph, so pass raw `[0, 255]` pixels. Load any PVT variant the same way with `from_weights("zeromodels/")`: | 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).