VBoussot commited on
Commit
bd77191
·
verified ·
1 Parent(s): 727eb15

Block-level UNetPlusPlus.yml + Tanh + clean-key checkpoints (forward-exact 0.0)

Browse files
Finetune/CV_0.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:bb84ca7d72b035b93d2459b8afd35a148fbbd2c6a58e3f91f48bf5f706d31b33
3
- size 104505879
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:090652d2d1fd6bf7174334e75ac9faeef73c9f137b26a14d978f1e103ca40a19
3
+ size 104510103
Finetune/CV_1.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:37974ea5087c06baeba0a8ed8f1115ec211a5c54d97d45a21ad7672c1daec661
3
- size 104505879
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3be3599f2f3b2f31fe634193fb13126bc45aba24aa19779c9a9a52bb58b62978
3
+ size 104510103
Finetune/CV_2.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:cc102616fc374e0691a9159ea4a4cf835da52c9b2998f580edc1a3dcd9f65f9c
3
- size 104505879
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e819996a3a37cfde24bd90e53c52a55ffeae393e510a8f0549c804b6730d286
3
+ size 104510103
Finetune/CV_3.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4283e3916e2f644951fa942df4520ab5043e328e3cd9966df1772db72cffd515
3
- size 104505879
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9539a4804290913865c32f686776f6a2d2300b1074abf36e101ff46d51ab4e44
3
+ size 104510103
Finetune/CV_4.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:298bc0a4986d03e779d731a31736ad0ebc75584322fc3b0fdd0643e2246ab571
3
- size 104506071
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:534b170ce1d795f6cbda183cb2d4cf3a956fc6bb797eb93bb3e73d1606322586
3
+ size 104510295
Finetune/Config.yml CHANGED
@@ -1,68 +1,8 @@
1
  Trainer:
2
  Model:
3
- classpath: UNetpp.yml
4
- UNetpp:
5
- outputs_criterions:
6
- Head:Tanh:
7
- targets_criterions:
8
- CT:
9
- criterions_loader:
10
- MAE:
11
- schedulers:
12
- Constant:
13
- nb_step: 0
14
- value: 1
15
- is_loss: true
16
- group: 0
17
- start: 0
18
- stop: None
19
- accumulation: false
20
- reduction: mean
21
- SAM_Perceptual:
22
- train: true
23
- weights: [0, 1, 1, 0]
24
- schedulers:
25
- Constant:
26
- nb_step: 0
27
- value: 0.5
28
- is_loss: true
29
- group: 0
30
- start: 0
31
- stop: None
32
- accumulation: false
33
- CT;MASK:
34
- criterions_loader:
35
- MAE:
36
- schedulers:
37
- Constant:
38
- nb_step: 0
39
- value: 1
40
- is_loss: false
41
- group: 0
42
- start: 0
43
- stop: None
44
- accumulation: false
45
- reduction: mean
46
- schedulers:
47
- PolyLRScheduler:
48
- initial_lr: 0.01
49
- max_steps: 500
50
- exponent: 0.9
51
- current_step: 0
52
- nb_step: 0
53
- Patch: None
54
- optimizer:
55
- name: SGD
56
- lr: 0.01
57
- momentum: 0.99
58
- dampening: 0
59
- weight_decay: 3e-05
60
- nesterov: true
61
- maximize: false
62
- foreach: None
63
- differentiable: false
64
- fused: None
65
- nb_channel: 5
66
  Dataset:
67
  groups_src:
68
  MASK:
 
1
  Trainer:
2
  Model:
3
+ classpath: UNetPlusPlus.yml
4
+ UNetPlusPlus:
5
+ outputs_criterions: None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  Dataset:
7
  groups_src:
8
  MASK:
Finetune/Prediction.yml CHANGED
@@ -1,7 +1,7 @@
1
  Predictor:
2
  Model:
3
- classpath: UNetpp.yml
4
- UNetpp:
5
  outputs_criterions: None
6
  Dataset:
7
  groups_src:
 
1
  Predictor:
2
  Model:
3
+ classpath: UNetPlusPlus.yml
4
+ UNetPlusPlus:
5
  outputs_criterions: None
6
  Dataset:
7
  groups_src:
Finetune/UNetPlusPlus.yml ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Declarative KonfAI UNetPlusPlus -- weight- and forward-exact with smp.UnetPlusPlus (ResNet encoder).
2
+ #
3
+ # This graph reproduces, block-for-block and in forward-execution order, the network built by
4
+ # `segmentation_models_pytorch.UnetPlusPlus(encoder_name="resnet34", encoder_weights=None,
5
+ # in_channels=5, classes=1, activation=None)` -- the exact ImpactSynth "MR" backbone: a torchvision
6
+ # ResNet-34 encoder feeding a UNet++ nested (dense) decoder. It is the declarative twin of the
7
+ # parametric `konfai.models.python.segmentation.unetplusplus.UNetPlusPlus`. Because the weighted
8
+ # leaves execute in exactly the same sequence as the reference, a REAL smp checkpoint of this
9
+ # topology loads straight into this KonfAI model through the execution-order bridge
10
+ # `konfai.utils.pretrained.transfer_weights_by_execution_order`, and the KonfAI logits are
11
+ # `torch.allclose` with the reference output (see tests/unit/test_unetplusplus_yaml.py, which
12
+ # transfers the parametric UNetPlusPlus's weights in and checks maxdiff < 1e-4).
13
+ #
14
+ # It is authored at the BLOCK level from two generic, registry-backed composite blocks -- so the
15
+ # whole graph reads as the architecture's topology (encoder stages + the UNet++ decoder grid + head),
16
+ # not a conv-by-conv unroll:
17
+ #
18
+ # * `ResNetStage` = one encoder resolution stage: a stack of `n_blocks` torchvision `BasicBlock`
19
+ # (`ResNetBasicBlock`). Its FIRST block carries the stage stride (strided-conv downsampling; the
20
+ # `1x1` projection skip is built automatically when stride or channels change) and the channel
21
+ # change; the rest are stride 1. conv_bias=False, BatchNorm -- the torchvision ResNet convention.
22
+ # * `UNetPlusPlusNode` = one UNet++ dense-grid node `x_{d}_{l}`, a MULTI-input node
23
+ # `in_branch: [coarser, skip_0, skip_1, ...]`: nearest-neighbour upsample of the shallower-column
24
+ # predecessor, a Concat of the upsampled feature FIRST then every same-resolution dense skip and the
25
+ # encoder skip (smp order), then two `Conv(3x3) -> BatchNorm -> ReLU` blocks (smp's `Conv2dReLU`).
26
+ # `skip_channels` lists the per-skip widths in `in_branch` order: its length wires the concat and its
27
+ # sum fixes the conv input width `up_channels + sum(skip_channels)`. The final full-resolution node
28
+ # has no skip.
29
+ #
30
+ # ENCODER (ResNet-34): a stem `Conv(7x7, stride 2) -> BatchNorm -> ReLU` (`enc_c1`, 64ch, 1/2 res) and a
31
+ # `MaxPool(3, stride 2)`, then four `ResNetStage`s with block counts [3, 4, 6, 3] and widths
32
+ # [64, 128, 256, 512] (`enc_l1..enc_l4`, 1/4..1/32 res). The five features consumed by the decoder are
33
+ # `enc_c1` and `enc_l1..enc_l4`. (resnet18 = block counts [2, 2, 2, 2], same widths.)
34
+ #
35
+ # DECODER channel table (smp's UnetPlusPlusDecoder arithmetic for a BasicBlock ResNet encoder). A
36
+ # declarative YAML cannot compute the dense-grid channel recurrence, so the widths are written
37
+ # explicitly per node; `up_channels + sum(skip_channels) -> out_channels` is the node's `Conv2dReLU`
38
+ # input/output. `dx_d_l` is the branch holding node `x_{d}_{l}`:
39
+ #
40
+ # node in_branch (coarser, skips...) up + skips = conv_in -> out
41
+ # x_0_0 enc_l4, enc_l3 512 + [256] = 768 -> 256
42
+ # x_1_1 enc_l3, enc_l2 256 + [128] = 384 -> 128
43
+ # x_2_2 enc_l2, enc_l1 128 + [64] = 192 -> 64
44
+ # x_3_3 enc_l1, enc_c1 64 + [64] = 128 -> 64
45
+ # x_0_1 dx_0_0, dx_1_1, enc_l2 256 + [128,128] = 512 -> 128
46
+ # x_1_2 dx_1_1, dx_2_2, enc_l1 128 + [64,64] = 256 -> 64
47
+ # x_2_3 dx_2_2, dx_3_3, enc_c1 64 + [64,64] = 192 -> 64
48
+ # x_0_2 dx_0_1, dx_1_2, dx_2_2, enc_l1 128 + [64,64,64] = 320 -> 64
49
+ # x_1_3 dx_1_2, dx_2_3, dx_3_3, enc_c1 64 + [64,64,64] = 256 -> 64
50
+ # x_0_3 dx_0_2, dx_1_3, dx_2_3, dx_3_3, enc_c1 64 + [64,64,64,64]= 320 -> 32
51
+ # x_0_4 dx_0_3 32 + [] = 32 -> 16
52
+ #
53
+ # A `Conv(3x3)` segmentation head emits raw logits (activation=None -> the weight-exact comparison
54
+ # point). The nodes below are declared in smp forward-execution order so the 117 weighted leaves (72
55
+ # encoder + 44 decoder + 1 head) pair one-to-one with the reference.
56
+ #
57
+ # FIXED DEPTH / ENCODER: a declarative YAML cannot loop, so the 4 encoder stages + 11 decoder nodes and
58
+ # the decoder channel table are structural (this file is the resnet18/34 BasicBlock topology). `dim`,
59
+ # `in_channels`, `num_classes`, `stem_channels`, `stage_channels` and `n_blocks_per_stage` stay
60
+ # parametric; retargeting another BasicBlock encoder means editing `n_blocks_per_stage` (e.g. resnet18)
61
+ # and, for different widths, recomputing the decoder table above.
62
+ #
63
+ # Use it as a KonfAI model classpath:
64
+ # classpath: default|UNetPlusPlus.yml # shipped catalog copy
65
+ # classpath: /path/to/UNetPlusPlus.yml # any local copy
66
+ name: UNetPlusPlus
67
+
68
+ parameters:
69
+ dim: 2
70
+ in_channels: 5
71
+ num_classes: 1
72
+ # torchvision ResNet-34 stem width and stage planes (enc_l1..enc_l4).
73
+ stem_channels: 64
74
+ stage_channels: [64, 128, 256, 512]
75
+ # BasicBlock counts per encoder stage (resnet34 = [3, 4, 6, 3]; resnet18 = [2, 2, 2, 2]).
76
+ n_blocks_per_stage: [3, 4, 6, 3]
77
+
78
+ network:
79
+ in_channels: ${in_channels}
80
+ dim: ${dim}
81
+
82
+ modules:
83
+ # ===== Encoder: ResNet-34 stem + four BasicBlock stages =======================
84
+ # Stem: Conv(7x7, s2) -> BatchNorm -> ReLU (enc_c1, a decoder skip at 1/2 res), then MaxPool.
85
+ - name: Stem
86
+ type: ConvBlock
87
+ in_branch: [0]
88
+ out_branch: [enc_c1]
89
+ args:
90
+ dim: ${dim}
91
+ in_channels: ${in_channels}
92
+ out_channels: ${stem_channels}
93
+ block_configs:
94
+ - $object: BlockConfig
95
+ args:
96
+ kernel_size: 7
97
+ stride: 2
98
+ padding: 3
99
+ bias: false
100
+ activation: ReLU
101
+ norm_mode: BATCH
102
+ - name: StemMaxPool
103
+ type: MaxPool
104
+ in_branch: [enc_c1]
105
+ out_branch: [enc_mp]
106
+ args:
107
+ dim: ${dim}
108
+ kernel_size: 3
109
+ stride: 2
110
+ padding: 1
111
+
112
+ # Residual stages; each output enc_l1..enc_l4 is a decoder skip. Stage 1 follows the maxpool at
113
+ # 1/4 and never strides; stages 2-4 stride their first block (downsampling + channel change).
114
+ - name: Encoder_1
115
+ type: ResNetStage
116
+ in_branch: [enc_mp]
117
+ out_branch: [enc_l1]
118
+ args:
119
+ dim: ${dim}
120
+ in_channels: ${stem_channels}
121
+ out_channels: ${stage_channels.0}
122
+ n_blocks: ${n_blocks_per_stage.0}
123
+ stride: 1
124
+ - name: Encoder_2
125
+ type: ResNetStage
126
+ in_branch: [enc_l1]
127
+ out_branch: [enc_l2]
128
+ args:
129
+ dim: ${dim}
130
+ in_channels: ${stage_channels.0}
131
+ out_channels: ${stage_channels.1}
132
+ n_blocks: ${n_blocks_per_stage.1}
133
+ stride: 2
134
+ - name: Encoder_3
135
+ type: ResNetStage
136
+ in_branch: [enc_l2]
137
+ out_branch: [enc_l3]
138
+ args:
139
+ dim: ${dim}
140
+ in_channels: ${stage_channels.1}
141
+ out_channels: ${stage_channels.2}
142
+ n_blocks: ${n_blocks_per_stage.2}
143
+ stride: 2
144
+ - name: Encoder_4
145
+ type: ResNetStage
146
+ in_branch: [enc_l3]
147
+ out_branch: [enc_l4]
148
+ args:
149
+ dim: ${dim}
150
+ in_channels: ${stage_channels.2}
151
+ out_channels: ${stage_channels.3}
152
+ n_blocks: ${n_blocks_per_stage.3}
153
+ stride: 2
154
+
155
+ # ===== UNet++ nested decoder grid (smp forward-execution order) ===============
156
+ # --- Column l = d (the diagonal): upsample encoder feat[d], concat encoder feat[d+1] ---
157
+ - name: x_0_0
158
+ type: UNetPlusPlusNode
159
+ in_branch: [enc_l4, enc_l3]
160
+ out_branch: [dx_0_0]
161
+ args: {dim: "${dim}", up_channels: 512, skip_channels: [256], out_channels:
162
+ 256}
163
+ - name: x_1_1
164
+ type: UNetPlusPlusNode
165
+ in_branch: [enc_l3, enc_l2]
166
+ out_branch: [dx_1_1]
167
+ args: {dim: "${dim}", up_channels: 256, skip_channels: [128], out_channels:
168
+ 128}
169
+ - name: x_2_2
170
+ type: UNetPlusPlusNode
171
+ in_branch: [enc_l2, enc_l1]
172
+ out_branch: [dx_2_2]
173
+ args: {dim: "${dim}", up_channels: 128, skip_channels: [64], out_channels: 64}
174
+ - name: x_3_3
175
+ type: UNetPlusPlusNode
176
+ in_branch: [enc_l1, enc_c1]
177
+ out_branch: [dx_3_3]
178
+ args: {dim: "${dim}", up_channels: 64, skip_channels: [64], out_channels: 64}
179
+
180
+ # --- Dense column l = d + 1 ---
181
+ - name: x_0_1
182
+ type: UNetPlusPlusNode
183
+ in_branch: [dx_0_0, dx_1_1, enc_l2]
184
+ out_branch: [dx_0_1]
185
+ args: {dim: "${dim}", up_channels: 256, skip_channels: [128, 128],
186
+ out_channels: 128}
187
+ - name: x_1_2
188
+ type: UNetPlusPlusNode
189
+ in_branch: [dx_1_1, dx_2_2, enc_l1]
190
+ out_branch: [dx_1_2]
191
+ args: {dim: "${dim}", up_channels: 128, skip_channels: [64, 64], out_channels:
192
+ 64}
193
+ - name: x_2_3
194
+ type: UNetPlusPlusNode
195
+ in_branch: [dx_2_2, dx_3_3, enc_c1]
196
+ out_branch: [dx_2_3]
197
+ args: {dim: "${dim}", up_channels: 64, skip_channels: [64, 64], out_channels:
198
+ 64}
199
+
200
+ # --- Dense column l = d + 2 ---
201
+ - name: x_0_2
202
+ type: UNetPlusPlusNode
203
+ in_branch: [dx_0_1, dx_1_2, dx_2_2, enc_l1]
204
+ out_branch: [dx_0_2]
205
+ args: {dim: "${dim}", up_channels: 128, skip_channels: [64, 64, 64],
206
+ out_channels: 64}
207
+ - name: x_1_3
208
+ type: UNetPlusPlusNode
209
+ in_branch: [dx_1_2, dx_2_3, dx_3_3, enc_c1]
210
+ out_branch: [dx_1_3]
211
+ args: {dim: "${dim}", up_channels: 64, skip_channels: [64, 64, 64],
212
+ out_channels: 64}
213
+
214
+ # --- Dense column l = d + 3 ---
215
+ - name: x_0_3
216
+ type: UNetPlusPlusNode
217
+ in_branch: [dx_0_2, dx_1_3, dx_2_3, dx_3_3, enc_c1]
218
+ out_branch: [dx_0_3]
219
+ args: {dim: "${dim}", up_channels: 64, skip_channels: [64, 64, 64, 64],
220
+ out_channels: 32}
221
+
222
+ # --- Final full-resolution node (no skip: smp DecoderBlock(in, 0, out)) ---
223
+ - name: x_0_4
224
+ type: UNetPlusPlusNode
225
+ in_branch: [dx_0_3]
226
+ out_branch: [dx_0_4]
227
+ args: {dim: "${dim}", up_channels: 32, skip_channels: [], out_channels: 16}
228
+
229
+ # ===== Segmentation head (activation=None -> raw logits) =======================
230
+ - name: SegmentationHead
231
+ type: Conv
232
+ in_branch: [dx_0_4]
233
+ out_branch:
234
+ - logits
235
+ args:
236
+ dim: ${dim}
237
+ in_channels: 16
238
+ out_channels: ${num_classes}
239
+ kernel_size: 3
240
+ stride: 1
241
+ padding: 1
242
+ bias: true
243
+ - name: Tanh
244
+ type: Tanh
245
+ in_branch:
246
+ - logits
247
+ out_branch:
248
+ - -1
249
+ args: {}