Official code for the TPAMI paper "Coded Event Focal Stack for Continuous Refocusing in Dynamic Scene".
CEFS uses event streams and two boundary RGB frames to synthesize continuously refocused images in dynamic scenes. This repository contains the training code, evaluation code, real-data inference path, safe event preprocessing tools, and release documentation.
- Source code is released under Apache License 2.0.
- Model weights released by the authors are Apache-2.0 model assets.
- Datasets are not included in this repository. The CEFS DF-Motion companion dataset page is moonboat/cefs-df-motion.
- Legacy pretrained checkpoints are included under
checkpoints/legacy/.
conda create -n cefs python=3.12
conda activate cefs
pip install -r requirements.txtThe pinned environment was verified with Python 3.12 and CUDA-enabled PyTorch. If your CUDA runtime or platform differs, install a matching torch / torchvision pair before installing the remaining dependencies.
CEFS/
├── __main__.py # unified train / evaluation entry point
├── datasets/ # dataset loaders
├── modules/ # model definitions
├── trainer/ # training loops
├── test/ # evaluation and real-data inference
├── tools/ # safe preprocessing / visualization CLIs
├── scripts/ # portable launch-script templates
├── utils/ # options, logging, checkpoint, and shared utilities
├── docs/ # release, data, checkpoint, training, and evaluation notes
└── requirements.txt
The current evaluation and real-data inference paths use the legacy inference models in modules/legacy/.
Expected public checkpoint layout:
checkpoints/legacy/
├── cefs_legacy_inter_stack64.pth
└── cefs_legacy_focus_stack64.pth
These files are committed to this repository for the first release. See docs/checkpoints.md for architecture compatibility and SHA256 metadata.
Datasets are hosted outside the code repository. The CEFS DF-Motion companion dataset page is:
https://huggingface.co/datasets/moonboat/cefs-df-motion
Hugging Face files:
test/cefs_df_motion_test.tar.gz: DF-Motion test datatrain/scene_001_events.tar.gzandtrain/scene_001_aif.tar.gz: partial training assets for scene 1
The full 30-scene training split is not fully uploaded yet. Package it in smaller verified parts before public use.
Download:
huggingface-cli download moonboat/cefs-df-motion \
--repo-type dataset \
--local-dir data/cefs_df_motionThe main layouts expected by the current code are:
- real-data inference:
IMG/andevent_stacks_test_15/ - real-video inference:
IMG/andevent_stacks_video/ - simulation evaluation: scene folders with
events/0.npyandgt/ - training: scene folders with event, ground-truth, and optional all-in-focus targets
See docs/data_format.md for complete layout examples.
Show all command-line options:
python __main__.py --helpReal-data inference:
python __main__.py \
--mode exp \
--test_real \
--StackSize 64 \
--evs_ratio 5 \
--test_data_path /path/to/recording \
--ckpt_inter checkpoints/legacy/cefs_legacy_inter_stack64.pth \
--ckpt_focus checkpoints/legacy/cefs_legacy_focus_stack64.pthSynthetic evaluation:
CKPT_INTER=checkpoints/legacy/cefs_legacy_inter_stack64.pth \
CKPT_FOCUS=checkpoints/legacy/cefs_legacy_focus_stack64.pth \
DATA_PATH=/path/to/synthetic \
OUTPUT_PATH=artifacts/output/synthetic \
bash scripts/eval_synthetic.shCamera-shake evaluation:
CKPT_INTER=checkpoints/legacy/cefs_legacy_inter_stack64.pth \
CKPT_FOCUS=checkpoints/legacy/cefs_legacy_focus_stack64.pth \
DATA_PATH=/path/to/camera_shake \
OUTPUT_PATH=artifacts/output/camera_shake \
bash scripts/eval_camerashake.shTraining scripts are provided as templates under scripts/. They use repo-relative defaults and can be configured through environment variables. See docs/training.md for the script-to-dataset mapping.
Generate event stacks from raw event text files:
python tools/make_event_stack.py \
--input /path/to/recording \
--height 720 \
--width 1280 \
--stack-size 64 \
--sweep-frames 12 \
--start 480Visualize event text or stack files:
python tools/visualize_events.py \
--input /path/to/events.txt \
--height 720 \
--width 1280 \
--output /path/to/events.pngUse --sweep-frames 12 for 24 fps real-data recordings and --sweep-frames 15 for 30 fps recordings. Generated outputs are not overwritten by default; pass --overwrite explicitly to replace existing files.
Run the release-surface checks:
python __main__.py --help
bash -n scripts/*.sh
python tools/make_event_stack.py --help
python tools/visualize_events.py --help
python -m py_compile $(find . -path './.git' -prune -o -path './artifacts' -prune -o -name '*.py' -print)These checks do not require datasets or checkpoints.
docs/checkpoints.md: checkpoint families, metadata, and compatibility notesdocs/data_format.md: expected event, stack, real-data, simulation, and training layoutsdocs/evaluation.md: evaluation entry points and metric outputsdocs/huggingface_dataset.md: DF-Motion dataset release and upload notesdocs/training.md: training scripts and dataset assumptionsdocs/reproduction.md: minimal reproduction notesdocs/release_audit.md: release-readiness audit
@article{teng2026coded,
title = {Coded Event Focal Stack for Continuous Refocusing in Dynamic Scene},
author = {Teng, Minggui and Xuan, Suhang and Yan, Zhiang and Lou, Hanyue and Li, Boyu and Fan, Bin and Shi, Boxin},
journal = {IEEE Transactions on Pattern Analysis and Machine Intelligence},
volume = {48},
number = {6},
pages = {7147--7160},
year = {2026},
doi = {10.1109/TPAMI.2026.3664082}
}Source code is released under the Apache License 2.0. Author-released model weights are Apache-2.0 model assets. Datasets are distributed separately from the code repository.