How gihankaushyal/hit_finder works
Purpose and Entry Points
This is a Python/PyTorch research pipeline for detector-agnostic SFX hit classification across AGIPD, JUNGFRAU, ePix10k, and Eiger4M. Primary executable training entry points are src/training/train_supervised.py, src/training/train_ssl_pretrain.py, and src/training/train_ssl_finetune.py; experiment selection is YAML-driven under configs/.
Input and Detector Boundary
Raw HDF5/CXI data and pre-assembled .img files enter through detector-aware I/O. Detector identity is read from metadata, not image appearance. src/preprocessing/io.py loads formats; src/preprocessing/geometry.py applies detector-specific geometry assets such as src/preprocessing/data/agipd.geom and src/preprocessing/data/epix10k.geom. Reborn is the material external geometry/assembly dependency; Fabio supports .img.
Shared Preprocessing Contract
src/preprocessing/pipeline.py orchestrates the invariant preprocessing sequence: assemble detector panels, compute global contrast normalization on the full assembled frame, then crop/tile patches and apply local normalization. src/preprocessing/normalize.py implements GCN/LCN; src/preprocessing/augment.py applies training augmentation and peak-aware cutout. The critical boundary is that 224×224 patches are cropped, never resized, and GCN precedes all crops.
Hitfinding and Patch Label Generation
The hitfinder subsystem detects Bragg-peak centroids used to create reliable patch labels rather than assigning a frame label to arbitrary crops. It exposes interchangeable implementations through src/hitfinders/base.py, with CPU PF8 paths in src/hitfinders/pf8.py and src/hitfinders/numpy_pf8.py, plus GPU paths in src/hitfinders/gpu.py and src/hitfinders/gpu_pf8.py. A compiled PF8 wrapper is available in src/hitfinders/_pf8_wrap.c.
Dataset and Training Data Flow
src/data/dataset.py and src/data/dataloader.py bridge preprocessed frames into PyTorch batches. The asymmetric supervised path samples positive crops centered on hitfinder centroids and hard-negative crops kept away from peaks; both are augmented after cropping. src/data/synthetic.py supplies synthetic-data support. Data is expected under data/raw, data/processed, data/splits, and data/synthetic.
Model Tracks
The supervised baseline is defined in src/models/supervised.py and trained by src/training/train_supervised.py, using configurable ResNet variants including configs/supervised/resnet18_asymmetric.yaml and configs/supervised/resnet50.yaml. The SSL track is defined in src/models/ssl.py: MAE/ViT pretraining on unlabeled frames is run by src/training/train_ssl_pretrain.py, followed by labeled classification fine-tuning in src/training/train_ssl_finetune.py. PyTorch 2.x and timm are core runtime dependencies.
Evaluation and Compute
src/evaluation/benchmark.py performs cross-detector, leave-one-detector-out evaluation; src/evaluation/metrics.py calculates classification metrics. Evaluation tiles full frames into 224×224 patches, scores patches, and aggregates patch votes into frame predictions. The intended execution platform is ASU Sol HPC with CUDA GPUs and SLURM; submission workflows are represented by scripts/submit_all_lodo_folds.sh, scripts/submit_ssl_pretrain.sh, and scripts/templates/slurm_gpu_job.sh.
Main entry points: dataset.py Asymmetric patch dataset · pipeline.py Preprocessing pipeline · base.py Hitfinder interface · dataloader.py PyTorch dataloader
Components 19
Input & preprocessing
Detector-aware frame assembly and patch preparation.
- Raw frames · Raw, processed, split, and synthetic datasets.
data/raw - Detector I/O · Reads detector metadata and supported frame formats.
src/preprocessing/io.py - Geometry assembly · Applies detector-specific panel geometry via Reborn.
src/preprocessing/geometry.py - Preprocessing pipeline · Assembles frames, applies GCN, then crops 224×224 patches and LCN.
src/preprocessing/pipeline.py - Augmentation · Applies training augmentation and peak-aware cutout after cropping.
src/preprocessing/augment.py
Hitfinding
Peak centroids drive reliable crop labels.
- Hitfinder interface · Interchangeable peak-centroid detection implementations.
src/hitfinders/base.py - PF8 CPU · Python, NumPy, and compiled PF8 paths.
src/hitfinders/pf8.py - PF8 GPU · GPU peak detection path.
src/hitfinders/gpu_pf8.py
Training data
Patch sampling and PyTorch batching.
- Asymmetric patch dataset · Centers positives on peaks and keeps hard negatives away from peaks.
src/data/dataset.py - PyTorch dataloader · Builds training and evaluation batches.
src/data/dataloader.py - Synthetic data
src/data/synthetic.py
Model tracks
Supervised and self-supervised classifiers.
- ResNet classifier · Configurable supervised ResNet variants.
src/models/supervised.py - Supervised training · YAML-selected baseline training.
src/training/train_supervised.py - MAE/ViT SSL · MAE/ViT pretraining and classification fine-tuning model.
src/models/ssl.py - SSL pretraining · Trains on unlabeled frames.
src/training/train_ssl_pretrain.py - SSL fine-tuning · Fine-tunes SSL representations with labels.
src/training/train_ssl_finetune.py
Evaluation & compute
Cross-detector benchmarking and cluster execution.
- LODO benchmark · Tiles frames, scores patches, and aggregates patch votes.
src/evaluation/benchmark.py - Classification metrics
src/evaluation/metrics.py - SLURM GPU jobs · ASU Sol CUDA submission workflows.
scripts/submit_all_lodo_folds.sh
Connections 22
- Raw frames → Detector I/O: loads
- Detector I/O → Geometry assembly: detector metadata
- Geometry assembly → Preprocessing pipeline: assembled frame
- Preprocessing pipeline → Hitfinder interface: full frame
- Hitfinder interface → PF8 CPU: CPU implementation
- Hitfinder interface → PF8 GPU: GPU implementation
- Preprocessing pipeline → Asymmetric patch dataset: cropped patches
- Hitfinder interface → Asymmetric patch dataset: peak centroids
- Augmentation → Asymmetric patch dataset: post-crop augmentation
- Synthetic data → Asymmetric patch dataset: optional samples
- Asymmetric patch dataset → PyTorch dataloader: labeled patches
- PyTorch dataloader → Supervised training: batches
- Supervised training → ResNet classifier: trains
- Preprocessing pipeline → SSL pretraining: unlabeled frames
- SSL pretraining → MAE/ViT SSL: pretrains
- MAE/ViT SSL → SSL fine-tuning: initializes
- PyTorch dataloader → SSL fine-tuning: labeled batches
- ResNet classifier → LODO benchmark: patch scores
- MAE/ViT SSL → LODO benchmark: patch scores
- LODO benchmark → Classification metrics: frame predictions
- SLURM GPU jobs → Supervised training: submits jobs
- SLURM GPU jobs → SSL pretraining: submits jobs