Skip to content

Commit bd9123f

Browse files
committed
fixing gradcam + initializing docs structure
1 parent 905ba86 commit bd9123f

10 files changed

Lines changed: 49 additions & 13 deletions

File tree

‎docs/challenges.md‎

Whitespace-only changes.

‎docs/data-preprocessing.md‎

Whitespace-only changes.

‎docs/index.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ An anomaly-based defect detection system for industrial quality control, built a
44

55
## What This Project Does
66

7-
This application inspects metal nut images from the [MVTec AD dataset](https://www.mvtec.com/company/research/datasets/mvtec-ad) and classifies them as **Good** or **Defective** using the PatchCore anomaly detection algorithm. It produces heatmaps showing exactly where the model identifies anomalies.
7+
This application inspects **Steel Surface Defect Classification Dataset**, and classifies them with 4 different types of defect: **defect_1, defect_2, defect_3, defect_4, or no_defect** using PyTorch for a **Convolutional Network architecture** with a **residuals approach**. Plus with a Streamlit app that produces heatmaps showing exactly where the model identifies anomalies.
88

99
## Project Components
1010

1111
| Component | Technology | Purpose |
1212
|-----------|------------|---------|
1313
| Frontend | Streamlit | Interactive inspection UI with image display and metrics |
14-
| Backend | PatchCore (Anomalib) | Anomaly detection model with heatmap generation |
14+
| Backend | PyTorch CNN Architecture | Anomaly detection model with heatmap generation |
1515
| Camera Simulation | Custom Python module | Mimics industrial camera acquisition from dataset images |
1616
| Documentation | MkDocs + Material | This site — project docs and guides |
1717
| CI/CD | GitHub Actions | Automated testing and linting on every push |
@@ -21,15 +21,15 @@ This application inspects metal nut images from the [MVTec AD dataset](https://w
2121

2222
```bash
2323
# Clone and set up
24-
git clone <your-repo-url>
24+
git clone JimWid/Anomaly_Detection
2525
cd anomaly_detection
2626

27-
# Install dependencies (see Installation page for full details)
28-
pip install -r requirements.txt
27+
# This version uses UV
28+
uv sync
2929

30-
# Train the model (one-time, ~2 minutes)
31-
python -m anomaly_detection.train
30+
# Train the model (one-time, ~20 minutes)
31+
python -m steel_defect.train --epochs 20
3232

3333
# Launch the app
34-
streamlit run anomaly_detection/app.py
34+
streamlit run final_project/steel_defect/app.py
3535
```

‎docs/model-architecture.md‎

Whitespace-only changes.

‎docs/project-overview.md‎

Whitespace-only changes.

‎docs/results.md‎

Whitespace-only changes.

‎docs/training.md‎

Whitespace-only changes.

‎final_project/logs/app.log‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,35 @@
311311
2026-08-04 13:18:20 | WARNING | steel_defect.app | Grad-CAM failed: 'SteelCNN' object has no attribute 'features'
312312
2026-08-04 13:18:22 | INFO | steel_defect.inference | Inference #68 | label=defect_3 | confidence=0.546 | time=23.3ms
313313
2026-08-04 13:18:22 | WARNING | steel_defect.app | Grad-CAM failed: 'SteelCNN' object has no attribute 'features'
314+
2026-08-04 13:37:05 | INFO | steel_defect.inference | SteelPredictor initialized | checkpoint=C:\Personal Projects\Anomaly_Detection\final_project\models\steel_cnn_best.pt | device=cuda
315+
2026-08-04 13:37:05 | INFO | steel_defect.inference | Model loaded | time=68ms
316+
2026-08-04 13:37:09 | INFO | steel_defect.inference | Inference #1 | label=defect_3 | confidence=0.519 | time=94.1ms
317+
2026-08-04 13:37:10 | INFO | steel_defect.inference | Inference #2 | label=defect_1 | confidence=0.452 | time=2.9ms
318+
2026-08-04 13:37:12 | INFO | steel_defect.inference | Inference #3 | label=defect_1 | confidence=0.520 | time=17.9ms
319+
2026-08-04 13:37:13 | INFO | steel_defect.inference | Inference #4 | label=defect_3 | confidence=0.685 | time=16.3ms
320+
2026-08-04 13:37:15 | INFO | steel_defect.inference | Inference #5 | label=defect_1 | confidence=0.495 | time=16.7ms
321+
2026-08-04 13:37:17 | INFO | steel_defect.inference | Inference #6 | label=defect_3 | confidence=0.544 | time=17.0ms
322+
2026-08-04 13:37:18 | INFO | steel_defect.inference | Inference #7 | label=defect_3 | confidence=0.520 | time=16.5ms
323+
2026-08-04 13:37:20 | INFO | steel_defect.inference | Inference #8 | label=defect_1 | confidence=0.438 | time=16.7ms
324+
2026-08-04 13:37:21 | INFO | steel_defect.inference | Inference #9 | label=defect_3 | confidence=0.627 | time=16.6ms
325+
2026-08-04 13:37:23 | INFO | steel_defect.inference | Inference #10 | label=defect_3 | confidence=0.423 | time=21.1ms
326+
2026-08-04 13:37:25 | INFO | steel_defect.inference | Inference #11 | label=defect_3 | confidence=0.540 | time=21.0ms
327+
2026-08-04 13:37:26 | INFO | steel_defect.inference | Inference #12 | label=defect_3 | confidence=0.456 | time=21.1ms
328+
2026-08-04 13:37:28 | INFO | steel_defect.inference | Inference #13 | label=no_defect | confidence=0.737 | time=21.0ms
329+
2026-08-04 13:37:29 | INFO | steel_defect.inference | Inference #14 | label=defect_1 | confidence=0.443 | time=20.8ms
330+
2026-08-04 13:37:31 | INFO | steel_defect.inference | Inference #15 | label=defect_3 | confidence=0.546 | time=16.4ms
331+
2026-08-04 13:37:33 | INFO | steel_defect.inference | Inference #16 | label=defect_3 | confidence=0.913 | time=17.0ms
332+
2026-08-04 13:37:34 | INFO | steel_defect.inference | Inference #17 | label=defect_1 | confidence=0.456 | time=16.8ms
333+
2026-08-04 13:37:36 | INFO | steel_defect.inference | Inference #18 | label=defect_1 | confidence=0.512 | time=16.4ms
334+
2026-08-04 13:37:37 | INFO | steel_defect.inference | Inference #19 | label=no_defect | confidence=0.540 | time=16.4ms
335+
2026-08-04 13:37:39 | INFO | steel_defect.inference | Inference #20 | label=defect_1 | confidence=0.445 | time=16.7ms
336+
2026-08-04 13:37:41 | INFO | steel_defect.inference | Inference #21 | label=defect_3 | confidence=0.589 | time=20.9ms
337+
2026-08-04 13:37:42 | INFO | steel_defect.inference | Inference #22 | label=defect_3 | confidence=0.550 | time=21.1ms
338+
2026-08-04 13:37:45 | INFO | steel_defect.inference | Inference #23 | label=no_defect | confidence=0.720 | time=23.5ms
339+
2026-08-04 13:37:47 | INFO | steel_defect.inference | Inference #24 | label=no_defect | confidence=0.874 | time=20.7ms
340+
2026-08-04 13:37:48 | INFO | steel_defect.inference | Inference #25 | label=no_defect | confidence=1.000 | time=20.9ms
341+
2026-08-04 13:37:50 | INFO | steel_defect.inference | Inference #26 | label=defect_3 | confidence=0.533 | time=20.8ms
342+
2026-08-04 13:37:52 | INFO | steel_defect.inference | Inference #27 | label=no_defect | confidence=0.544 | time=20.9ms
343+
2026-08-04 13:37:53 | INFO | steel_defect.inference | Inference #28 | label=no_defect | confidence=0.992 | time=20.7ms
344+
2026-08-04 13:37:55 | INFO | steel_defect.inference | Inference #29 | label=no_defect | confidence=0.866 | time=16.7ms
345+
2026-08-04 13:37:56 | INFO | steel_defect.inference | Inference #30 | label=no_defect | confidence=0.705 | time=16.6ms

‎final_project/steel_defect/app.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def get_images_in_category(category: str) -> list[Path]:
7878
def generate_gradcam(predictor: SteelPredictor, image_tensor: torch.Tensor) -> np.ndarray:
7979
"""Generate Grad-CAM heatmap from the last conv layer."""
8080
try:
81-
# Get the last convolutional layer from model.features
81+
# Get the last convolutional layer from model.features / this verson uses 'residual_block_3' as the last block
8282
target_layer = None
83-
for layer in reversed(list(predictor.model.features.children())):
83+
for layer in reversed(list(predictor.model.residual_block_3.children())):
8484
if isinstance(layer, torch.nn.Conv2d):
8585
target_layer = layer
8686
break

‎mkdocs.yml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ theme:
1313

1414
nav:
1515
- Home: index.md
16+
- Architecture: model-architecture.md
17+
- Data Preprocessing: data-preprocessing.md
18+
- Training: training.md
19+
- Results: results.md
20+
- Challenges: challenges.md
1621
- Installation: installation.md
1722
- Usage Guide: usage.md
18-
- Architecture: architecture.md
19-
- Advanced - Image Acquisition: advanced-acquisition.md
20-
- Homework:
23+
24+
- Homework - DONE:
2125
- Overview: homework/index.md
2226
- Step 1 - Preprocessing: homework/step-1-preprocessing.md
2327
- Step 2 - Dataset: homework/step-2-dataset.md

0 commit comments

Comments
 (0)