Downloads · 30 days
16
2% of all-time downloads
laszlokiss27/doodle-dash2
doodle-dash2 is a image classification model from laszlokiss27. Use it when you need a label for an image. It is set up for transformers.
This is a fine-tuned model based on apple/mobilevitv2-1.0-imagenet1k-256 trained for sketch image recognition using Xenova/quickdraw-small dataset.
Downloads · 30 days
16
2% of all-time downloads
All-time downloads
872
Public
Parameters
4.6M
37.2 MB on disk
Likes
0
Public
Click a slice to open those files.
.onnx18.8 MB · 51%
From the Hugging Face model README
This is a fine-tuned model based on apple/mobilevitv2-1.0-imagenet1k-256 trained for sketch image recognition using Xenova/quickdraw-small dataset.
from transformers import MobileViTImageProcessor, MobileViTV2ForImageClassification
from PIL import Image
import requests
import torch
import numpy as np # Importing NumPy
url = "https://static.thenounproject.com/png/2024184-200.png"
response = requests.get(url, stream=True)
# Convert to grayscale to ensure a single channel input
image = Image.open(response.raw).convert('L') # Convert to grayscale
processor = MobileViTImageProcessor.from_pretrained("laszlokiss27/doodle-dash2")
model = MobileViTV2ForImageClassification.from_pretrained("laszlokiss27/doodle-dash2")
# Convert the PIL image to a tensor and add a channel dimension
image_tensor = torch.unsqueeze(torch.tensor(np.array(image)), 0).float()
image_tensor = image_tensor.unsqueeze(0) # Add batch dimension
# Check if processor requires specific form of input
inputs = processor(images=image_tensor, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
# Get prediction
predicted_class_idx = logits.argmax(-1).item()
predicted_class = model.config.id2label[predicted_class_idx]
print("Predicted class:", predicted_class)