Semantic segmentation for surface crack detection using fine-tuned CLIPSeg.
CrackSeg fine-tunes CLIPSeg — a vision-language segmentation model — on a 14,000+ image crack dataset to produce pixel-wise binary masks for surface crack detection. The model takes an image as input and returns a segmentation mask highlighting crack regions.
| Metric | Score |
|---|---|
| Dice Score | 0.612 |
| mIoU | 0.716 |
- Base model: CLIPSeg (CIDAS/clipseg-rd64-refined)
- Fine-tuning strategy: Partial — decoder fully unfrozen, last 2 layers of CLIP vision encoder, last 1 layer of CLIP text encoder
- Loss: Focal Loss (α=0.75, γ=2.0) to handle severe class imbalance from thin crack regions
- Optimizer: AdamW with differential learning rates
- Decoder:
5e-5 - Vision encoder layers:
2e-6 - Text encoder layers:
1e-6
- Decoder:
- Scheduler: CosineAnnealingLR
- Gradient clipping: max norm 1.0
- Early stopping: patience = 5
- Source: Roboflow (COCO format)
- Size: 14,000+ images
- Splits: Train / Validation / Test
- Annotation pipeline: COCO JSON → binary mask generation via polygon rasterization with bbox fallback
The model correctly identifies thin surface cracks under varied lighting conditions. Known failure cases include shadowed regions being misidentified as cracks — a known limitation of texture-based segmentation.
crackseg/
├── notebook/
│ └── Cracks.ipynb
├── app.py
├── requirements.txt
├── .gitignore
├── LICENSE.md
└── README.md
python -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activate
pip install -r requirements.txt
python app.pyWeights are loaded automatically from HuggingFace Hub (primus29/crackseg).
Try it on HuggingFace Spaces — upload any image of a surface and get back a segmentation mask and red overlay.