Update README.md
Browse files
README.md
CHANGED
@@ -33,17 +33,17 @@ The species list is derived from data available at <https://www.israbirding.com/
|
|
33 |
import birder
|
34 |
from birder.inference.classification import infer_image
|
35 |
|
36 |
-
(net,
|
37 |
|
38 |
# Get the image size the model was trained on
|
39 |
-
size = birder.get_size_from_signature(signature)
|
40 |
|
41 |
# Create an inference transform
|
42 |
-
transform = birder.classification_transform(size, rgb_stats)
|
43 |
|
44 |
image = "path/to/image.jpeg" # or a PIL image, must be loaded in RGB format
|
45 |
(out, _) = infer_image(net, image, transform)
|
46 |
-
# out is a NumPy array with shape of (1,
|
47 |
```
|
48 |
|
49 |
### Image Embeddings
|
@@ -52,17 +52,17 @@ image = "path/to/image.jpeg" # or a PIL image, must be loaded in RGB format
|
|
52 |
import birder
|
53 |
from birder.inference.classification import infer_image
|
54 |
|
55 |
-
(net,
|
56 |
|
57 |
# Get the image size the model was trained on
|
58 |
-
size = birder.get_size_from_signature(signature)
|
59 |
|
60 |
# Create an inference transform
|
61 |
-
transform = birder.classification_transform(size, rgb_stats)
|
62 |
|
63 |
image = "path/to/image.jpeg" # or a PIL image
|
64 |
(out, embedding) = infer_image(net, image, transform, return_embedding=True)
|
65 |
-
# embedding is a NumPy array with shape of (1,
|
66 |
```
|
67 |
|
68 |
### Detection Feature Map
|
@@ -71,23 +71,23 @@ image = "path/to/image.jpeg" # or a PIL image
|
|
71 |
from PIL import Image
|
72 |
import birder
|
73 |
|
74 |
-
(net,
|
75 |
|
76 |
# Get the image size the model was trained on
|
77 |
-
size = birder.get_size_from_signature(signature)
|
78 |
|
79 |
# Create an inference transform
|
80 |
-
transform = birder.classification_transform(size, rgb_stats)
|
81 |
|
82 |
image = Image.open("path/to/image.jpeg")
|
83 |
features = net.detection_features(transform(image).unsqueeze(0))
|
84 |
# features is a dict (stage name -> torch.Tensor)
|
85 |
print([(k, v.size()) for k, v in features.items()])
|
86 |
# Output example:
|
87 |
-
# [('stage1', torch.Size([1, 96,
|
88 |
-
# ('stage2', torch.Size([1, 192,
|
89 |
-
# ('stage3', torch.Size([1, 384,
|
90 |
-
# ('stage4', torch.Size([1, 768,
|
91 |
```
|
92 |
|
93 |
## Citation
|
|
|
33 |
import birder
|
34 |
from birder.inference.classification import infer_image
|
35 |
|
36 |
+
(net, model_info) = birder.load_pretrained_model("convnext_v2_tiny_intermediate-il-common", inference=True)
|
37 |
|
38 |
# Get the image size the model was trained on
|
39 |
+
size = birder.get_size_from_signature(model_info.signature)
|
40 |
|
41 |
# Create an inference transform
|
42 |
+
transform = birder.classification_transform(size, model_info.rgb_stats)
|
43 |
|
44 |
image = "path/to/image.jpeg" # or a PIL image, must be loaded in RGB format
|
45 |
(out, _) = infer_image(net, image, transform)
|
46 |
+
# out is a NumPy array with shape of (1, 371), representing class probabilities.
|
47 |
```
|
48 |
|
49 |
### Image Embeddings
|
|
|
52 |
import birder
|
53 |
from birder.inference.classification import infer_image
|
54 |
|
55 |
+
(net, model_info) = birder.load_pretrained_model("convnext_v2_tiny_intermediate-il-common", inference=True)
|
56 |
|
57 |
# Get the image size the model was trained on
|
58 |
+
size = birder.get_size_from_signature(model_info.signature)
|
59 |
|
60 |
# Create an inference transform
|
61 |
+
transform = birder.classification_transform(size, model_info.rgb_stats)
|
62 |
|
63 |
image = "path/to/image.jpeg" # or a PIL image
|
64 |
(out, embedding) = infer_image(net, image, transform, return_embedding=True)
|
65 |
+
# embedding is a NumPy array with shape of (1, 768)
|
66 |
```
|
67 |
|
68 |
### Detection Feature Map
|
|
|
71 |
from PIL import Image
|
72 |
import birder
|
73 |
|
74 |
+
(net, model_info) = birder.load_pretrained_model("convnext_v2_tiny_intermediate-il-common", inference=True)
|
75 |
|
76 |
# Get the image size the model was trained on
|
77 |
+
size = birder.get_size_from_signature(model_info.signature)
|
78 |
|
79 |
# Create an inference transform
|
80 |
+
transform = birder.classification_transform(size, model_info.rgb_stats)
|
81 |
|
82 |
image = Image.open("path/to/image.jpeg")
|
83 |
features = net.detection_features(transform(image).unsqueeze(0))
|
84 |
# features is a dict (stage name -> torch.Tensor)
|
85 |
print([(k, v.size()) for k, v in features.items()])
|
86 |
# Output example:
|
87 |
+
# [('stage1', torch.Size([1, 96, 64, 64])),
|
88 |
+
# ('stage2', torch.Size([1, 192, 32, 32])),
|
89 |
+
# ('stage3', torch.Size([1, 384, 16, 16])),
|
90 |
+
# ('stage4', torch.Size([1, 768, 8, 8]))]
|
91 |
```
|
92 |
|
93 |
## Citation
|