Skip to content

About

Efficient training and inference for Optimum-Path Forest Networks (OPFNets) in medical image classification.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OPFNet

Code for Efficient Graph-Based Metric Learning for Medical Image Classification (Aparco-Cardenas and Falcão, SIPAIM 2026).

OPFNet is a small CNN encoder + projector trained with a two-stage loss (triplet loss, then an Optimum-Path Forest (OPF) loss) and classified with a single-model OPF at inference time.

Structure

main.py               # CLI: builds data/model and runs the two-stage training
opfnet/
  model.py            # encoder + projector
  data.py             # Lab image dataset, loading from train/test file lists
  losses.py           # triplet mining and OPF-based loss
  sampling.py         # stratified sampling, OPF prototype selection
  trainer.py          # triplet-stage and OPF-stage epochs
  evaluate.py         # single-model OPF inference (balanced acc., macro F1)
opforch/              # bundled PyTorch OPF implementation (Apache 2.0, G. de Rosa)
data/                 # train/test file lists; eggs.tar.gz = eggs lists + images

Requirements

Python >= 3.12 and pip install -r requirements.txt. opforch is bundled and imported directly, so no installation is needed. Run everything from the repository root.

Data

Each dataset is read from data/<dataset>/<dataset>.{train,test}.csv, plain text lists with one image path per line.

  • eggs (Helminth eggs) is included as data/eggs.tar.gz (train/test lists + images). Extract it from the repository root:
    tar -xzf data/eggs.tar.gz -C data
  • larvae, protozoan: download the images from the intestinal parasite datasets of Suzuki et al. (2013) and place them in data/<dataset>/orig/.
  • brisc2025: download BRISC 2025 (Fateh et al., Scientific Data, 2026) and place the images in data/brisc2025/{train,test}/.

Usage

Pass the dataset name. The train and test sets are read from data/<dataset>/<dataset>.train.csv and data/<dataset>/<dataset>.test.csv:

python main.py --dataset eggs          # eggs, larvae, protozoan or brisc2025

Main options: --transition (last epoch of the triplet stage, default 30), --lr-tri / --lr (learning rate of each stage), --batch-size-opf, --embedding-size, --num-epochs. The model is evaluated on the test set after the last epoch only; use --test-interval N for additional evaluations every N epochs. Metrics go to TensorBoard (--tensorboard-root).

Acknowledgments

We thank Gustavo de Rosa for creating and sharing OPForch, the PyTorch implementation of Optimum-Path Forest on which our OPF decision layer is built. A minimal copy of it is bundled in opforch/ under its original Apache 2.0 license.

Citation

@inproceedings{aparco2026efficient,
  title     = {Efficient Graph-Based Metric Learning for Medical Image Classification},
  author    = {Aparco-Cardenas, David and Falc{\~a}o, Alexandre X.},
  booktitle = {SIPAIM},
  year      = {2026}
}

About

Efficient training and inference for Optimum-Path Forest Networks (OPFNets) in medical image classification.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages