Downloads · 30 days
31
25% of all-time downloads
samir-mohamed/concrete-crack-segmentation
concrete-crack-segmentation is a image segmentation model from samir-mohamed. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
A deep learning project for detecting and segmenting concrete cracks in images using an improved UNet architecture. The model achieves exceptional performance with Dice coefficient of 99.77% and IoU of 99.54%.
Downloads · 30 days
31
25% of all-time downloads
All-time downloads
122
Public
Repo size
124 MB
Likes
0
Public
Click a slice to open those files.
.pth124 MB · 100%
From the Hugging Face model README
A deep learning project for detecting and segmenting concrete cracks in images using an improved UNet architecture. The model achieves exceptional performance with Dice coefficient of 99.77% and IoU of 99.54%.
| Metric | Value |
|---|---|
| Dice Score | 99.77% |
| IoU Score | 99.54% |
| F1 Score | 99.77% |
| Precision | 99.54% |
| Recall | 100.00% |
| Training Loss | 0.0162 |
| Validation Loss | 0.0139 |
concreate-crack-segmentation/
├── Concreate_Crack_Segmentation.ipynb # Main notebook
├── Dataset/
│ ├── images/ # 800 concrete images (256x256)
│ └── masks/ # Corresponding crack masks
├── unet_model_weights.pth # Trained model weights
├── model_config.json # Model configuration
├── training_history.json # Training metrics history
├── training_history.png # Training plots
├── predictions_visualization.png # Sample predictions
├── requirements.txt # Dependencies
├── README.md # This file
├── model_card.md # Model card for HF
└── inference.py # Inference script
torch==2.0.0
torchvision==0.15.0
Pillow==9.5.0
numpy==1.24.3
opencv-python==4.8.0.74
matplotlib==3.7.2
tqdm==4.66.1
from PIL import Image
import torch
from inference import predict_crack_segmentation
# Make prediction
image_path = "path/to/image.jpg"
prediction = predict_crack_segmentation(image_path, threshold=0.5)
# Mount Google Drive and run notebook cells in order
# Dataset path: /MyDrive/computer vision course/projects/Concreate Crack Segmentation/Dataset/
Loading Phase
Preprocessing
Normalization
Augmentation (train only)
import torch
from model import ImprovedUNet
model = ImprovedUNet(in_channels=3, out_channels=1, depth=4, start_filters=64)
model.load_state_dict(torch.load('unet_model_weights.pth'))
model.eval()
from PIL import Image
import torchvision.transforms as transforms
image = Image.open('concrete.jpg').convert('RGB')
image = transforms.Resize((256, 256))(image)
image_tensor = transforms.ToTensor()(image).unsqueeze(0)
with torch.no_grad():
prediction = model(image_tensor)
segmentation_mask = prediction.squeeze().numpy()
from torch.utils.data import DataLoader
from dataset_class import CrackDataset
dataset = CrackDataset(images_path, masks_path, transform=val_transform)
loader = DataLoader(dataset, batch_size=32, shuffle=False)
predictions = []
for images, masks in loader:
with torch.no_grad():
preds = model(images)
predictions.extend(preds.cpu().numpy())
# Modify these in the notebook:
BATCH_SIZE = 16 # Change batch size
NUM_EPOCHS = 25 # Change max epochs
LEARNING_RATE = 2e-3 # Change learning rate
IMG_WIDTH = IMG_HEIGHT = 256 # Change image size
# In CombinedLoss:
bce_weight = 0.4 # Weight for BCE loss
dice_weight = 0.6 # Weight for Dice loss
# Adjust for different focus (higher dice_weight → more focus on segmentation)
Solution: Set num_workers=0 in DataLoader (already implemented)
Solution:
Solution:
Tested with:
See model_card.md for detailed model information.
Created as educational project for concrete crack detection using deep learning.
MIT License - Feel free to use for educational and commercial purposes.
For issues or questions, please create an issue in the repository.
Last Updated: March 28, 2026
Model Status: Production Ready ✓