Instructions to use laszlokiss27/doodle-dash2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use laszlokiss27/doodle-dash2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="laszlokiss27/doodle-dash2") 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("laszlokiss27/doodle-dash2") model = AutoModelForImageClassification.from_pretrained("laszlokiss27/doodle-dash2") - Notebooks
- Google Colab
- Kaggle
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Model description
|
| 2 |
+
This is a fine-tuned model based on [apple/mobilevitv2-1.0-imagenet1k-256](https://huggingface.co/apple/mobilevitv2-1.0-imagenet1k-256) trained for sketch image recognition using [Xenova/quickdraw-small](https://huggingface.co/datasets/Xenova/quickdraw-small) dataset.
|
| 3 |
+
|
| 4 |
+
## How to use?
|
| 5 |
+
```
|
| 6 |
+
from transformers import MobileViTImageProcessor, MobileViTV2ForImageClassification
|
| 7 |
+
from PIL import Image
|
| 8 |
+
import requests
|
| 9 |
+
import torch
|
| 10 |
+
import numpy as np # Importing NumPy
|
| 11 |
+
|
| 12 |
+
url = "https://static.thenounproject.com/png/2024184-200.png"
|
| 13 |
+
response = requests.get(url, stream=True)
|
| 14 |
+
|
| 15 |
+
# Convert to grayscale to ensure a single channel input
|
| 16 |
+
image = Image.open(response.raw).convert('L') # Convert to grayscale
|
| 17 |
+
|
| 18 |
+
processor = MobileViTImageProcessor.from_pretrained("laszlokiss27/doodle-dash2")
|
| 19 |
+
model = MobileViTV2ForImageClassification.from_pretrained("laszlokiss27/doodle-dash2")
|
| 20 |
+
|
| 21 |
+
# Convert the PIL image to a tensor and add a channel dimension
|
| 22 |
+
image_tensor = torch.unsqueeze(torch.tensor(np.array(image)), 0).float()
|
| 23 |
+
image_tensor = image_tensor.unsqueeze(0) # Add batch dimension
|
| 24 |
+
|
| 25 |
+
# Check if processor requires specific form of input
|
| 26 |
+
inputs = processor(images=image_tensor, return_tensors="pt")
|
| 27 |
+
|
| 28 |
+
outputs = model(**inputs)
|
| 29 |
+
logits = outputs.logits
|
| 30 |
+
|
| 31 |
+
# Get prediction
|
| 32 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 33 |
+
predicted_class = model.config.id2label[predicted_class_idx]
|
| 34 |
+
print("Predicted class:", predicted_class)
|
| 35 |
+
|
| 36 |
+
```
|