How to use from the
Use from the
Keras library
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"

import keras

model = keras.saving.load_model("hf://zeromodels/pvt-v2-b0")

See our collection for all PVT and PVTv2 versions.

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

GitHub Docs Collection

zeromodels/pvt-v2-b0

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

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

Pure-Keras 3 conversion of OpenGVLab/pvt_v2_b0 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
from zeromodels.models.pvt_v2 import PvtV2ImageClassify, PvtV2Model, PvtV2ImageProcessor

model = PvtV2ImageClassify.from_weights("zeromodels/pvt-v2-b0")
processor = PvtV2ImageProcessor.from_weights("zeromodels/pvt-v2-b0")

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-b0", 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
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_b0").

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-b0

Finetuned
(2)
this model

Collection including zeromodels/pvt-v2-b0

Paper for zeromodels/pvt-v2-b0