SurfaceGuard AI: SegFormer-B5 ensemble for industrial surface defect segmentation

Pixel-level segmentation of four steel-surface defect types (defect_a to defect_d) on 800x128 images, built for the Kaggle competition Industrial Surface Anomaly Segmentation (IIT Madras BS Data Science, Deep Learning and GenAI project; Amit Kumar Verma, 24f1000489).

Kaggle public leaderboard: 0.75203 with the preset best_unweighted_lam4 (the default in config.json). Re-predicted with this bundle, 6 test images match the scored file with mean Dice 1.0000 (minimum 0.9999).

Model

  • Four SegFormer models with a MiT-B5 encoder (segmentation_models_pytorch 0.6.0), 4 sigmoid output channels plus a presence head, ImageNet-pretrained encoders fine-tuned for 12 epochs at 2x resolution; two members use standard sampling, two importance-weighted sampling towards the rougher test images.
  • Inference: equal-weight mean over the four members and four flip views, presence gate (0.45 class probability + 0.35 mean of the top-100 pixel probabilities + 0.20 maximum), per-class hysteresis thresholds and blob filter (config.json -> presets).

Validation (1,708 held-out images; competition metric 0.7 x foreground Dice + 0.2 x false-positive score + 0.1 x empty accuracy)

  • Selected ensemble honest test-like score: 0.77
  • Normal validation, micro-style score 0.7934, Dice a-d [0.5274, 0.5733, 0.734, 0.8055]
  • Test-like (re-weighted) validation, micro-style score 0.7732, Dice a-d [0.4187, 0.5603, 0.7212, 0.8086]

Use

from huggingface_hub import snapshot_download
folder = snapshot_download('kramit1116/surfaceguard-segformer-b5')        # private repository: add token='hf_...'
import sys; sys.path.insert(0, folder)
from inference import SurfaceGuardPredictor
predictor = SurfaceGuardPredictor(deploy_dir=folder)      # loads the 4 models (CUDA if available)
result = predictor.predict('image.jpg', tta=True)         # masks, rles (competition format), areas, gate_scores, overlay_rgb
pip install -r requirements.txt
python inference.py --deploy_dir . --image image.jpg --out overlay.png
python app.py                                             # the web demo, locally

Files

models/*.pt (fp32 state dicts), config.json (architecture, preprocessing, TTA, gate, all threshold presets), inference.py, app.py, requirements.txt, weights_manifest.json (SHA-256), verification_report.json.

Limits

  • Trained and validated only on this competition's 800x128 gray images; other images are resized and not validated.
  • Weakest on rough surfaces, especially defect_a. A decision aid, not a certified inspection system.
  • Trained on Kaggle competition data: check the competition rules before sharing the weights publicly.
Downloads last month
11
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support