Skip to content

Repository files navigation

DFCAN — PyTorch Implementation for Fluorescence Microscopy Super-Resolution

A clean, config-driven PyTorch re-implementation of DFCAN (Fourier Channel Attention Network) for biological image super-resolution on the BioSR dataset.
Supports 2×, 4×, and 8× upscaling on F-actin and other BioSR structures.


Background

DFCAN was originally proposed in:

Nat. Methods 2021Evaluation of deep learning strategies for nucleus segmentation in fluorescence images
Architecture reference: Wang et al., ECCV 2020 — Fourier Channel Attention Networks

This repository provides a from-scratch PyTorch port of DFCAN with a modular, config-based design. The original codebase was TensorFlow-based with hard-coded paths and deprecated APIs. This implementation is reproducible, system-independent, and built around YAML configs for easy scale/dataset switching.


Results

Trained on F-actin (SIM) from the BioSR dataset:

Scale MAE PSNR
0.0465 24.74 dB

Evaluated on the BioSR validation split. Training was run on Mac (CPU) with a limited iteration budget — results are from an early checkpoint and not fully converged.


Repository Structure

DFCAN_PyTorch/
│
├── configs/
│   ├── dfcan_2x.yaml        # Config for 2× super-resolution
│   ├── dfcan_4x.yaml        # Config for 4× super-resolution
│   └── dfcan_8x.yaml        # Config for 8× super-resolution
│
├── src/
│   ├── models/              # DFCAN network definition
│   ├── trainers/
│   │   └── train.py         # Training loop
│   └── inference/
│       └── evaluate.py      # Evaluation & inference
│
├── data_agmt_matlab/        # MATLAB scripts for BioSR LR-HR pair generation
├── dataset/                 # Dataset root (populated after MATLAB preprocessing)
├── checkpoints/             # Saved model checkpoints
│
├── train.sh                 # Training helper script
├── eval.sh                  # Evaluation helper script
├── infer.sh                 # Inference helper script
├── requirements.txt
└── README.md

Installation

git clone https://github.com/Jamijunky/DFCAN_PyTorch.git
cd DFCAN_PyTorch
pip install -r requirements.txt

Requirements: Python ≥ 3.8, PyTorch ≥ 1.12, torchvision, numpy, Pillow, PyYAML, tqdm, scikit-image, matplotlib


Dataset Preparation

This implementation uses the BioSR dataset (F-actin structure).

  1. Download BioSR from the official source.
  2. Run the MATLAB preprocessing script to generate LR-HR patch pairs:
% Inside MATLAB, from the repo root:
cd data_agmt_matlab
run generate_pairs.m

This populates dataset/train/ and dataset/val/ with LR-HR .tif pairs at your chosen scale factor.


Training

Via shell script (Linux/Mac):

./train.sh configs/dfcan_2x.yaml
./train.sh configs/dfcan_4x.yaml
./train.sh configs/dfcan_8x.yaml

Cross-platform (Windows compatible):

python -m src.trainers.train --config configs/dfcan_4x.yaml

Checkpoints are saved to checkpoints/dfcan_4x/ (or the path specified in the config). Training resumes automatically from the latest checkpoint if one exists.


Evaluation

./eval.sh configs/dfcan_4x.yaml checkpoints/dfcan_4x/best.pth test

Or manually:

python -m src.inference.evaluate \
  --config configs/dfcan_4x.yaml \
  --checkpoint checkpoints/dfcan_4x/best.pth \
  --split test

Reports MAE and PSNR on the specified split.


Inference

./infer.sh configs/dfcan_4x.yaml checkpoints/dfcan_4x/best.pth

Output .tif files are saved to the results directory defined in the config. Scientific .tif format is used throughout to preserve image fidelity (no lossy compression).


Config Structure

Each YAML config controls all training and inference parameters:

scale_factor: 4
input_channels: 1         # 1 for WF, 9 for SIM
patch_size: 128
batch_size: 4
max_iters: 12000
lr: 5.0e-5
lr_decay: 0.5

data:
  train_dir: dataset/train/F-actin
  val_dir: dataset/val/F-actin

checkpoint:
  save_dir: checkpoints/dfcan_4x
  save_interval: 500

results_dir: results/dfcan_4x

Key Design Decisions

Why PyTorch over the original TF code?
The original DFCAN repo used TensorFlow 1.x-era patterns with deprecated keras imports, hard-coded paths, and broken scikit-image metric calls (compare_psnr, compare_ssim were removed in scikit-image ≥ 0.19). This port modernises the full stack.

Why not directly scale to 4× or 8× from a 2× checkpoint?
Naively changing scale_factor without retraining causes the model to hallucinate structures at unlearned frequency bands — the network was never constrained against those artifacts. Each scale requires either its own training run or a properly staged recursive inference pipeline (2× → 4× → 8×), which is what infer.sh implements.

Config-driven design
All hyperparameters, paths, and scale factors live in YAML configs. No hard-coded values anywhere in the source.


Citation

If you use this code, please cite the original DFCAN paper:

@inproceedings{wang2020fourier,
  title     = {Fourier Channel Attention Networks},
  author    = {Wang, Zhendong and others},
  booktitle = {ECCV},
  year      = {2020}
}

And the BioSR dataset:

@article{chen2021three,
  title   = {Three-dimensional residual channel attention networks denoise and sharpen fluorescence microscopy image volumes},
  author  = {Chen, Joanna and others},
  journal = {Nature Methods},
  year    = {2021}
}

Author

Abdullah Jami
B.Tech (IT), IIIT Sonepat
Research conducted under Dr. Hazique Aetesam, Asst. Professor, CS&E, BIT Mesra (Oct 2025 – Feb 2026)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages