Image Classification
Transformers
Safetensors
English
siglip
Digits
Mnist
SigLIP2
0-t0-9
Number-Classification
Instructions to use prithivMLmods/Mnist-Digits-SigLIP2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use prithivMLmods/Mnist-Digits-SigLIP2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="prithivMLmods/Mnist-Digits-SigLIP2") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoProcessor, AutoModelForImageClassification processor = AutoProcessor.from_pretrained("prithivMLmods/Mnist-Digits-SigLIP2") model = AutoModelForImageClassification.from_pretrained("prithivMLmods/Mnist-Digits-SigLIP2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,7 +1,27 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
```py
|
| 6 |
Classification Report:
|
| 7 |
precision recall f1-score support
|
|
@@ -23,3 +43,85 @@ weighted avg 0.9928 0.9928 0.9928 60000
|
|
| 23 |
```
|
| 24 |
|
| 25 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- ylecun/mnist
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
base_model:
|
| 8 |
+
- google/siglip2-base-patch16-224
|
| 9 |
+
pipeline_tag: image-classification
|
| 10 |
+
library_name: transformers
|
| 11 |
+
tags:
|
| 12 |
+
- Digits
|
| 13 |
+
- Mnist
|
| 14 |
+
- SigLIP2
|
| 15 |
+
- 0-t0-9
|
| 16 |
+
- Number-Classification
|
| 17 |
---
|
| 18 |
|
| 19 |
+

|
| 20 |
+
|
| 21 |
+
# **Mnist-Digits-SigLIP2**
|
| 22 |
+
|
| 23 |
+
> **Mnist-Digits-SigLIP2** is an image classification model fine-tuned from **google/siglip2-base-patch16-224** to classify handwritten digits (0-9) using the **SiglipForImageClassification** architecture. It is trained on the MNIST dataset for accurate digit recognition.
|
| 24 |
+
|
| 25 |
```py
|
| 26 |
Classification Report:
|
| 27 |
precision recall f1-score support
|
|
|
|
| 43 |
```
|
| 44 |
|
| 45 |

|
| 46 |
+
|
| 47 |
+
### **Classes:**
|
| 48 |
+
- **Class 0:** "0"
|
| 49 |
+
- **Class 1:** "1"
|
| 50 |
+
- **Class 2:** "2"
|
| 51 |
+
- **Class 3:** "3"
|
| 52 |
+
- **Class 4:** "4"
|
| 53 |
+
- **Class 5:** "5"
|
| 54 |
+
- **Class 6:** "6"
|
| 55 |
+
- **Class 7:** "7"
|
| 56 |
+
- **Class 8:** "8"
|
| 57 |
+
- **Class 9:** "9"
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
# **Run with Transformers🤗**
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
!pip install -q transformers torch pillow gradio
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
import gradio as gr
|
| 69 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
| 70 |
+
from transformers.image_utils import load_image
|
| 71 |
+
from PIL import Image
|
| 72 |
+
import torch
|
| 73 |
+
|
| 74 |
+
# Load model and processor
|
| 75 |
+
model_name = "prithivMLmods/Mnist-Digits-SigLIP2"
|
| 76 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
| 77 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 78 |
+
|
| 79 |
+
def classify_digit(image):
|
| 80 |
+
"""Predicts the digit in the given handwritten digit image."""
|
| 81 |
+
image = Image.fromarray(image).convert("RGB")
|
| 82 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 83 |
+
|
| 84 |
+
with torch.no_grad():
|
| 85 |
+
outputs = model(**inputs)
|
| 86 |
+
logits = outputs.logits
|
| 87 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 88 |
+
|
| 89 |
+
labels = {
|
| 90 |
+
"0": "0", "1": "1", "2": "2", "3": "3", "4": "4",
|
| 91 |
+
"5": "5", "6": "6", "7": "7", "8": "8", "9": "9"
|
| 92 |
+
}
|
| 93 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
| 94 |
+
|
| 95 |
+
return predictions
|
| 96 |
+
|
| 97 |
+
# Create Gradio interface
|
| 98 |
+
iface = gr.Interface(
|
| 99 |
+
fn=classify_digit,
|
| 100 |
+
inputs=gr.Image(type="numpy"),
|
| 101 |
+
outputs=gr.Label(label="Prediction Scores"),
|
| 102 |
+
title="MNIST Digit Classification 🔢",
|
| 103 |
+
description="Upload a handwritten digit image (0-9) to recognize it using MNIST-Digits-SigLIP2."
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# Launch the app
|
| 107 |
+
if __name__ == "__main__":
|
| 108 |
+
iface.launch()
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
# **Sample Inference**
|
| 114 |
+
|
| 115 |
+

|
| 116 |
+

|
| 117 |
+

|
| 118 |
+

|
| 119 |
+
|
| 120 |
+
# **Intended Use:**
|
| 121 |
+
|
| 122 |
+
The **Mnist-Digits-SigLIP2** model is designed for handwritten digit recognition. Potential applications include:
|
| 123 |
+
|
| 124 |
+
- **Optical Character Recognition (OCR):** Digit recognition for various documents.
|
| 125 |
+
- **Banking & Finance:** Automated check processing.
|
| 126 |
+
- **Education & Learning:** AI-powered handwriting assessment.
|
| 127 |
+
- **Embedded Systems:** Handwriting input in smart devices.
|