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).
1import torch
2from torchvision import transforms
3from PIL import Image
4
5# Assume you have the model definition from the GitHub repo
6from model import UNetWithResNet34
7
8# Instantiate model
9model = UNetWithResNet34(num_classes=4, pretrained=False)
10model.load_state_dict(torch.load("best.pth", map_location="cpu"))
11model.eval()
12
13# Preprocessing
14transform = transforms.Compose([
15 transforms.Resize((256, 1600)),
16 transforms.ToTensor(),
17])
18
19# Inference
20image = Image.open("steel_sheet.png").convert("RGB")
21input_tensor = transform(image).unsqueeze(0) # shape: (1, 3, 256, 1600)
22
23with torch.no_grad():
24 logits = model(input_tensor)
25 probs = torch.sigmoid(logits) # shape: (1, 4, 256, 1600)
26
27# Binarize at optimal threshold
28masks = (probs > 0.45).float() # shape: (1, 4, 256, 1600)
29Visualise the masks
30python
31import matplotlib.pyplot as plt
32
33# Show class 1 mask
34plt.imshow(masks[0, 0], cmap='gray')
35plt.title("Defect Class 1 Prediction")
36plt.axis('off')
37plt.show()
38📁 Files in this repository
39File Description
40best.pth Model weights achieving lowest validation loss (0.4358)
41config.json (Optional) Training hyperparameters
42README.md This file
43📝 Notes from the Test Report
44The model successfully learns to detect major defect regions but struggles with small or subtle defects.
45
46Defect sizes vary significantly (small spots to large continuous streaks).
47
48Multiple defect classes can appear on the same image.
49
50The loss curves show no overfitting; further training with stronger augmentation or pseudo‑labeling could improve the Dice score above 0.85.
51
52🔗 Related Resources
53Source code, training scripts, and design documents: GitHub repository
54
55Dataset: Severstal Steel Defect Detection
56
57U‑Net paper: Ronneberger et al., MICCAI 2015
58
59ResNet paper: He et al., CVPR 2016
60
61📄 License
62MIT