See our collection for all PVT and PVTv2 versions.

Run PVTv2 with Keras 3: JAX, PyTorch, or TensorFlow

GitHub Docs Collection

zeromodels/pvt-v2-b5

Paper: PVTv2: Improved Baselines with Pyramid Vision Transformer (arXiv:2106.13797) · HF Papers

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: ~82.0M
  • ImageNet-1k top-1: 83.8%

For more details on the model, see the upstream model card.

Pure-Keras 3 conversion of OpenGVLab/pvt_v2_b5 for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.

This is an image-classification / backbone checkpoint (PvtV2ImageClassify / PvtV2Model).

✨ Quick start

import os
os.environ["KERAS_BACKEND"] = "torch"  # or "jax" / "tensorflow"

from PIL import Image
import numpy as np
from zeromodels.models.pvt_v2 import PvtV2ImageClassify, PvtV2Model

model = PvtV2ImageClassify.from_weights("zeromodels/pvt-v2-b5")
backbone = PvtV2Model.from_weights("zeromodels/pvt-v2-b5", 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 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
pvt-v2-b1 78.7% zeromodels/pvt-v2-b1
pvt-v2-b2 82.0% zeromodels/pvt-v2-b2
pvt-v2-b2-linear 82.1% zeromodels/pvt-v2-b2-linear
pvt-v2-b3 83.1% zeromodels/pvt-v2-b3
pvt-v2-b4 83.6% zeromodels/pvt-v2-b4
pvt-v2-b5 83.8% 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 and Loading Weights.
  • Upstream checkpoints load directly: PvtV2ImageClassify.from_weights("hf:OpenGVLab/pvt_v2_b5").

Special Thanks

A huge thank you to the PVT authors (whai362/PVT) and the Hugging Face community for creating and releasing these models.

License: see the YAML license above (matches the upstream checkpoint).

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for zeromodels/pvt-v2-b5

Finetuned
(1)
this model

Collection including zeromodels/pvt-v2-b5

Paper for zeromodels/pvt-v2-b5