fix unet bottleneck dim off by 1 error#29
Conversation
michaelmckinsey1
left a comment
There was a problem hiding this comment.
So should https://github.com/PatrickRMiles/ScaFFold/blob/506024b18f84620d970d586ca1973b83c361e5ea/ScaFFold/configs/benchmark_default.yml#L8 and https://github.com/PatrickRMiles/ScaFFold/blob/506024b18f84620d970d586ca1973b83c361e5ea/ScaFFold/configs/benchmark_testing.yml#L8 both be updated to 4 instead of 3?
No because this is fixing the internal calculation of layers to be the intended amount |
This PR adjusts how we calculate the numbers of "layers" in the unet from
problem_scaleandunet_bottleneck_dim. With this change, the bottleneck spatial dimensions are nowpow(2, unet_bottleneck_dim)as intended.Context: We noticed recently that the
unet_bottleneck_dimdid not map to the spatial dimensions of the bottleneck layers as we expected: for a dim of 3, we expected bottleneck spatial dimensions of size 8, we observed 4. This has to do with how we build the unet (or equivalently how we define "layers"). We pass a layers arg into the Unet construction. I think we have been interpreting this to mean the number of "levels" in the unet, but with how we construct the unet, it's actually "levels" - 1 (or equivalently the number of 2x2 downsampling steps we apply).We construct the unet as follows:
In ScaFFold, we calculate layers as layers = problem_scale - bottleneck_dim + 1 . At scale 6 and bottleneck dim 3, we have 6 - 3 + 1 == 4 . So in the unet, we have 1 + (layers - 1) + 1 == 1 + (4-1) + 1 == 5 "levels", four of which include 2x2 downsampling from the MaxPool3d. This means we take input of size 64, and apply 2x2 downsampling four times. 64 -> 32 -> 16 -> 8 -> 4. That's why we see bottleneck spatial dims of size 4, instead of 8. This holds regardless of problem_scale: at scale 7, we have input size 128 but five downsampling steps, so we still arrive at bottleneck spatial dim size 4.