IMvision12 commited on
Commit
41d1359
·
verified ·
1 Parent(s): b71acfa

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +11 -8
README.md CHANGED
@@ -40,20 +40,23 @@ This is an **image-classification / backbone** checkpoint (`PvtV2ImageClassify`
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-b3")
50
- backbone = PvtV2Model.from_weights("zeromodels/pvt-v2-b3", 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
 
40
 
41
  ```python
42
  import os
43
+
44
  os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
45
 
46
  from PIL import Image
47
+ from zeromodels.models.pvt_v2 import PvtV2ImageClassify, PvtV2Model, PvtV2ImageProcessor
 
48
 
49
  model = PvtV2ImageClassify.from_weights("zeromodels/pvt-v2-b3")
50
+ processor = PvtV2ImageProcessor.from_weights("zeromodels/pvt-v2-b3")
51
 
52
+ image = Image.open("your_image.jpg").convert("RGB")
53
+ pixels = processor(image) # resize + normalize (normalization lives in the processor)
54
+ logits = model(pixels, training=False)
55
+ print(logits.shape) # (1, num_classes)
56
+
57
+ # Feature extraction: the backbone without the classifier head
58
+ backbone = PvtV2Model.from_weights("zeromodels/pvt-v2-b3", as_backbone=True)
59
+ features = backbone(pixels, training=False)
60
  ```
61
 
62
  Normalization is baked into the graph, so pass raw `[0, 255]` pixels. Load any PVTv2