Update README.md
Browse files
README.md
CHANGED
@@ -2,7 +2,23 @@
|
|
2 |
license: apache-2.0
|
3 |
datasets:
|
4 |
- prithivMLmods/Math-Shapes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
---
|
|
|
|
|
|
|
|
|
|
|
6 |
```py
|
7 |
Classification Report:
|
8 |
precision recall f1-score support
|
@@ -21,4 +37,86 @@ Parallelogram ▰ 0.9926 0.9840 0.9883 1500
|
|
21 |
weighted avg 0.9908 0.9908 0.9907 12000
|
22 |
```
|
23 |
|
24 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
datasets:
|
4 |
- prithivMLmods/Math-Shapes
|
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 |
+
- Shapes
|
13 |
+
- Geometric
|
14 |
+
- SigLIP2
|
15 |
+
- art
|
16 |
---
|
17 |
+
|
18 |
+
# **Geometric-Shapes-Classification**
|
19 |
+
|
20 |
+
> **Geometric-Shapes-Classification** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a multi-class shape recognition task. It classifies various geometric shapes using the **SiglipForImageClassification** architecture.
|
21 |
+
|
22 |
```py
|
23 |
Classification Report:
|
24 |
precision recall f1-score support
|
|
|
37 |
weighted avg 0.9908 0.9908 0.9907 12000
|
38 |
```
|
39 |
|
40 |
+

|
41 |
+
|
42 |
+
The model categorizes images into the following classes:
|
43 |
+
|
44 |
+
- **Class 0:** Circle ◯
|
45 |
+
- **Class 1:** Kite ⬰
|
46 |
+
- **Class 2:** Parallelogram ▰
|
47 |
+
- **Class 3:** Rectangle ▭
|
48 |
+
- **Class 4:** Rhombus ◆
|
49 |
+
- **Class 5:** Square ◼
|
50 |
+
- **Class 6:** Trapezoid ⏢
|
51 |
+
- **Class 7:** Triangle ▲
|
52 |
+
|
53 |
+
---
|
54 |
+
|
55 |
+
# **Run with Transformers 🤗**
|
56 |
+
|
57 |
+
```python
|
58 |
+
!pip install -q transformers torch pillow gradio
|
59 |
+
```
|
60 |
+
|
61 |
+
```python
|
62 |
+
import gradio as gr
|
63 |
+
from transformers import AutoImageProcessor
|
64 |
+
from transformers import SiglipForImageClassification
|
65 |
+
from PIL import Image
|
66 |
+
import torch
|
67 |
+
|
68 |
+
# Load model and processor
|
69 |
+
model_name = "prithivMLmods/Geometric-Shapes-Classification"
|
70 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
71 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
72 |
+
|
73 |
+
# Label mapping with symbols
|
74 |
+
labels = {
|
75 |
+
"0": "Circle ◯",
|
76 |
+
"1": "Kite ⬰",
|
77 |
+
"2": "Parallelogram ▰",
|
78 |
+
"3": "Rectangle ▭",
|
79 |
+
"4": "Rhombus ◆",
|
80 |
+
"5": "Square ◼",
|
81 |
+
"6": "Trapezoid ⏢",
|
82 |
+
"7": "Triangle ▲"
|
83 |
+
}
|
84 |
+
|
85 |
+
def classify_shape(image):
|
86 |
+
"""Classifies the geometric shape in the input image."""
|
87 |
+
image = Image.fromarray(image).convert("RGB")
|
88 |
+
inputs = processor(images=image, return_tensors="pt")
|
89 |
+
|
90 |
+
with torch.no_grad():
|
91 |
+
outputs = model(**inputs)
|
92 |
+
logits = outputs.logits
|
93 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
94 |
+
|
95 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
96 |
+
|
97 |
+
return predictions
|
98 |
+
|
99 |
+
# Gradio interface
|
100 |
+
iface = gr.Interface(
|
101 |
+
fn=classify_shape,
|
102 |
+
inputs=gr.Image(type="numpy"),
|
103 |
+
outputs=gr.Label(label="Prediction Scores"),
|
104 |
+
title="Geometric Shapes Classification",
|
105 |
+
description="Upload an image to classify geometric shapes such as circle, triangle, square, and more."
|
106 |
+
)
|
107 |
+
|
108 |
+
# Launch the app
|
109 |
+
if __name__ == "__main__":
|
110 |
+
iface.launch()
|
111 |
+
```
|
112 |
+
|
113 |
+
---
|
114 |
+
|
115 |
+
# **Intended Use**
|
116 |
+
|
117 |
+
The **Geometric-Shapes-Classification** model is designed to recognize basic geometric shapes in images. Example use cases:
|
118 |
+
|
119 |
+
- **Educational Tools:** For learning and teaching geometry visually.
|
120 |
+
- **Computer Vision Projects:** As a shape detector in robotics or automation.
|
121 |
+
- **Image Analysis:** Recognizing symbols in diagrams or engineering drafts.
|
122 |
+
- **Assistive Technology:** Supporting shape identification for visually impaired applications.
|