A comprehensive deep learning framework for material image segmentation using various encoder-decoder architectures.
- Multiple encoder architectures: ResNet50, SE-ResNeXt101
- Multiple decoder architectures: UNet, DeepLabV3, DeepLabV3+
- Multiple pretraining strategies: ImageNet, MicroNet
- Support for various material datasets
- Command-line interface for easy experimentation
- Automatic result visualization and analysis
pip install torch torchvision
pip install segmentation-models-pytorch
pip install opencv-python
pip install scikit-learn
pip install pandas matplotlib
pip install tqdm pillow
pip install huggingface-hubOrganize your datasets in the following structure:
project_root/
├── mdsmg_experiment.py
├── AFM/
│ ├── images/
│ │ ├── image1.png
│ │ ├── image2.tif
│ │ └── ...
│ └── masks/
│ ├── image1.png
│ ├── image2.tif
│ └── ...
├── SEM/
│ ├── images/
│ └── masks/
└── ...
Supported image formats: PNG, TIF/TIFF, JPG/JPEG
python mdsmg_experiment.py --datasets AFM --encoders resnet50 --decoders unet --pretrained imagenetpython mdsmg_experiment.py --datasets AFM SEM --encoders resnet50 se_resnext101 --decoders unet deeplabv3 --pretrained imagenet micronetpython mdsmg_experiment.py --datasets AFM --epochs 10 --batch-size 1 --image-size 128python mdsmg_experiment.py --datasets AFM SEM Carbon --encoders resnet50 se_resnext101 --decoders unet deeplabv3 deeplabv3plus --pretrained imagenet micronet --epochs 200 --visualize| Argument | Type | Default | Description |
|---|---|---|---|
--datasets |
list | ['AFM'] |
Dataset names to use |
--encoders |
list | ['resnet50'] |
Encoder architectures |
--decoders |
list | ['unet'] |
Decoder architectures |
--pretrained |
list | ['imagenet'] |
Pretraining strategies |
--epochs |
int | 50 |
Number of training epochs |
--batch-size |
int | 2 |
Batch size for training |
--image-size |
int | 256 |
Input image size (square) |
--device |
str | 'cuda' |
Device to use (cuda/cpu) |
--output |
str | 'experiment_results.csv' |
Output CSV filename |
--visualize |
flag | False |
Create visualization plots |
resnet50: ResNet-50 backbonese_resnext101: SE-ResNeXt-101 backbone
unet: U-Net decoderdeeplabv3: DeepLabV3 decoderdeeplabv3plus: DeepLabV3+ decoder
imagenet: ImageNet pretrained weightsmicronet: MicroNet pretrained weights (specialized for microscopy)
# Full comparison study
python mdsmg_experiment.py \
--datasets AFM SEM Carbon \
--encoders resnet50 se_resnext101 \
--decoders unet deeplabv3 deeplabv3plus \
--pretrained imagenet micronet \
--epochs 200 \
--batch-size 2 \
--image-size 256 \
--visualize \
--output full_study_results.csv# Fast testing with small configuration
python mdsmg_experiment.py \
--datasets AFM \
--encoders resnet50 \
--decoders unet \
--epochs 20 \
--batch-size 4 \
--image-size 128# For systems without GPU
python mdsmg_experiment.py \
--datasets AFM \
--device cpu \
--batch-size 1 \
--epochs 10# For limited GPU memory
python mdsmg_experiment.py \
--datasets AFM \
--batch-size 1 \
--image-size 128 \
--epochs 50The script generates several output files:
- CSV Results (
experiment_results.csv): Detailed metrics for each configuration - Model Weights (
best_*.pth): Best model weights for each configuration - Visualizations (
experiment_results.png): Performance comparison plots (if--visualizeis used)
The script automatically displays:
- Training progress with loss values
- Validation metrics (IoU, Dice coefficient)
- Best model performance
- GPU memory usage
- Experiment completion status
For systems with limited GPU memory:
- Reduce batch size:
--batch-size 1 - Reduce image size:
--image-size 128 - Use CPU:
--device cpu - Close other GPU applications
-
CUDA Out of Memory
# Solution: Reduce batch size and image size python mdsmg_experiment.py --batch-size 1 --image-size 128 -
Dataset Not Found
# Ensure dataset folder structure is correct # Check that images/ and masks/ folders exist -
MicroNet Weights Loading Failed
# This is normal - will fall back to ImageNet weights # MicroNet weights are optional
- Faster Training: Use larger batch sizes if memory allows
- Better Results: Use larger image sizes (512x512) if memory allows
- Quick Testing: Start with 10-20 epochs for initial experiments
- Production: Use 100-200 epochs for final results
The CSV output contains:
best_val_iou: Best validation IoU score (higher is better)final_val_dice: Final validation Dice coefficientconfig: Model configuration stringtrain_samples: Number of training samplesval_samples: Number of validation samples
Typical IoU scores:
> 0.8: Excellent0.6-0.8: Good0.4-0.6: Fair< 0.4: Poor
@software{Materials Data Segmentation Benchmark,
title={Context Determines Optimal Architecture in Materials Segmentation},
author={Lu, Mingjian and Tripathi, Pawan Kumar and Shteyn, Mark and Ganguly, Debargha and French, Roger H. and Chaudhary, Vipin and Wu, Yinghui},
year={2026},
url={https://openreview.net/forum?id=kYqWdpXCx8}
}