Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- semantic-segmentation
|
| 5 |
+
- unet
|
| 6 |
+
- resnet34
|
| 7 |
+
- steel-defect-detection
|
| 8 |
+
- severstal
|
| 9 |
+
- pytorch
|
| 10 |
+
datasets:
|
| 11 |
+
- severstal-steel-defect-detection
|
| 12 |
+
metrics:
|
| 13 |
+
- dice
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# ResNet34‑UNet for Steel Defect Segmentation
|
| 17 |
+
|
| 18 |
+
This repository hosts the **trained model weights** for a U‑Net with ResNet34 backbone, fine‑tuned for semantic segmentation of surface defects on steel sheets. The model classifies and localises four defect types and outputs pixel‑wise probability maps.
|
| 19 |
+
|
| 20 |
+
> 🔗 **Full training and inference code is available on GitHub:**
|
| 21 |
+
> [https://github.com/zyxdtt/cv-course-project/tree/main/Semantic%20Segmentation](https://github.com/zyxdtt/cv-course-project/tree/main/Semantic%20Segmentation)
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 🧠 Model Description
|
| 26 |
+
|
| 27 |
+
| Property | Details |
|
| 28 |
+
|----------|---------|
|
| 29 |
+
| Architecture | U‑Net with encoder: ResNet34 (pretrained on ImageNet) |
|
| 30 |
+
| Input size | 256 × 1600 pixels (single channel grayscale converted to RGB for pretrained backbone) |
|
| 31 |
+
| Output | 4 probability maps (height 256, width 1600) with sigmoid activation |
|
| 32 |
+
| Loss function | `L = BinaryCrossEntropy + (1 - Dice)` |
|
| 33 |
+
| Optimiser | AdamW (initial LR = 1e-4) |
|
| 34 |
+
| Training epochs | 10 |
|
| 35 |
+
| Data augmentation | Random horizontal flip (p=0.5) |
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## 📊 Performance on Validation Set
|
| 40 |
+
|
| 41 |
+
The validation set consists of **1,333 images** (20% of the Severstal dataset). Evaluation metric is the **Dice coefficient**.
|
| 42 |
+
|
| 43 |
+
### Overall Metrics
|
| 44 |
+
|
| 45 |
+
| Metric | Value |
|
| 46 |
+
|--------|-------|
|
| 47 |
+
| Best overall Dice | **0.6296** |
|
| 48 |
+
| Optimal probability threshold | **0.45** |
|
| 49 |
+
| Best validation loss | 0.4358 (epoch 10) |
|
| 50 |
+
|
| 51 |
+
### Per‑Class Dice (threshold = 0.45)
|
| 52 |
+
|
| 53 |
+
| Class | Dice |
|
| 54 |
+
|-------|------|
|
| 55 |
+
| Defect class 1 | 0.651 |
|
| 56 |
+
| Defect class 2 | 0.624 |
|
| 57 |
+
| Defect class 3 | 0.637 |
|
| 58 |
+
| Defect class 4 | 0.606 |
|
| 59 |
+
|
| 60 |
+
### Threshold Robustness
|
| 61 |
+
|
| 62 |
+
The Dice score remains between 0.6293 and 0.6296 for thresholds from 0.3 to 0.7, with a maximum at 0.4, 0.45, and 0.5. This indicates that the model produces highly confident predictions (probabilities near 0 or 1).
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## 🚀 Usage Example (PyTorch)
|
| 67 |
+
|
| 68 |
+
### Load the model and weights
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
import torch
|
| 72 |
+
from torchvision import transforms
|
| 73 |
+
from PIL import Image
|
| 74 |
+
|
| 75 |
+
# Assume you have the model definition from the GitHub repo
|
| 76 |
+
from model import UNetWithResNet34
|
| 77 |
+
|
| 78 |
+
# Instantiate model
|
| 79 |
+
model = UNetWithResNet34(num_classes=4, pretrained=False)
|
| 80 |
+
model.load_state_dict(torch.load("best.pth", map_location="cpu"))
|
| 81 |
+
model.eval()
|
| 82 |
+
|
| 83 |
+
# Preprocessing
|
| 84 |
+
transform = transforms.Compose([
|
| 85 |
+
transforms.Resize((256, 1600)),
|
| 86 |
+
transforms.ToTensor(),
|
| 87 |
+
])
|
| 88 |
+
|
| 89 |
+
# Inference
|
| 90 |
+
image = Image.open("steel_sheet.png").convert("RGB")
|
| 91 |
+
input_tensor = transform(image).unsqueeze(0) # shape: (1, 3, 256, 1600)
|
| 92 |
+
|
| 93 |
+
with torch.no_grad():
|
| 94 |
+
logits = model(input_tensor)
|
| 95 |
+
probs = torch.sigmoid(logits) # shape: (1, 4, 256, 1600)
|
| 96 |
+
|
| 97 |
+
# Binarize at optimal threshold
|
| 98 |
+
masks = (probs > 0.45).float() # shape: (1, 4, 256, 1600)
|
| 99 |
+
Visualise the masks
|
| 100 |
+
python
|
| 101 |
+
import matplotlib.pyplot as plt
|
| 102 |
+
|
| 103 |
+
# Show class 1 mask
|
| 104 |
+
plt.imshow(masks[0, 0], cmap='gray')
|
| 105 |
+
plt.title("Defect Class 1 Prediction")
|
| 106 |
+
plt.axis('off')
|
| 107 |
+
plt.show()
|
| 108 |
+
📁 Files in this repository
|
| 109 |
+
File Description
|
| 110 |
+
best.pth Model weights achieving lowest validation loss (0.4358)
|
| 111 |
+
config.json (Optional) Training hyperparameters
|
| 112 |
+
README.md This file
|
| 113 |
+
📝 Notes from the Test Report
|
| 114 |
+
The model successfully learns to detect major defect regions but struggles with small or subtle defects.
|
| 115 |
+
|
| 116 |
+
Defect sizes vary significantly (small spots to large continuous streaks).
|
| 117 |
+
|
| 118 |
+
Multiple defect classes can appear on the same image.
|
| 119 |
+
|
| 120 |
+
The loss curves show no overfitting; further training with stronger augmentation or pseudo‑labeling could improve the Dice score above 0.85.
|
| 121 |
+
|
| 122 |
+
🔗 Related Resources
|
| 123 |
+
Source code, training scripts, and design documents: GitHub repository
|
| 124 |
+
|
| 125 |
+
Dataset: Severstal Steel Defect Detection
|
| 126 |
+
|
| 127 |
+
U‑Net paper: Ronneberger et al., MICCAI 2015
|
| 128 |
+
|
| 129 |
+
ResNet paper: He et al., CVPR 2016
|
| 130 |
+
|
| 131 |
+
📄 License
|
| 132 |
+
MIT
|