File size: 4,509 Bytes
be8e94e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24126e3
8ca8664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3e0a0d
8ca8664
9d97cac
8ca8664
 
 
 
 
 
 
 
 
 
 
 
 
0371b55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ca8664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7f2d59
8ca8664
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
language: 
- en
license: mit
library_name: pytorch
tags:
- autoencoder
- anomaly-detection
- computer-vision
- manufacturing
- onnx
- openvino
- edge-ai
pipeline_tag: image-classification
base_model: custom/autoencoder
datasets:
- custom
metrics:
- reconstruction-error
---

# Anomaly Detection Model – Edge AI for Casting Defect Inspection

## Overview
The **Anomaly Detection Model** is an **autoencoder-based anomaly detection system** fine-tuned for industrial **casting defect inspection**. It identifies whether a metal casting image is *normal (OK)* or *defective* by reconstructing input images and analyzing reconstruction errors.

This model is designed for **Edge AI deployment**, optimized via **ONNX** and **OpenVINO IR** formats to run efficiently on low-power Intel edge devices.

---

## Model Details
- **Architecture:** Convolutional Autoencoder
- **Framework:** PyTorch
- **Training Objective:** Minimize reconstruction loss (MSE) for normal samples
- **Optimization:** ONNX and OpenVINO IR export for edge inference
- **Task:** Unsupervised anomaly detection
- **Domain:** Industrial visual inspection

---

## Repository Structure
```
β”œβ”€β”€ casting_autoencoder.pth    # Trained PyTorch model
β”œβ”€β”€ casting_autoencoder.onnx   # ONNX export
β”œβ”€β”€ model.bin                  # OpenVINO IR model (bin)
β”œβ”€β”€ model.xml                  # OpenVINO IR model (xml)
β”œβ”€β”€ model_card.yaml
β”œβ”€β”€ requirements.txt           # Dependencies
β”œβ”€β”€ inference.py               # inference code
└── README.md                  # Model card (this file)
```

---

## Dataset
**Dataset:** Casting Product Image Dataset (Kaggle)
- **Classes:** Defective / Normal
- **Modality:** Grayscale industrial images
- **Training Strategy:** Only *normal* samples used for training the autoencoder.

---

## Key Configuration Parameters

- **Image Size**: 304Γ—304 pixels
- **Batch Size**: 32
- **Learning Rate**: 1e-3
- **Epochs**: 10
- **Loss Function**: MSE Loss
- **Optimizer**: Adam


## Model Outputs

The training script generates:

- `casting_autoencoder.pth` - PyTorch model weights
- `casting_autoencoder.onnx` - ONNX export for deployment
- Calibrated anomaly threshold based on defective samples


## Anomaly Detection Process

1. **Training Phase**: Model learns to reconstruct normal casting images
2. **Threshold Calibration**: Uses defective samples to determine optimal threshold
3. **Inference**: Images with reconstruction error > threshold are flagged as defective

## Performance

- **Final Training Loss**: 0.0005
- **Suggested Threshold**: 0.0004
- **Model Type**: Unsupervised anomaly detection
- **Architecture**: Convolutional Autoencoder


## Applications

This model is designed for:

- Quality control in metal casting manufacturing
- Real-time defect detection on production lines
- Automated visual inspection systems
- Edge deployment in industrial environments


## Model Features

- **Unsupervised Learning**: Trained only on normal samples
- **Real-time Capable**: Optimized for edge deployment
- **ONNX Compatible**: Ready for production deployment
- **Automatic Thresholding**: Self-calibrating anomaly detection
- **Industrial Grade**: Tested on real manufacturing data


## Technical Details

The model uses a symmetric encoder-decoder architecture with:

- Stride-2 convolutions for downsampling
- Transposed convolutions for upsampling
- ReLU activation in hidden layers
- Sigmoid output activation for pixel reconstruction.

---

## Export & Deployment
| Format | Purpose |
|---------|----------|
| `.pth` | Original PyTorch model |
| `.onnx` | Framework-independent inference |
| `.xml` / `.bin` | OpenVINO IR format for edge devices |

**Edge Optimization:** Model converted and optimized using `openvino.convert_model()`.


---

## Intended Use
- Automated visual inspection for manufacturing/QA systems.
- Real-time edge deployment in industrial environments.

**Not recommended for:**
- Non-industrial datasets.
- Scenarios with significant domain drift (e.g., lighting changes or non-casting objects).

---

## Limitations
- Accuracy depends on lighting and background consistency.
- Model trained primarily on grayscale casting images.
- Thresholds for anomaly detection must be tuned for specific deployment environments.

---

## License
This project is released under the MIT License.

---

## Author
**Arunima Surendran**  
Applied AI  Engineer  
[GitHub Repository](https://github.com/arunimakanavu/anomalydetectionmodel)

---