dwei commited on
Commit
a88ce35
Β·
verified Β·
1 Parent(s): 2c98f6c

Add ONNX export (opset 17, fixed [48,96,96] window) + card section

Browse files
Files changed (2) hide show
  1. README.md +34 -1
  2. affinity_scratch_48x96x96.onnx +3 -0
README.md CHANGED
@@ -17,7 +17,7 @@ tags:
17
 
18
  | | |
19
  |---|---|
20
- | File | `affinity_scratch_48x96x96.ckpt` (247 MB) |
21
  | Architecture | MedNeXt-L, kernel 3 (61.8 M parameters) |
22
  | Input / output | 1 channel EM β†’ 6 channel affinity (`banis+`; channels 0–2 are the nearest-neighbour affinity used downstream) |
23
  | Training patch | `[48, 96, 96]` (ZYX) β€” anisotropic, β‰ˆ isotropic in nm for the 9Γ—9Γ—20 nm grid |
@@ -80,6 +80,39 @@ checkpoint is the "scratch" affinity in that table:
80
  Affinity quality alone is not what these numbers measure β€” see the tutorial for the
81
  decode and error-correction steps that produce them.
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  ## Checkpoint format
84
 
85
  A PyTorch Lightning checkpoint (`state_dict` keys are prefixed `model.model.`). Optimizer
 
17
 
18
  | | |
19
  |---|---|
20
+ | Files | `affinity_scratch_48x96x96.ckpt` (247 MB) Β· `affinity_scratch_48x96x96.onnx` (247 MB, opset 17) |
21
  | Architecture | MedNeXt-L, kernel 3 (61.8 M parameters) |
22
  | Input / output | 1 channel EM β†’ 6 channel affinity (`banis+`; channels 0–2 are the nearest-neighbour affinity used downstream) |
23
  | Training patch | `[48, 96, 96]` (ZYX) β€” anisotropic, β‰ˆ isotropic in nm for the 9Γ—9Γ—20 nm grid |
 
80
  Affinity quality alone is not what these numbers measure β€” see the tutorial for the
81
  decode and error-correction steps that produce them.
82
 
83
+ ## ONNX
84
+
85
+ `affinity_scratch_48x96x96.onnx` is the same weights exported for runtimes without PyTorch.
86
+
87
+ ```python
88
+ import numpy as np, onnxruntime as ort
89
+
90
+ session = ort.InferenceSession("affinity_scratch_48x96x96.onnx",
91
+ providers=["CPUExecutionProvider"])
92
+ image = np.random.randn(1, 1, 48, 96, 96).astype(np.float32) # (B, C, Z, Y, X)
93
+ logits = session.run(["logits"], {"image": image})[0] # (B, 6, 48, 96, 96)
94
+ affinity = 1.0 / (1.0 + np.exp(-0.2 * logits)) # scale_sigmoid, temperature 0.2
95
+ ```
96
+
97
+ Three things the graph does **not** do for you:
98
+
99
+ - **The activation.** The output is raw logits. The pipeline applies `scale_sigmoid` with
100
+ BANIS' temperature 0.2 β€” `sigmoid(0.2 * x)` β€” downstream, and step 2's watershed thresholds
101
+ are calibrated against that.
102
+ - **Channel selection.** Six channels are emitted; the decode consumes channels 0–2.
103
+ - **Sliding-window assembly.** One window in, one window out. Tiling, overlap and blending
104
+ are the caller's job.
105
+
106
+ The spatial dims are fixed at `[48, 96, 96]` and only the batch axis is dynamic β€” see the
107
+ window section above for why a dynamic spatial axis would be a trap here. Deep supervision is
108
+ switched off in the export, so the graph has a single output.
109
+
110
+ Verified against PyTorch on identical input: max |diff| 2.2e-04 on logits spanning
111
+ [1.03, 21.17] (relative 1.0e-05), which is **4.6e-06** after `scale_sigmoid` β€” float32
112
+ accumulation noise, not a behavioural difference. Regenerate with
113
+ `python scripts/export_onnx.py --config tutorials/neuron_j0126/1_affinity_supervised.yaml
114
+ --checkpoint <ckpt> --output model.onnx --check`.
115
+
116
  ## Checkpoint format
117
 
118
  A PyTorch Lightning checkpoint (`state_dict` keys are prefixed `model.model.`). Optimizer
affinity_scratch_48x96x96.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:783d9970d185f7f7211e5a62c4802cf1b6799022c6804e2bcbcf0d5a2c15a0b0
3
+ size 247520493