Spaces:
Running
Running
Initial Gradio space
Browse files- README.md +39 -8
- app.py +19 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,14 +1,45 @@
|
|
| 1 |
---
|
| 2 |
-
title: Casting Defect
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
-
license:
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Casting Defect Detection
|
| 3 |
+
emoji: 🔍
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.33.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
models:
|
| 12 |
+
- gfichetdc/casting-defect-vit
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# Casting Defect Detection (ViT)
|
| 16 |
+
|
| 17 |
+
Fine-tuned **ViT-B/16** on 6,633 casting surface images to classify parts as **defective** or **ok**.
|
| 18 |
+
|
| 19 |
+
| Metric | Value |
|
| 20 |
+
|--------|-------|
|
| 21 |
+
| Macro F1 | 0.995 |
|
| 22 |
+
| Accuracy | 99.6% |
|
| 23 |
+
| Base model | google/vit-base-patch16-224 |
|
| 24 |
+
| Training images | 6,633 |
|
| 25 |
+
| Test images | 715 |
|
| 26 |
+
| Epochs | 3 |
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from transformers import pipeline
|
| 32 |
+
|
| 33 |
+
classifier = pipeline("image-classification", model="gfichetdc/casting-defect-vit")
|
| 34 |
+
result = classifier("path/to/casting_image.jpeg")
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Dataset
|
| 38 |
+
|
| 39 |
+
[Kaggle — Casting Product Image Data for Quality Inspection](https://www.kaggle.com/datasets/ravirajsinh45/real-life-industrial-dataset-of-casting-product): 7,348 grayscale images of submersible pump impellers.
|
| 40 |
+
|
| 41 |
+
## Training
|
| 42 |
+
|
| 43 |
+
- Fine-tuned `google/vit-base-patch16-224` with HuggingFace Trainer
|
| 44 |
+
- lr=2e-5, batch size 16, 3 epochs on RTX 3060 (~10 min)
|
| 45 |
+
- Experiment tracking with MLflow
|
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline("image-classification", model="gfichetdc/casting-defect-vit")
|
| 5 |
+
|
| 6 |
+
def predict(image):
|
| 7 |
+
results = classifier(image)
|
| 8 |
+
return {r["label"]: r["score"] for r in results}
|
| 9 |
+
|
| 10 |
+
demo = gr.Interface(
|
| 11 |
+
fn=predict,
|
| 12 |
+
inputs=gr.Image(type="pil"),
|
| 13 |
+
outputs=gr.Label(num_top_classes=2),
|
| 14 |
+
title="Casting Defect Detection (ViT)",
|
| 15 |
+
description="Fine-tuned ViT-B/16 classifying casting surface images as defective or ok. 99.5% macro F1.",
|
| 16 |
+
examples=[],
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
Pillow
|