Block-level ResidualEncoderUNet.yml + clean-key checkpoint (forward-exact 0.0)
Browse files- body/Body.pt +2 -2
- body/Prediction.yml +1 -33
- body/ResidualEncoderUNet.yml +263 -0
body/Body.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ba1c39f84a6128e6813e17f0f193330719fdb91a4d1aa77dce0c920cff78b4d2
|
| 3 |
+
size 47390541
|
body/Prediction.yml
CHANGED
|
@@ -1,39 +1,7 @@
|
|
| 1 |
Predictor:
|
| 2 |
Model:
|
| 3 |
-
classpath:
|
| 4 |
ResidualEncoderUNet:
|
| 5 |
-
dim: 2
|
| 6 |
-
in_channels: 5
|
| 7 |
-
n_stages: 6
|
| 8 |
-
features_per_stage:
|
| 9 |
-
- 24
|
| 10 |
-
- 48
|
| 11 |
-
- 96
|
| 12 |
-
- 192
|
| 13 |
-
- 256
|
| 14 |
-
- 256
|
| 15 |
-
strides:
|
| 16 |
-
- 1
|
| 17 |
-
- 2
|
| 18 |
-
- 2
|
| 19 |
-
- 2
|
| 20 |
-
- 2
|
| 21 |
-
- 2
|
| 22 |
-
n_blocks_per_stage:
|
| 23 |
-
- 1
|
| 24 |
-
- 2
|
| 25 |
-
- 2
|
| 26 |
-
- 3
|
| 27 |
-
- 3
|
| 28 |
-
- 3
|
| 29 |
-
n_conv_per_stage_decoder:
|
| 30 |
-
- 1
|
| 31 |
-
- 1
|
| 32 |
-
- 1
|
| 33 |
-
- 1
|
| 34 |
-
- 1
|
| 35 |
-
num_classes: 12
|
| 36 |
-
deep_supervision: false
|
| 37 |
outputs_criterions: None
|
| 38 |
Dataset:
|
| 39 |
groups_src:
|
|
|
|
| 1 |
Predictor:
|
| 2 |
Model:
|
| 3 |
+
classpath: ResidualEncoderUNet.yml
|
| 4 |
ResidualEncoderUNet:
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Declarative KonfAI ResidualEncoderUNet -- weight-exact with nnU-Net's ResEnc U-Net.
|
| 2 |
+
#
|
| 3 |
+
# This graph reproduces, block-for-block and in forward-execution order, the
|
| 4 |
+
# reference `dynamic_network_architectures.architectures.unet.ResidualEncoderUNet`
|
| 5 |
+
# (the nnU-Net "ResEnc" backbone -- e.g. the ImpactSeg body model). It is the
|
| 6 |
+
# residual-encoder counterpart of `PlainConvUNet.yml`: the DECODER is identical
|
| 7 |
+
# (nnU-Net shares `UNetDecoder` between the two backbones), only the encoder
|
| 8 |
+
# differs. Because the weighted leaves execute in exactly the same sequence as
|
| 9 |
+
# the reference, a REAL ResEnc nnU-Net checkpoint of this topology loads straight
|
| 10 |
+
# into this KonfAI model through the execution-order bridge
|
| 11 |
+
# `konfai.utils.pretrained.transfer_weights_by_execution_order`, and the KonfAI
|
| 12 |
+
# logits are `torch.allclose` with the reference output (see
|
| 13 |
+
# tests/unit/test_residualencoderunet_yaml.py, which transfers the parametric
|
| 14 |
+
# ResidualEncoderUNet's weights in and checks maxdiff < 1e-4).
|
| 15 |
+
#
|
| 16 |
+
# It is authored at the STAGE level from two generic, registry-backed composite
|
| 17 |
+
# blocks -- so the whole ~20-node graph reads as the architecture's topology,
|
| 18 |
+
# not a conv-by-conv unroll:
|
| 19 |
+
#
|
| 20 |
+
# * `ResidualStage` = one encoder resolution stage: a stack of `n_blocks`
|
| 21 |
+
# nnU-Net ResNet-D `ResidualBlockD`. Its FIRST block carries the stage stride
|
| 22 |
+
# (strided-conv downsampling; stage 0 keeps stride 1 = full resolution) and
|
| 23 |
+
# the channel change; the rest are stride 1. A stride-only stage (channels
|
| 24 |
+
# unchanged, e.g. 256->256) uses the avgpool residual skip and carries no
|
| 25 |
+
# projection weights.
|
| 26 |
+
# * `DecoderStage` = one decoder resolution stage, a TWO-input node
|
| 27 |
+
# `in_branch: [coarser, skip]`: ConvTranspose(kernel = stride = the matching
|
| 28 |
+
# encoder stride) on the coarser feature, concat of the encoder skip
|
| 29 |
+
# (transpose output FIRST, then skip), then `n_conv` decoder conv blocks
|
| 30 |
+
# mapping 2*skip -> skip. Each conv block is Conv -> InstanceNorm(affine=True)
|
| 31 |
+
# -> LeakyReLU(0.01), conv_bias=True -- byte-for-byte nnU-Net's signature.
|
| 32 |
+
#
|
| 33 |
+
# The ImpactSeg "body" topology (the default parameters below): a 6-stage ResEnc
|
| 34 |
+
# with feature widths [24, 48, 96, 192, 256, 256], strides [1, 2, 2, 2, 2, 2],
|
| 35 |
+
# n_blocks_per_stage [1, 2, 2, 3, 3, 3], one conv per decoder stage, a 5-channel
|
| 36 |
+
# 2D input and 12 output classes. The single 1x1 seg head emits RAW LOGITS at
|
| 37 |
+
# full resolution (deep_supervision=False -- what nnU-Net returns), which is the
|
| 38 |
+
# weight-exact comparison point.
|
| 39 |
+
#
|
| 40 |
+
# ANISOTROPIC STRIDES/KERNELS: `strides` and `kernel_sizes` accept BOTH isotropic
|
| 41 |
+
# ints AND per-axis lists per stage (e.g. [1, 2, 2]), passed straight through to
|
| 42 |
+
# the convs and the transpose, so real anisotropic ResEnc plans load unchanged.
|
| 43 |
+
#
|
| 44 |
+
# FIXED DEPTH: a declarative YAML cannot loop, so the 6 encoder + 5 decoder stages
|
| 45 |
+
# are structural. To load a checkpoint of a different depth, replicate the stage
|
| 46 |
+
# pattern below (the wiring is identical at every depth); feature widths, strides,
|
| 47 |
+
# block counts, kernels, dim, in_channels and class count stay parametric.
|
| 48 |
+
#
|
| 49 |
+
# Use it as a KonfAI model classpath:
|
| 50 |
+
# classpath: default|ResidualEncoderUNet.yml # shipped catalog copy
|
| 51 |
+
# classpath: /path/to/ResidualEncoderUNet.yml # any local copy
|
| 52 |
+
# overriding `dim` / `in_channels` / `features_per_stage` / `strides` /
|
| 53 |
+
# `n_blocks_per_stage` / `n_conv_per_stage_decoder` / `num_classes` through the
|
| 54 |
+
# model `parameters`.
|
| 55 |
+
name: ResidualEncoderUNet
|
| 56 |
+
|
| 57 |
+
parameters:
|
| 58 |
+
dim: 2
|
| 59 |
+
in_channels: 5
|
| 60 |
+
# Encoder feature width per stage; the last entry is the bottleneck. Stage 5
|
| 61 |
+
# keeps 256->256 (stride-only), which uses the avgpool residual skip.
|
| 62 |
+
features_per_stage: [24, 48, 96, 192, 256, 256]
|
| 63 |
+
# Per-stage stride. Entry 0 is the full-resolution stage (stride 1). Each entry
|
| 64 |
+
# may be an int (isotropic) or a per-axis list (anisotropic, e.g. [1, 2, 2]).
|
| 65 |
+
strides: [1, 2, 2, 2, 2, 2]
|
| 66 |
+
# Residual blocks stacked per encoder stage (first carries the stride).
|
| 67 |
+
n_blocks_per_stage: [1, 2, 2, 3, 3, 3]
|
| 68 |
+
# Decoder conv blocks per stage (nnU-Net's n_conv_per_stage_decoder).
|
| 69 |
+
n_conv_per_stage_decoder: [1, 1, 1, 1, 1]
|
| 70 |
+
num_classes: 12
|
| 71 |
+
kernel_size: 3
|
| 72 |
+
conv_bias: true
|
| 73 |
+
negative_slope: 0.01
|
| 74 |
+
|
| 75 |
+
network:
|
| 76 |
+
in_channels: ${in_channels}
|
| 77 |
+
dim: ${dim}
|
| 78 |
+
|
| 79 |
+
modules:
|
| 80 |
+
# ----- Stem: one non-strided conv block (never downsamples), 5 -> 24 ---------
|
| 81 |
+
- name: Stem
|
| 82 |
+
type: ConvBlock
|
| 83 |
+
in_branch: [0]
|
| 84 |
+
out_branch: [stem]
|
| 85 |
+
args:
|
| 86 |
+
dim: ${dim}
|
| 87 |
+
in_channels: ${in_channels}
|
| 88 |
+
out_channels: ${features_per_stage.0}
|
| 89 |
+
block_configs:
|
| 90 |
+
- $object: BlockConfig
|
| 91 |
+
args:
|
| 92 |
+
kernel_size: ${kernel_size}
|
| 93 |
+
stride: 1
|
| 94 |
+
padding: 1
|
| 95 |
+
bias: ${conv_bias}
|
| 96 |
+
activation: LeakyReLU;0.01
|
| 97 |
+
norm_mode: INSTANCE_AFFINE
|
| 98 |
+
|
| 99 |
+
# ----- Encoder: residual stages (each output is a decoder skip) --------------
|
| 100 |
+
# Stage k: stack n_blocks_per_stage[k] ResidualBlockD; first block strides + changes width.
|
| 101 |
+
- name: Encoder_0
|
| 102 |
+
type: ResidualStage
|
| 103 |
+
in_branch: [stem]
|
| 104 |
+
out_branch: [enc0]
|
| 105 |
+
args:
|
| 106 |
+
dim: ${dim}
|
| 107 |
+
in_channels: ${features_per_stage.0}
|
| 108 |
+
out_channels: ${features_per_stage.0}
|
| 109 |
+
n_blocks: ${n_blocks_per_stage.0}
|
| 110 |
+
stride: ${strides.0}
|
| 111 |
+
kernel_size: ${kernel_size}
|
| 112 |
+
conv_bias: ${conv_bias}
|
| 113 |
+
negative_slope: ${negative_slope}
|
| 114 |
+
- name: Encoder_1
|
| 115 |
+
type: ResidualStage
|
| 116 |
+
in_branch: [enc0]
|
| 117 |
+
out_branch: [enc1]
|
| 118 |
+
args:
|
| 119 |
+
dim: ${dim}
|
| 120 |
+
in_channels: ${features_per_stage.0}
|
| 121 |
+
out_channels: ${features_per_stage.1}
|
| 122 |
+
n_blocks: ${n_blocks_per_stage.1}
|
| 123 |
+
stride: ${strides.1}
|
| 124 |
+
kernel_size: ${kernel_size}
|
| 125 |
+
conv_bias: ${conv_bias}
|
| 126 |
+
negative_slope: ${negative_slope}
|
| 127 |
+
- name: Encoder_2
|
| 128 |
+
type: ResidualStage
|
| 129 |
+
in_branch: [enc1]
|
| 130 |
+
out_branch: [enc2]
|
| 131 |
+
args:
|
| 132 |
+
dim: ${dim}
|
| 133 |
+
in_channels: ${features_per_stage.1}
|
| 134 |
+
out_channels: ${features_per_stage.2}
|
| 135 |
+
n_blocks: ${n_blocks_per_stage.2}
|
| 136 |
+
stride: ${strides.2}
|
| 137 |
+
kernel_size: ${kernel_size}
|
| 138 |
+
conv_bias: ${conv_bias}
|
| 139 |
+
negative_slope: ${negative_slope}
|
| 140 |
+
- name: Encoder_3
|
| 141 |
+
type: ResidualStage
|
| 142 |
+
in_branch: [enc2]
|
| 143 |
+
out_branch: [enc3]
|
| 144 |
+
args:
|
| 145 |
+
dim: ${dim}
|
| 146 |
+
in_channels: ${features_per_stage.2}
|
| 147 |
+
out_channels: ${features_per_stage.3}
|
| 148 |
+
n_blocks: ${n_blocks_per_stage.3}
|
| 149 |
+
stride: ${strides.3}
|
| 150 |
+
kernel_size: ${kernel_size}
|
| 151 |
+
conv_bias: ${conv_bias}
|
| 152 |
+
negative_slope: ${negative_slope}
|
| 153 |
+
- name: Encoder_4
|
| 154 |
+
type: ResidualStage
|
| 155 |
+
in_branch: [enc3]
|
| 156 |
+
out_branch: [enc4]
|
| 157 |
+
args:
|
| 158 |
+
dim: ${dim}
|
| 159 |
+
in_channels: ${features_per_stage.3}
|
| 160 |
+
out_channels: ${features_per_stage.4}
|
| 161 |
+
n_blocks: ${n_blocks_per_stage.4}
|
| 162 |
+
stride: ${strides.4}
|
| 163 |
+
kernel_size: ${kernel_size}
|
| 164 |
+
conv_bias: ${conv_bias}
|
| 165 |
+
negative_slope: ${negative_slope}
|
| 166 |
+
# Stage 5: bottleneck, 256 -> 256 at stride 2 (avgpool skip, no projection).
|
| 167 |
+
- name: Encoder_5
|
| 168 |
+
type: ResidualStage
|
| 169 |
+
in_branch: [enc4]
|
| 170 |
+
out_branch: [enc5]
|
| 171 |
+
args:
|
| 172 |
+
dim: ${dim}
|
| 173 |
+
in_channels: ${features_per_stage.4}
|
| 174 |
+
out_channels: ${features_per_stage.5}
|
| 175 |
+
n_blocks: ${n_blocks_per_stage.5}
|
| 176 |
+
stride: ${strides.5}
|
| 177 |
+
kernel_size: ${kernel_size}
|
| 178 |
+
conv_bias: ${conv_bias}
|
| 179 |
+
negative_slope: ${negative_slope}
|
| 180 |
+
|
| 181 |
+
# ----- Decoder: coarsest-first, upsample + concat skip + conv blocks ---------
|
| 182 |
+
# Stage j upsamples encoder feature (n_stages-1-j) and concatenates skip (n_stages-2-j).
|
| 183 |
+
- name: Decoder_0
|
| 184 |
+
type: DecoderStage
|
| 185 |
+
in_branch: [enc5, enc4]
|
| 186 |
+
out_branch: [dec0]
|
| 187 |
+
args:
|
| 188 |
+
dim: ${dim}
|
| 189 |
+
in_channels: ${features_per_stage.5}
|
| 190 |
+
skip_channels: ${features_per_stage.4}
|
| 191 |
+
n_conv: ${n_conv_per_stage_decoder.0}
|
| 192 |
+
kernel_size: ${kernel_size}
|
| 193 |
+
conv_bias: ${conv_bias}
|
| 194 |
+
negative_slope: ${negative_slope}
|
| 195 |
+
upsample_stride: ${strides.5}
|
| 196 |
+
- name: Decoder_1
|
| 197 |
+
type: DecoderStage
|
| 198 |
+
in_branch: [dec0, enc3]
|
| 199 |
+
out_branch: [dec1]
|
| 200 |
+
args:
|
| 201 |
+
dim: ${dim}
|
| 202 |
+
in_channels: ${features_per_stage.4}
|
| 203 |
+
skip_channels: ${features_per_stage.3}
|
| 204 |
+
n_conv: ${n_conv_per_stage_decoder.1}
|
| 205 |
+
kernel_size: ${kernel_size}
|
| 206 |
+
conv_bias: ${conv_bias}
|
| 207 |
+
negative_slope: ${negative_slope}
|
| 208 |
+
upsample_stride: ${strides.4}
|
| 209 |
+
- name: Decoder_2
|
| 210 |
+
type: DecoderStage
|
| 211 |
+
in_branch: [dec1, enc2]
|
| 212 |
+
out_branch: [dec2]
|
| 213 |
+
args:
|
| 214 |
+
dim: ${dim}
|
| 215 |
+
in_channels: ${features_per_stage.3}
|
| 216 |
+
skip_channels: ${features_per_stage.2}
|
| 217 |
+
n_conv: ${n_conv_per_stage_decoder.2}
|
| 218 |
+
kernel_size: ${kernel_size}
|
| 219 |
+
conv_bias: ${conv_bias}
|
| 220 |
+
negative_slope: ${negative_slope}
|
| 221 |
+
upsample_stride: ${strides.3}
|
| 222 |
+
- name: Decoder_3
|
| 223 |
+
type: DecoderStage
|
| 224 |
+
in_branch: [dec2, enc1]
|
| 225 |
+
out_branch: [dec3]
|
| 226 |
+
args:
|
| 227 |
+
dim: ${dim}
|
| 228 |
+
in_channels: ${features_per_stage.2}
|
| 229 |
+
skip_channels: ${features_per_stage.1}
|
| 230 |
+
n_conv: ${n_conv_per_stage_decoder.3}
|
| 231 |
+
kernel_size: ${kernel_size}
|
| 232 |
+
conv_bias: ${conv_bias}
|
| 233 |
+
negative_slope: ${negative_slope}
|
| 234 |
+
upsample_stride: ${strides.2}
|
| 235 |
+
- name: Decoder_4
|
| 236 |
+
type: DecoderStage
|
| 237 |
+
in_branch: [dec3, enc0]
|
| 238 |
+
out_branch: [dec4]
|
| 239 |
+
args:
|
| 240 |
+
dim: ${dim}
|
| 241 |
+
in_channels: ${features_per_stage.1}
|
| 242 |
+
skip_channels: ${features_per_stage.0}
|
| 243 |
+
n_conv: ${n_conv_per_stage_decoder.4}
|
| 244 |
+
kernel_size: ${kernel_size}
|
| 245 |
+
conv_bias: ${conv_bias}
|
| 246 |
+
negative_slope: ${negative_slope}
|
| 247 |
+
upsample_stride: ${strides.1}
|
| 248 |
+
|
| 249 |
+
# ----- Segmentation head -----------------------------------------------------
|
| 250 |
+
# Single full-resolution 1x1 conv emitting RAW LOGITS (deep_supervision=False,
|
| 251 |
+
# what nnU-Net returns). This is the weight-exact comparison point.
|
| 252 |
+
- name: SegHead
|
| 253 |
+
type: Conv
|
| 254 |
+
in_branch: [dec4]
|
| 255 |
+
out_branch: [-1]
|
| 256 |
+
args:
|
| 257 |
+
dim: ${dim}
|
| 258 |
+
in_channels: ${features_per_stage.0}
|
| 259 |
+
out_channels: ${num_classes}
|
| 260 |
+
kernel_size: 1
|
| 261 |
+
stride: 1
|
| 262 |
+
padding: 0
|
| 263 |
+
bias: true
|