This repository contains the paper Few-Shot Segmentation of Complex Microstructures: Minimizing Training Images by Maximizing Representativeness and Diversity by Bo Lei, Txai Sibley, and Elizabeth Holm.
The core idea is to reduce annotation cost for semantic segmentation of complex microstructures by selecting a small but informative set of training images. The proposed selection strategy, additively maximizing representativeness and diversity (AMRD), operates on unlabeled candidate images and favors samples that both represent the dataset well and cover uncommon morphologies.
AMRD follows the workflow described in the manuscript:
- Extract pixel-level hypercolumn features from the first three VGG16 convolutional blocks.
- Reduce feature dimensionality with PCA and build a visual vocabulary with KMeans.
- Encode each image with VLAD.
- Measure image similarity with cosine similarity between VLAD embeddings.
- Select images greedily by maximizing representativeness plus a weighted diversity term.
In the paper, smaller values of the diversity weight
The manuscript experiments focus on two datasets already organized under data/:
uhcs: 24 SEM images of ultrahigh carbon steel with four target classes.MetalDAM: 42 SEM images from additive manufacturing metallurgy with four target classes used in this study.
selection/: AMRD, random selection, hypercolumn encoding, and VLAD utilities.segmentation/: U-Net training, evaluation, configs, and checkpoints.experiments/: cross-validation runners, analysis scripts, and manuscript figure helpers.data/: images, labels, and split files.
Install the Python dependencies:
pip install -r requirements.txtThe repository assumes images, labels, and split files already exist under data/<dataset>/.
Common split formats used here are:
- text splits for fixed train/validation/test partitions, such as
train16A.txt,validate4A.txt, andtest4A.txtindata/uhcs/splits/ - CSV splits for cross-validation, such as
full_CV10.csvfor UHCS andfull_CV6.csvfor MetalDAM
Selection outputs are written back into data/<dataset>/splits/, and model checkpoints are saved under segmentation/checkpoints/<dataset>/<experiment>/.
The main selection entry point is selection/select_img.py.
Example: select 4 UHCS training images from the fixed 16-image candidate pool used in the manuscript.
python -m selection.select_img \
--dataset uhcs \
--split_file train16A.txt \
--n_select 4 \
--method amrd \
--amrd_lambda 0.1This writes the selected image list to:
data/uhcs/splits/amrd_lambda0.1_4-shot.txt
Useful arguments:
--dataset: dataset name such asuhcsorMetalDAM--split_file: text or CSV split file containing candidate images--n_select: number of images to select--method:amrdorrandom--amrd_lambda: diversity weight for AMRD--n_samples_per_image: number of sampled hypercolumns per image--pca_dim: PCA output dimension for VLAD construction--n_words: number of visual words--gpu_id: GPU index
The main training entry point is segmentation/train.py. Config files live under segmentation/configs/<dataset>/.
Example: train on the UHCS fixed split with the full 16-image training set.
python -m segmentation.train --dataset uhcs --config full_sup.yamlExample: train on the 4-shot AMRD-selected UHCS split.
python -m segmentation.train --dataset uhcs --config amrd_lambda0.1_4-shot.yamlFor full-supervised cross-validation:
python experiments/run_cv.py --dataset uhcs --config full_CV10.yaml -m train
python experiments/run_cv.py --dataset MetalDAM --config full_CV6.yaml -m trainFor selected-subset cross-validation using pre-generated selection configs:
python experiments/run_selected_cv.py --dataset uhcs --config select_CV10/amrd_lambda0.1_4-shot.yaml -m train
python experiments/run_selected_cv.py --dataset MetalDAM --config select_CV6/amrd_lambda0.5_4-shot.yaml -m trainIf you use this repository, please cite the manuscript and reference this codebase in your experimental setup description.