Instructions to use google/vit-base-patch32-384 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/vit-base-patch32-384 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="google/vit-base-patch32-384") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("google/vit-base-patch32-384") model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch32-384") - Inference
- Notebooks
- Google Colab
- Kaggle
Update README
Browse files
README.md
CHANGED
|
@@ -41,11 +41,12 @@ url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
|
| 41 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 42 |
feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch32-384')
|
| 43 |
model = ViTForImageClassification.from_pretrained('google/vit-base-patch32-384')
|
| 44 |
-
inputs = feature_extractor(images=image)
|
| 45 |
outputs = model(**inputs)
|
| 46 |
logits = outputs.logits
|
| 47 |
# model predicts one of the 1000 ImageNet classes
|
| 48 |
-
|
|
|
|
| 49 |
```
|
| 50 |
|
| 51 |
Currently, both the feature extractor and model support PyTorch. Tensorflow and JAX/FLAX are coming soon, and the API of ViTFeatureExtractor might change.
|
|
|
|
| 41 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 42 |
feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch32-384')
|
| 43 |
model = ViTForImageClassification.from_pretrained('google/vit-base-patch32-384')
|
| 44 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 45 |
outputs = model(**inputs)
|
| 46 |
logits = outputs.logits
|
| 47 |
# model predicts one of the 1000 ImageNet classes
|
| 48 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 49 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
| 50 |
```
|
| 51 |
|
| 52 |
Currently, both the feature extractor and model support PyTorch. Tensorflow and JAX/FLAX are coming soon, and the API of ViTFeatureExtractor might change.
|