CoolFace
Modelpublic

Jan358/Geometric-Shapes-Classification

sourceHugging Faceapache-2.0updated 27d agoView on Hugging Face
0likes22downloads
README.md124 linesDownload Raw Back to root
1---2license: apache-2.03datasets:4- prithivMLmods/Math-Shapes5language:6- en7base_model:8- google/siglip2-base-patch16-2249pipeline_tag: image-classification10library_name: transformers11tags:12- Shapes13- Geometric14- SigLIP215- art16---17 18![zdfdf.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/z98n2b4kPFRoxPGKddrno.png)19  20# **Geometric-Shapes-Classification**21 22> **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.23 24```py25Classification Report:26                 precision    recall  f1-score   support27 28       Circle ◯     0.9921    0.9987    0.9953      150029         Kite ⬰     0.9927    0.9927    0.9927      150030Parallelogram ▰     0.9926    0.9840    0.9883      150031    Rectangle ▭     0.9993    0.9913    0.9953      150032      Rhombus ◆     0.9846    0.9820    0.9833      150033       Square ◼     0.9914    0.9987    0.9950      150034    Trapezoid ⏢     0.9966    0.9793    0.9879      150035     Triangle ▲     0.9772    0.9993    0.9881      150036 37       accuracy                         0.9908     1200038      macro avg     0.9908    0.9908    0.9907     1200039   weighted avg     0.9908    0.9908    0.9907     1200040```41 42![download (3).png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/WAdeb9cy5DBb-zZ0TPx0k.png)43 44The model categorizes images into the following classes:45 46- **Class 0:** Circle ◯  47- **Class 1:** Kite ⬰  48- **Class 2:** Parallelogram ▰  49- **Class 3:** Rectangle ▭  50- **Class 4:** Rhombus ◆  51- **Class 5:** Square ◼  52- **Class 6:** Trapezoid ⏢  53- **Class 7:** Triangle ▲  54 55---56 57# **Run with Transformers 🤗**58 59```python60!pip install -q transformers torch pillow gradio61```62 63```python64import gradio as gr65from transformers import AutoImageProcessor66from transformers import SiglipForImageClassification67from PIL import Image68import torch69 70# Load model and processor71model_name = "prithivMLmods/Geometric-Shapes-Classification"72model = SiglipForImageClassification.from_pretrained(model_name)73processor = AutoImageProcessor.from_pretrained(model_name)74 75# Label mapping with symbols76labels = {77    "0": "Circle ◯",78    "1": "Kite ⬰",79    "2": "Parallelogram ▰",80    "3": "Rectangle ▭",81    "4": "Rhombus ◆",82    "5": "Square ◼",83    "6": "Trapezoid ⏢",84    "7": "Triangle ▲"85}86 87def classify_shape(image):88    """Classifies the geometric shape in the input image."""89    image = Image.fromarray(image).convert("RGB")90    inputs = processor(images=image, return_tensors="pt")91 92    with torch.no_grad():93        outputs = model(**inputs)94        logits = outputs.logits95        probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()96 97    predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}98    99    return predictions100 101# Gradio interface102iface = gr.Interface(103    fn=classify_shape,104    inputs=gr.Image(type="numpy"),105    outputs=gr.Label(label="Prediction Scores"),106    title="Geometric Shapes Classification",107    description="Upload an image to classify geometric shapes such as circle, triangle, square, and more."108)109 110# Launch the app111if __name__ == "__main__":112    iface.launch()113```114 115---116 117# **Intended Use**118 119The **Geometric-Shapes-Classification** model is designed to recognize basic geometric shapes in images. Example use cases:120 121- **Educational Tools:** For learning and teaching geometry visually.  122- **Computer Vision Projects:** As a shape detector in robotics or automation.  123- **Image Analysis:** Recognizing symbols in diagrams or engineering drafts.  124- **Assistive Technology:** Supporting shape identification for visually impaired applications.