SSFA stands for Self-Supervised Functional Analysis.
SSFA is a self-supervised pipeline for neuron extraction on single-photon (1p) calcium videos. The repository contains:
- Original BG rejection + segmentation scripts in
codes/ - A Hydra orchestration layer in
src/andconfigs/ - A Gradio web UI in
webapp/
Using Conda:
conda env create -f environment.yaml
conda activate ssfaOr with pip:
pip install -r requirements.txtOptional runtime env defaults:
cp .env.example .envPlace TIFF stacks in datasets/dataset_orig with numeric file names:
datasets/
└── dataset_orig/
├── 1.tiff
├── 2.tiff
└── ...
Main entrypoint:
python src/pipeline.py task=<task_name>Supported tasks:
bg_cropbg_trainbg_inferbg_postseg_cropseg_trainseg_inferseg_postvisualizeinfer_full
End-to-end inference:
python src/pipeline.py \
task=infer_full \
pipeline.input_dir=./datasets/dataset_orig \
pipeline.output_dir=./output/pipeline_outputBG training:
python src/pipeline.py task=bg_train bg.train.gsize=8 bg.train.epochs=50Segmentation training:
python src/pipeline.py task=seg_train seg.train.gsize=8 seg.train.epochs=100Inspect composed config:
python src/pipeline.py task=infer_full --cfg job
python src/pipeline.py task=bg_train --cfg job
python src/pipeline.py task=seg_train --cfg jobHydra config groups exposed in configs/:
paths.*pipeline.*bg.*seg.*webui.*hydra.*
The Hydra runner includes compatibility shims for modern PyTorch and legacy checkpoints:
- Forces legacy
torch.load(..., weights_only=False)behavior via environment - Auto-converts DataParallel checkpoints (
module.*) into single-device compatible temporary checkpoints during inference
Defaults:
- BG checkpoint:
./output/BG_output/checkpoint.pth - Seg checkpoint:
./output/SEG_output/checkpoint.pth
Hydra web UI entrypoint:
python src/webui.py webui.port=7860 webui.device=0 webui.device_type=autoThen open:
http://localhost:7860
The web UI accepts MP4/TIFF input, runs full SSFA inference, and exports:
- Full ZIP bundle
- Background TIFF
- Background-rejected TIFF
- Segmentation TIFF
- Temporal traces MAT
- Manifest JSON
webui.device_type options:
auto(default): uses CUDA if available, otherwise CPUcudacpu
./webapp/launch.sh 0This repository ships local SSFA Fiji/DeepImageJ plugin bundles in Plugin/:
Plugin/rmbg_plugin.zip: background rejection model packagePlugin/segmentation_plugin.zip: segmentation model package
If you clone this repository on a new machine, fetch plugin artifacts first:
git lfs install
git lfs pull --include "Plugin/*.zip"Install and run:
unzip Plugin/rmbg_plugin.zip -d Plugin/
unzip Plugin/segmentation_plugin.zip -d Plugin/In Fiji (with DeepImageJ installed):
- Open
Plugins -> DeepImageJ -> Run. - Select one plugin descriptor:
Plugin/rmbg_plugin/rdf.yamlPlugin/segmentation_plugin/rdf.yaml
Keep each extracted plugin folder intact because rdf.yaml references local assets (for example General.jar and fiji.pt) by relative path.
Original scripts remain unchanged in codes/ and can still be called directly, for example:
python -u ./codes/BG_Rejection/infer.py ...
python -u ./codes/Segmentation/infer.py ...
python -u ./codes/Segmentation/postprocessing.py ...The Hydra layer is orchestration-only and preserves existing compute paths for parity.
For task=infer_full, default staged outputs are:
output/pipeline_output/bg_stage/output/pipeline_output/seg_stage/output/pipeline_output/final_output/
- Input videos for the inference scripts should contain at least 128 frames for temporal patching.
- Web UI runtime folders (
webapp/jobs/,webapp/jobs_full_test/) are generated on demand and ignored by git. - Plugin zip artifacts are tracked with Git LFS.


