pvt-v2-b2-linear / README.md
IMvision12's picture
Upload README.md with huggingface_hub
539de9d verified
|
Raw
History Blame Contribute Delete
4.42 kB
metadata
pipeline_tag: image-classification
license: apache-2.0
base_model: OpenGVLab/pvt_v2_b2_linear
library_name: zeromodels
tags:
  - keras
  - zeromodels
  - image-classification
  - pvt-v2
  - backbone
  - arxiv:2106.13797
  - pytorch
  - jax
  - tf

See our collection for all PVT and PVTv2 versions.

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

GitHub Docs Collection

zeromodels/pvt-v2-b2-linear

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

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

Pure-Keras 3 conversion of OpenGVLab/pvt_v2_b2_linear 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-b2-linear")
processor = PvtV2ImageProcessor.from_weights("zeromodels/pvt-v2-b2-linear")

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-linear", 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_b2_linear").

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).