pvt-v2-b2 / README.md
IMvision12's picture
Upload README.md with huggingface_hub
56f38c8 verified
|
Raw
History Blame Contribute Delete
4.36 kB
---
pipeline_tag: image-classification
license: apache-2.0
base_model: OpenGVLab/pvt_v2_b2
library_name: zeromodels
tags:
- keras
- zeromodels
- image-classification
- pvt-v2
- backbone
- arxiv:2106.13797
- pytorch
- jax
- tf
---
## ***See [our collection](https://huggingface.co/collections/zeromodels/pvt-and-pvtv2-6a90e9dd0a2b03a982d0b876) for all PVT and PVTv2 versions.***
# Run PVTv2 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-PVTv2-blue)](https://imvision12.github.io/ZeroModels/pvt_v2/) [![Collection](https://img.shields.io/badge/HF-PVTv2%20collection-yellow)](https://huggingface.co/collections/zeromodels/pvt-and-pvtv2-6a90e9dd0a2b03a982d0b876)
# zeromodels/pvt-v2-b2
Paper: [PVTv2: Improved Baselines with Pyramid Vision Transformer (arXiv:2106.13797)](https://arxiv.org/abs/2106.13797) · [HF Papers](https://huggingface.co/papers/2106.13797)
PVTv2 improves PVT with overlapping patch embeddings, a convolutional feed-forward network, and no position embeddings (so any input resolution works), plus an optional linear-attention variant. Use `PvtV2ImageClassify` for logits or `PvtV2Model` for tokens / per-stage features via `as_backbone=True`.
- Parameters: ~25.4M
- ImageNet-1k top-1: **82.0%**
For more details on the model, see the upstream [model card](https://huggingface.co/OpenGVLab/pvt_v2_b2).
Pure-**Keras 3** conversion of [`OpenGVLab/pvt_v2_b2`](https://huggingface.co/OpenGVLab/pvt_v2_b2) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
This is an **image-classification / backbone** checkpoint (`PvtV2ImageClassify` / `PvtV2Model`).
## ✨ Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from zeromodels.models.pvt_v2 import PvtV2ImageClassify, PvtV2Model, PvtV2ImageProcessor
model = PvtV2ImageClassify.from_weights("zeromodels/pvt-v2-b2")
processor = PvtV2ImageProcessor.from_weights("zeromodels/pvt-v2-b2")
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 = PvtV2Model.from_weights("zeromodels/pvt-v2-b2", as_backbone=True)
features = backbone(pixels, training=False)
```
Normalization is baked into the graph, so pass raw `[0, 255]` pixels. Load any PVTv2
variant the same way with `from_weights("zeromodels/<variant>")`:
| Variant | ImageNet-1k top-1 | Hub |
|---|---|---|
| `pvt-v2-b0` | 70.5% | [`zeromodels/pvt-v2-b0`](https://huggingface.co/zeromodels/pvt-v2-b0) |
| `pvt-v2-b1` | 78.7% | [`zeromodels/pvt-v2-b1`](https://huggingface.co/zeromodels/pvt-v2-b1) |
| `pvt-v2-b2` | 82.0% | [`zeromodels/pvt-v2-b2`](https://huggingface.co/zeromodels/pvt-v2-b2) |
| `pvt-v2-b2-linear` | 82.1% | [`zeromodels/pvt-v2-b2-linear`](https://huggingface.co/zeromodels/pvt-v2-b2-linear) |
| `pvt-v2-b3` | 83.1% | [`zeromodels/pvt-v2-b3`](https://huggingface.co/zeromodels/pvt-v2-b3) |
| `pvt-v2-b4` | 83.6% | [`zeromodels/pvt-v2-b4`](https://huggingface.co/zeromodels/pvt-v2-b4) |
| `pvt-v2-b5` | 83.8% | [`zeromodels/pvt-v2-b5`](https://huggingface.co/zeromodels/pvt-v2-b5) |
## Tips
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
- `PvtV2ImageClassify` returns class logits; `PvtV2Model` 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_v2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
- Upstream checkpoints load directly: `PvtV2ImageClassify.from_weights("hf:OpenGVLab/pvt_v2_b2")`.
## 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).