Geometric Shapes Classification
基於SigLIP2微調的圖像分類模型,專用於識別8種基本幾何形狀
下載量 159
發布時間 : 4/4/2025
模型概述
該模型採用SiglipForImageClassification架構,可準確分類圓形、風箏形、平行四邊形、長方形、菱形、正方形、梯形和三角形等幾何形狀。
模型特點
高精度分類
在8類形狀識別任務中達到99.08%的準確率
符號化輸出
分類結果附帶幾何符號標識(如◯▲◼等)
教育友好
特別適合幾何教學場景的視覺識別
模型能力
幾何形狀識別
圖像分類
視覺特徵提取
使用案例
教育
幾何教學輔助
自動識別並標註教學材料中的幾何形狀
提升幾何概念可視化教學效率
計算機視覺
工程圖紙分析
識別技術圖紙中的基本幾何元素
準確率超過99%的形狀分類
🚀 幾何形狀分類模型
本項目的幾何形狀分類模型是一個圖像分類的視覺語言編碼器模型,它基於 google/siglip2-base-patch16-224 進行微調,用於多類形狀識別任務。該模型使用 SiglipForImageClassification 架構對各種幾何形狀進行分類。
🚀 快速開始
安裝依賴
!pip install -q transformers torch pillow gradio
運行代碼
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from PIL import Image
import torch
# Load model and processor
model_name = "prithivMLmods/Geometric-Shapes-Classification"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)
# Label mapping with symbols
labels = {
"0": "Circle ◯",
"1": "Kite ⬰",
"2": "Parallelogram ▰",
"3": "Rectangle ▭",
"4": "Rhombus ◆",
"5": "Square ◼",
"6": "Trapezoid ⏢",
"7": "Triangle ▲"
}
def classify_shape(image):
"""Classifies the geometric shape in the input image."""
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
return predictions
# Gradio interface
iface = gr.Interface(
fn=classify_shape,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(label="Prediction Scores"),
title="Geometric Shapes Classification",
description="Upload an image to classify geometric shapes such as circle, triangle, square, and more."
)
# Launch the app
if __name__ == "__main__":
iface.launch()
💻 使用示例
基礎用法
# 以下代碼展示瞭如何使用該模型進行幾何形狀分類
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from PIL import Image
import torch
# 加載模型和處理器
model_name = "prithivMLmods/Geometric-Shapes-Classification"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)
# 帶有符號的標籤映射
labels = {
"0": "Circle ◯",
"1": "Kite ⬰",
"2": "Parallelogram ▰",
"3": "Rectangle ▭",
"4": "Rhombus ◆",
"5": "Square ◼",
"6": "Trapezoid ⏢",
"7": "Triangle ▲"
}
def classify_shape(image):
"""對輸入圖像中的幾何形狀進行分類。"""
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
return predictions
# Gradio 界面
iface = gr.Interface(
fn=classify_shape,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(label="Prediction Scores"),
title="Geometric Shapes Classification",
description="上傳一張圖像,對圓形、三角形、正方形等幾何形狀進行分類。"
)
# 啟動應用
if __name__ == "__main__":
iface.launch()
📚 詳細文檔
分類報告
Classification Report:
precision recall f1-score support
Circle ◯ 0.9921 0.9987 0.9953 1500
Kite ⬰ 0.9927 0.9927 0.9927 1500
Parallelogram ▰ 0.9926 0.9840 0.9883 1500
Rectangle ▭ 0.9993 0.9913 0.9953 1500
Rhombus ◆ 0.9846 0.9820 0.9833 1500
Square ◼ 0.9914 0.9987 0.9950 1500
Trapezoid ⏢ 0.9966 0.9793 0.9879 1500
Triangle ▲ 0.9772 0.9993 0.9881 1500
accuracy 0.9908 12000
macro avg 0.9908 0.9908 0.9907 12000
weighted avg 0.9908 0.9908 0.9907 12000
模型分類的類別
該模型將圖像分類為以下類別:
- 類別 0:圓形 ◯
- 類別 1:風箏形 ⬰
- 類別 2:平行四邊形 ▰
- 類別 3:矩形 ▭
- 類別 4:菱形 ◆
- 類別 5:正方形 ◼
- 類別 6:梯形 ⏢
- 類別 7:三角形 ▲
預期用途
幾何形狀分類 模型旨在識別圖像中的基本幾何形狀。示例用例如下:
- 教育工具:用於以可視化方式學習和教授幾何知識。
- 計算機視覺項目:作為機器人或自動化中的形狀檢測器。
- 圖像分析:識別圖表或工程圖紙中的符號。
- 輔助技術:支持視障應用中的形狀識別。
📄 許可證
本項目採用 Apache-2.0 許可證。
📦 模型信息
屬性 | 詳情 |
---|---|
模型類型 | 圖像分類視覺語言編碼器模型 |
基礎模型 | google/siglip2-base-patch16-224 |
訓練數據集 | prithivMLmods/Math-Shapes |
庫名稱 | transformers |
標籤 | Shapes、Geometric、SigLIP2、art |
管道標籤 | 圖像分類 |
Nsfw Image Detection
Apache-2.0
基於ViT架構的NSFW圖像分類模型,通過監督學習在ImageNet-21k數據集上預訓練,並在80,000張圖像上微調,用於區分正常和NSFW內容。
圖像分類
Transformers

N
Falconsai
82.4M
588
Fairface Age Image Detection
Apache-2.0
基於Vision Transformer架構的圖像分類模型,在ImageNet-21k數據集上預訓練,適用於多類別圖像分類任務
圖像分類
Transformers

F
dima806
76.6M
10
Dinov2 Small
Apache-2.0
基於DINOv2方法訓練的小尺寸視覺Transformer模型,通過自監督學習提取圖像特徵
圖像分類
Transformers

D
facebook
5.0M
31
Vit Base Patch16 224
Apache-2.0
基於ImageNet-21k預訓練和ImageNet微調的視覺變換器模型,用於圖像分類任務
圖像分類
V
google
4.8M
775
Vit Base Patch16 224 In21k
Apache-2.0
基於ImageNet-21k數據集預訓練的視覺Transformer模型,用於圖像分類任務。
圖像分類
V
google
2.2M
323
Dinov2 Base
Apache-2.0
基於DINOv2方法訓練的視覺Transformer模型,通過自監督學習提取圖像特徵
圖像分類
Transformers

D
facebook
1.9M
126
Gender Classification
一個基於PyTorch和HuggingPics構建的圖像分類模型,用於識別圖像中的性別
圖像分類
Transformers

G
rizvandwiki
1.8M
48
Vit Base Nsfw Detector
Apache-2.0
基於Vision Transformer (ViT)架構的圖像分類模型,專門用於檢測圖像是否包含NSFW(不安全)內容。
圖像分類
Transformers

V
AdamCodd
1.2M
47
Vit Hybrid Base Bit 384
Apache-2.0
混合視覺變換器(ViT)模型結合了卷積網絡和Transformer架構,用於圖像分類任務,在ImageNet上表現出色。
圖像分類
Transformers

V
google
992.28k
6
Gender Classification 2
這是一個基於PyTorch框架和HuggingPics工具生成的圖像分類模型,專門用於性別分類任務。
圖像分類
Transformers

G
rizvandwiki
906.98k
32
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98