DSA vessel segmentation β nnU-Net 2D, ONNX
Binary cerebral-vessel segmentation for digital subtraction angiography (DSA) images. These are the five folds of a 2D nnU-Net v2 trained with a clDice loss, exported to ONNX (float32, unmodified weights) so they can run in a web browser with ONNX Runtime Web.
Try it in your browser: https://jctaylor666.github.io/dsa-vessel-seg-web/ β images are processed locally and never uploaded.
Research use only. Not a medical device.
Files
| file | what |
|---|---|
vessel_seg_fold{0..4}.onnx |
one fold each, fp32, ~185 MB |
model.json |
manifest the web app reads: patch size, file names, sizes, SHA-256 |
Each fold has the same graph:
| name | shape | dtype | |
|---|---|---|---|
| input | input |
[1, 1, 896, 768] |
float32, z-scored image patch (see below) |
| output | logits |
[1, 2, 896, 768] |
float32 logits for background, vessel |
Ops used: Conv, ConvTranspose, InstanceNormalization, LeakyRelu, Concat (opset 17).
Preprocessing and inference (identical to nnU-Net v2's predictor)
- Read the image as one 8-bit gray channel (H Γ W).
- Crop to the bounding box of non-zero pixels.
- Z-score the cropped image:
(x - mean) / max(std, 1e-8)over all its pixels. - Pad to at least 896 Γ 768 with zeros, split evenly before/after.
- Slide an 896 Γ 768 window at step 0.5 of the patch (nnU-Net's
compute_steps_for_sliding_window), weighting each tile by a Gaussian with Ο = patch / 8. - Optional mirroring test-time augmentation: average the logits of the 4 flips (axes 0, 1).
- Ensemble: average the logits of the folds you use.
- Softmax β vessel probability; vessel = probability > 0.5. Undo the padding and paste back into the crop box.
The browser implementation of these steps is
worker.js.
Minimal single-patch check in Python:
import numpy as np, onnxruntime as ort
s = ort.InferenceSession("vessel_seg_fold0.onnx")
x = np.zeros((1, 1, 896, 768), np.float32) # a z-scored patch
logits = s.run(None, {"input": x})[0] # (1, 2, 896, 768)
vessel = logits[0, 1] > logits[0, 0]
Model
- Framework: nnU-Net v2 (2.6.2), configuration
2d, plansnnUNetPlans, trainernnUNetTrainerClDice2D(Dice + CE + clDice loss); architecturePlainConvUNet, 8 stages, 32β512 features, InstanceNorm, LeakyReLU; 46.3 M parameters per fold; 5-fold cross-validation. - Weights:
checkpoint_final.pthof each fold, exported with PyTorch 2.3.1 (torch.onnx.export, opset 17).
Verification
- ONNX Runtime vs PyTorch on a real 896 Γ 768 patch (fold 0): max |Ξlogit| = 7.3e-3, argmax agreement 99.9999 %.
- Browser app (ONNX Runtime Web 1.31.1) vs nnU-Net's own
nnUNetPredictor, on one 791 Γ 1022 DSA frame:
| setting | backend | vessel px (browser / nnU-Net) | pixels that differ | time (Apple M-series laptop) |
|---|---|---|---|---|
| fold 0 | WebGPU | 59,193 / 59,191 | 2 | 1.1 s |
| fold 0 + mirroring | WebGPU | 57,064 / 57,064 | 0 | 3.2 s |
| fold 0 | CPU (WASM, 1 thread) | 59,207 / 59,191 | 22 | 22 s |
| 5 folds | WebGPU | 54,668 / 54,666 | 2 | 4.1 s |
| 5 folds + mirroring | WebGPU | 54,723 / 54,723 | 0 | 15.6 s |