Instructions to use zeromodels/pvt-v2-b5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/pvt-v2-b5 with Keras:
# 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-b5") - Notebooks
- Google Colab
- Kaggle
Add zeromodels PVT weights + zm_config + model card
Browse files- README.md +85 -0
- model.weights.h5 +3 -0
- zm_config.json +45 -0
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: image-classification
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: OpenGVLab/pvt_v2_b5
|
| 5 |
+
library_name: zeromodels
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
+
- image-classification
|
| 10 |
+
- pvt-v2
|
| 11 |
+
- backbone
|
| 12 |
+
- arxiv:2106.13797
|
| 13 |
+
- pytorch
|
| 14 |
+
- jax
|
| 15 |
+
- tf
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/pvt-and-pvtv2-6a90e9dd0a2b03a982d0b876) for all PVT and PVTv2 versions.***
|
| 19 |
+
|
| 20 |
+
# Run PVTv2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
+
|
| 22 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/pvt_v2/) [](https://huggingface.co/collections/zeromodels/pvt-and-pvtv2-6a90e9dd0a2b03a982d0b876)
|
| 23 |
+
|
| 24 |
+
# zeromodels/pvt-v2-b5
|
| 25 |
+
|
| 26 |
+
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)
|
| 27 |
+
|
| 28 |
+
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`.
|
| 29 |
+
|
| 30 |
+
- Parameters: ~82.0M
|
| 31 |
+
- ImageNet-1k top-1: **83.8%**
|
| 32 |
+
|
| 33 |
+
For more details on the model, see the upstream [model card](https://huggingface.co/OpenGVLab/pvt_v2_b5).
|
| 34 |
+
|
| 35 |
+
Pure-**Keras 3** conversion of [`OpenGVLab/pvt_v2_b5`](https://huggingface.co/OpenGVLab/pvt_v2_b5) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 36 |
+
|
| 37 |
+
This is an **image-classification / backbone** checkpoint (`PvtV2ImageClassify` / `PvtV2Model`).
|
| 38 |
+
|
| 39 |
+
## ✨ Quick start
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import os
|
| 43 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 44 |
+
|
| 45 |
+
from PIL import Image
|
| 46 |
+
import numpy as np
|
| 47 |
+
from zeromodels.models.pvt_v2 import PvtV2ImageClassify, PvtV2Model
|
| 48 |
+
|
| 49 |
+
model = PvtV2ImageClassify.from_weights("zeromodels/pvt-v2-b5")
|
| 50 |
+
backbone = PvtV2Model.from_weights("zeromodels/pvt-v2-b5", as_backbone=True)
|
| 51 |
+
|
| 52 |
+
image = Image.open("your_image.jpg").convert("RGB").resize((224, 224))
|
| 53 |
+
x = np.asarray(image, dtype="float32")[None] # (1, H, W, 3), raw [0, 255]
|
| 54 |
+
print(model(x).shape) # (1, num_classes)
|
| 55 |
+
feats = backbone(x)
|
| 56 |
+
print(len(feats), [tuple(f.shape) for f in feats]) # 4-stage feature pyramid
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Normalization is baked into the graph, so pass raw `[0, 255]` pixels. Load any PVTv2
|
| 60 |
+
variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 61 |
+
|
| 62 |
+
| Variant | ImageNet-1k top-1 | Hub |
|
| 63 |
+
|---|---|---|
|
| 64 |
+
| `pvt-v2-b0` | 70.5% | [`zeromodels/pvt-v2-b0`](https://huggingface.co/zeromodels/pvt-v2-b0) |
|
| 65 |
+
| `pvt-v2-b1` | 78.7% | [`zeromodels/pvt-v2-b1`](https://huggingface.co/zeromodels/pvt-v2-b1) |
|
| 66 |
+
| `pvt-v2-b2` | 82.0% | [`zeromodels/pvt-v2-b2`](https://huggingface.co/zeromodels/pvt-v2-b2) |
|
| 67 |
+
| `pvt-v2-b2-linear` | 82.1% | [`zeromodels/pvt-v2-b2-linear`](https://huggingface.co/zeromodels/pvt-v2-b2-linear) |
|
| 68 |
+
| `pvt-v2-b3` | 83.1% | [`zeromodels/pvt-v2-b3`](https://huggingface.co/zeromodels/pvt-v2-b3) |
|
| 69 |
+
| `pvt-v2-b4` | 83.6% | [`zeromodels/pvt-v2-b4`](https://huggingface.co/zeromodels/pvt-v2-b4) |
|
| 70 |
+
| `pvt-v2-b5` | 83.8% | [`zeromodels/pvt-v2-b5`](https://huggingface.co/zeromodels/pvt-v2-b5) |
|
| 71 |
+
|
| 72 |
+
## Tips
|
| 73 |
+
|
| 74 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 75 |
+
- `PvtV2ImageClassify` returns class logits; `PvtV2Model` returns features (`as_backbone=True` for the four-stage pyramid).
|
| 76 |
+
- Both the model and its data format (`channels_last` / `channels_first`) are supported and bit-exact.
|
| 77 |
+
- See the [docs](https://imvision12.github.io/ZeroModels/pvt_v2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 78 |
+
- Upstream checkpoints load directly: `PvtV2ImageClassify.from_weights("hf:OpenGVLab/pvt_v2_b5")`.
|
| 79 |
+
|
| 80 |
+
## Special Thanks
|
| 81 |
+
|
| 82 |
+
A huge thank you to the PVT authors ([whai362/PVT](https://github.com/whai362/PVT)) and the Hugging Face
|
| 83 |
+
community for creating and releasing these models.
|
| 84 |
+
|
| 85 |
+
License: see the YAML `license` above (matches the upstream checkpoint).
|
model.weights.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9036862130b567fd1709604d9591cc6d6b59af5dcba66de87b0b4054b473eb84
|
| 3 |
+
size 330511008
|
zm_config.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.6",
|
| 4 |
+
"model_module": "zeromodels.models.pvt_v2",
|
| 5 |
+
"model_class": "PvtV2ImageClassify",
|
| 6 |
+
"variant": "pvt-v2-b5",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"model_type": "pvt_v2",
|
| 10 |
+
"vision_config": {
|
| 11 |
+
"hidden_sizes": [
|
| 12 |
+
64,
|
| 13 |
+
128,
|
| 14 |
+
320,
|
| 15 |
+
512
|
| 16 |
+
],
|
| 17 |
+
"depths": [
|
| 18 |
+
3,
|
| 19 |
+
6,
|
| 20 |
+
40,
|
| 21 |
+
3
|
| 22 |
+
],
|
| 23 |
+
"num_attention_heads": [
|
| 24 |
+
1,
|
| 25 |
+
2,
|
| 26 |
+
5,
|
| 27 |
+
8
|
| 28 |
+
],
|
| 29 |
+
"sr_ratios": [
|
| 30 |
+
8,
|
| 31 |
+
4,
|
| 32 |
+
2,
|
| 33 |
+
1
|
| 34 |
+
],
|
| 35 |
+
"mlp_ratios": [
|
| 36 |
+
4,
|
| 37 |
+
4,
|
| 38 |
+
4,
|
| 39 |
+
4
|
| 40 |
+
],
|
| 41 |
+
"linear_attention": false,
|
| 42 |
+
"image_size": 224,
|
| 43 |
+
"num_classes": 1000
|
| 44 |
+
}
|
| 45 |
+
}
|