SegRef3D

TrainRef3D inference interchange v1.0

InferRef3D completes the browser-local human-in-the-loop path:

SegRef3D masks → Training ZIP → TrainRef3D model
        → Inference Request + Model ZIP → InferRef3D prediction
        → SegRef3D review/correction → Training ZIP

This MVP accepts only trainref3d-model-1.0 binary MONAI 3D UNet models with one scalar channel or three ordered R/G/B channels. No browser executes model.pt. Model/request/result validation and prediction import are browser-local; Colab transfer happens only when the user explicitly uploads files to their own runtime.

Model ZIP trust boundary

TrainRef3D_Model_TR3DM_<id>.zip has exactly:

model.pt
model_manifest.json
training_history.csv
validation_metrics.csv
README.txt

Lite validates safe paths, members and model_manifest.json, then retains the whole-archive SHA-256. It does not parse weights. InferRef3D independently validates the archive and loads only a trusted {state_dict, architecture_config} checkpoint via torch.load(..., weights_only=True). Checkpoint and manifest architecture configs must be equal.

Inference Request ZIP

Filename: TrainRef3D_Inference_Request_TR3DI_<id>.zip Format: trainref3d-inference-request-1.0

request_manifest.json
model/model_manifest.json
input/TR3DI_<id>_0000.nii[.gz]
input/TR3DI_<id>_0001.nii[.gz]   # RGB only
input/TR3DI_<id>_0002.nii[.gz]   # RGB only

model.pt is intentionally not duplicated. request_manifest.json records:

The source fingerprint is the ordered SHA-256 list of deterministic canonical NIfTI channel bytes, not display pixels. The canonical encoder is shared with Training Data export: original scalar NIfTI bytes are reused when geometry is unchanged; DICOM scalar values use stored value × slope + intercept; raster working-grid grayscale or R/G/B values are encoded deterministically. Rebuilding the same canonical bytes on result import prevents accidental import to a different same-shaped case.

Preprocessing and geometry

The model manifest is the source of truth. v1.0 accepts only the recorded TrainRef3D contract:

The full input remains CPU-side while sliding-window patches may use CUDA/AMP. The target-grid binary prediction is nearest-neighbor resampled with nibabel to (original_shape, original_affine). This geometry-aware inverse supports oblique affine, anisotropic spacing and non-zero origin. Class 1 becomes the model’s original target_label_id; it is never silently changed to Obj 1.

Inference Result ZIP

Filename: TrainRef3D_Inference_Result_TR3DI_<request-id>.zip Format: trainref3d-inference-result-1.0

prediction.nii.gz
inference_result.json
README.txt

The result includes no source image and no weights. Its manifest records success/request ID; model ID/hash/target; source channel count/category/fingerprints/original geometry; prediction file/hash/uint8 labels/foreground count/geometry; architecture, exact preprocessing and sliding-window settings; device and optional peak GPU memory; Python/torch/MONAI/CUDA versions; backend source SHA-256; and privacy declarations.

Creating an Inference Request requires a compatible Model ZIP. Importing a Result ZIP does not. Lite rejects a result unless ordered source fingerprints, channel count, prediction hash, uint8 datatype, label values (0 or target only), shape, spacing, affine, origin, orientation and declared original geometry agree with the current source. These errors cannot be overridden. The Result ZIP supplies the model ID/hash and target Obj ID/name. With a Model ZIP loaded, identity/hash/target/input and preprocessing are additionally compared; differences produce a warning requiring explicit confirmation, after all hard checks pass. Without a Model ZIP, the same confirmation shows result provenance and the source/geometry matches before import. Cancel leaves masks unchanged. Replace clears only the target Obj before applying foreground; Merge retains it and fills background. Both skip voxels occupied by another Obj and report the count. The whole import uses one existing bulk Undo transaction. A default Object X name may adopt the model target name; a user custom name is never overwritten.

Safety and limitations

ZIP traversal, duplicate/overlapping paths, symlinks, encrypted/unsupported members, undeclared files and bounded-expansion violations are rejected at both browser and Python boundaries. DICOM headers are not included, but pixels/voxels can contain burned-in text, facial or unique anatomy. Users must follow institutional rules before Colab upload.

Only binary MONAI UNet inference is implemented. There is no multiclass model, ONNX, nnU-Net, browser PyTorch, automatic upload, cloud inference service, automatic retraining or clinical deployment. A prediction is algorithmic output for expert review and correction, not an independent clinical diagnosis.