Skip to content
ModelListedExternal
Download

Sem Microstructure Segmentation

UNet with a pretrained ResNet-34 encoder for pixel-wise segmentation of Scanning Electron Microscopy (SEM) images of additively manufactured Ni-WC metal matrix composites. Trained to identify five microstructural...

KindOtherVersionRevision 61c03fb

Model source

Kind
Other
File size
88.9–280 MB
Version
vRevision 61c03fb
Updated
Sep 27, 2026
Downloads
0
Tasks
Image segmentation
Source
Hugging Face

Source description

SEM Microstructure Semantic Segmentation

UNet with a pretrained ResNet-34 encoder for pixel-wise segmentation of Scanning Electron Microscopy (SEM) images of additively manufactured Ni-WC metal matrix composites. Trained to identify five microstructural phases at pixel level.

Model Details

PropertyDetail
ArchitectureUNet + ResNet-34 encoder
Encoder weightsImageNet pretrained
Input channels1 (grayscale SEM image)
Output classes5 (pixel-wise segmentation)
FrameworkPyTorch + segmentation_models_pytorch
Training deviceApple MPS (M-series)

Classes

IDPhase
0Matrix
1Carbide
2Void
3Reprecipitate
4Dilution Zone

Test Performance

Evaluated on 54 held-out test images, scored at image level to avoid batch-size bias.

MetricMeanStdMinMax
mIoU0.8720.0880.7230.958
mDice0.9120.0790.7590.978
mBF10.7280.0270.6780.773

Per-Class Performance

ClassIoUDice
Matrix0.9390.969
Carbide0.7530.859
Void0.9760.988
Reprecipitate0.8910.942
Dilution Zone0.8810.937

Files

FileDescription
best_model.pthBest pretrained encoder checkpoint
ScratchUNet_best_unet.pthBest scratch-built UNet checkpoint

How to Use

Install dependencies

pip install torch segmentation-models-pytorch huggingface_hub

Load and run inference

import torch
from huggingface_hub import hf_hub_download
import segmentation_models_pytorch as smp

# Download checkpoint
ckpt_path = hf_hub_download(
    repo_id="imranlabs/sem-microstructure-segmentation",
    filename="best_model.pth"
)

# Rebuild architecture
model = smp.Unet(
    encoder_name    = "resnet34",
    encoder_weights = None,       # weights loaded from checkpoint
    in_channels     = 1,
    classes         = 5,
    activation      = None,
)

# Load weights
ckpt = torch.load(ckpt_path, map_location="cpu")
model.load_state_dict(ckpt["model_state"])
model.eval()

# Inference — input: (1, 1, H, W) float32 tensor normalised to [0, 1]
with torch.no_grad():
    logits = model(image_tensor)          # (1, 5, H, W)
    preds  = torch.argmax(logits, dim=1)  # (1, H, W) class labels

Training Details

  • Loss: 0.6 × Weighted CrossEntropy + 0.4 × DiceLoss
  • Optimizer: AdamW (weight decay 1e-5)
  • Scheduler: ReduceLROnPlateau
  • Strategy: Encoder frozen for first 4 epochs, then full fine-tuning
  • Early stopping: Monitored validation mIoU
  • Best checkpoint: Epoch 12, validation mIoU = 0.876

Dataset

Safdar, M. (2025). Scanning Electron Microscopy (SEM) Dataset of Additively Manufactured Ni-WC Metal Matrix Composites for Semantic Segmentation (Version 1). Zenodo. https://doi.org/10.5281/zenodo.17315241

Links

Author

Imran Khan — Physics PhD · SEM Metrology Engineer · Computer Vision / AI

Sources

1 source
Hugging FacePrimaryVersion 61c03fb55cfbdc898e4fdf3a5ed9ed28e0f03f31
huggingface.co/imranlabs/sem-microstructure-segmentation/tree/61c03fb55cfbdc898e4fdf3a5ed9ed28e0f03f31

Verified Sep 27

Model artifacts

2 artifacts

checkpoints/best_model.pth

pth · 280 MB · SHA-256 d02de1af5ed7…134f · Hugging Face

Download

checkpoints/ScratchUNet_best_unet.pth

pth · 88.9 MB · SHA-256 c2aaf37e9136…1c57 · Hugging Face

Download

Source excerpts

2 excerpts

--- license: mit language: - en tags: - semantic-segmentation - pytorch - unet - resnet34 - materials-science - microscopy - sem - computer-vision - segmentation-models-pytorch datasets: - safdar/sem-ni-wc-metal-matrix-composites metrics: - mean_iou - dice library_name: segmentation_models_pytorch pipeline_tag: image-segmentation --- # SEM Microstructure Semantic Segmentation UNet with a pretrained ResNet-34 encoder for pixel-wise segmentation of Scanning Electron Microscopy (SEM) images of additively manufactured Ni-WC metal matrix composites. Trained to identify five microstructural phases at pixel level. ## Model Details | Property | Detail | |------------------|---------------------------------------------| | Architecture | UNet + ResNet-34 encoder | | Encoder weights | ImageNet pretrained | | Input channels | 1 (grayscale SEM image) | | Output classes | 5 (pixel-wise segmentation) | | Framework | PyTorch + segmentation_models_pytorch | | Training device | Apple MPS (M-series) | ## Classes | ID | Phase | |----|----------------| | 0 | Matrix | | 1 | Carbide | | 2 | Void | | 3 | Reprecipitate | | 4 | Dilution Zone | ## Test Performance Evaluated on 54 held-out test images, scored at image level to avoid batch-size bias. | Metric | Mean | Std | Min | Max | |--------|-------|-------|-------|-------| | mIoU | 0.872 | 0.088 | 0.723 | 0.958 | | mDice | 0.912 | 0.079 | 0.759 | 0.978 | | mBF1 | 0.728 | 0.027 | 0.678 | 0.773 | ### Per-Class Performance | Class | IoU | Dice | |---------------|-------|-------| | Matrix | 0.939 | 0.969 | | Carbide | 0.753 | 0.859 | | Void | 0.976 | 0.988 | | Reprecipitate | 0.891 | 0.942 | | Dilution Zone | 0.881 | 0.937 | ## Files | File | Description | |----------------------------|------------------------------------| | `best_model.pth` | Best pretrained encoder checkpoint | | `ScratchUNet_best_unet.pth`| Best scratch-built UNet checkpoint | ## How to Use ### Install dependencies ```bash pip install torch segmentation-models-pytorch huggingface_hub ``` ### Load and run inference ```python import torch from huggingface_hub import hf_hub_download import segmentation_models_pytorch as smp # Download checkpoint ckpt_path = hf_hub_download( repo_id="imranlabs/sem-microstructure-segmentation", filename="best_model.pth" ) # Rebuild architecture model = smp.Unet( encoder_name = "resnet34", encoder_wei...

Source context: 0 downloads · 0 likes · Pipeline image-segmentation · Library segmentation_models_pytorch · Repo imranlabs/sem-microstructure-segmentation