Instructions to use addy88/perceiver_image_classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use addy88/perceiver_image_classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="addy88/perceiver_image_classifier") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoTokenizer, AutoModelForImageClassification tokenizer = AutoTokenizer.from_pretrained("addy88/perceiver_image_classifier") model = AutoModelForImageClassification.from_pretrained("addy88/perceiver_image_classifier") - Notebooks
- Google Colab
- Kaggle
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### How to use
|
| 2 |
+
Here is how to use this model in PyTorch:
|
| 3 |
+
```python
|
| 4 |
+
from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationLearned
|
| 5 |
+
import requests
|
| 6 |
+
from PIL import Image
|
| 7 |
+
feature_extractor = PerceiverFeatureExtractor.from_pretrained("addy88/perceiver_image_classifier")
|
| 8 |
+
model = PerceiverForImageClassificationLearned.from_pretrained("addy88/perceiver_image_classifier")
|
| 9 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 10 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 11 |
+
# prepare input
|
| 12 |
+
encoding = feature_extractor(image, return_tensors="pt")
|
| 13 |
+
inputs = encoding.pixel_values
|
| 14 |
+
# forward pass
|
| 15 |
+
outputs = model(inputs)
|
| 16 |
+
logits = outputs.logits
|
| 17 |
+
print("Predicted class:", model.config.id2label[logits.argmax(-1).item()])
|
| 18 |
+
>>> should print Predicted class: tabby, tabby cat
|
| 19 |
+
```
|