DGN Model Bundle Notes¶
This document records the trained DGN assets that HemiSpec should deploy for inference. Model training is not part of HemiSpec v1.
Scope¶
train_code/ is reference material only. Use it to understand:
- the
Generatorarchitecture, - the PyTorch checkpoint format,
- the corrected hemisphere crop convention,
- how generated hemisphere patches are pasted back for inspection.
Do not expose training as a user-facing feature in v1, and do not require users
to run train_code/train.py.
Current Local Assets¶
Reference-only training code:
These files are not imported by the public API, CLI, or GUI. They document the origin of the deployed runtime architecture and crop conventions.
Trained model output folders:
outputs_bi_stable_L/
ckpts/
best_netG_L.pth
netG_L.pth
metrics.csv
outputs_bi_stable_R/
ckpts/
best_netG_R.pth
netG_R.pth
metrics.csv
recon/
The inference adapter should load Generator checkpoints, not Discriminator checkpoints.
Direction Mapping¶
Use this owner-confirmed mapping in API, CLI, GUI, and documentation:
outputs_bi_stable_L = R_to_L = right hemisphere -> generated left hemisphere
outputs_bi_stable_R = L_to_R = left hemisphere -> generated right hemisphere
The current copied checkpoint folders use target-side names:
assets/models/dgn/outputs_bi_stable_L/ckpts/best_netG_L.pth
assets/models/dgn/outputs_bi_stable_R/ckpts/best_netG_R.pth
Future checkpoint exports may use explicit direction names:
assets/models/dgn/outputs_bi_stable_L/ckpts/best_netG_R2L.pth
assets/models/dgn/outputs_bi_stable_R/ckpts/best_netG_L2R.pth
discover_local_dgn_bundles() supports both conventions and prefers explicit
direction names when both exist.
Runtime Contract¶
The package-owned inference adapter should:
- Load a full preprocessed
*_GM_masked.nii.gzNIfTI. - Crop the source hemisphere.
- Run the matching trained
Generatorcheckpoint. - Paste the generated patch into the target hemisphere location.
- Save a reconstructed full-volume GM map with the original affine/header.
For a bilateral reconstructed map, run both directions and paste both generated hemispheres into one output volume.
Checkpoint Format¶
Generator checkpoints are PyTorch files with this shape:
The reference Generator expects a single-channel 3D hemisphere patch and
returns a single-channel generated hemisphere patch. The patch shape is:
Crops¶
Use the corrected anatomical convention:
The runtime adapter owns these constants in package code rather than importing
train_code directly.
Thresholds¶
The reference dataset code masks low-valued voxels before inference with:
ANS/RNS computation later uses:
Keep these thresholds separate in parameter names and documentation.
Output Naming¶
The final reconstructed output filename convention still needs to be chosen. Recommended v1 convention:
For compatibility with old scripts, keep support for: