Problems
Loading...
Step 6 of 6
Complete U-Net
Hard

Implement a compact numerical U-Net forward pass in NHWC layout. Apply an encoder block, save its skip tensor, max-pool into a two-convolution bottleneck, upsample and project the bottleneck, concatenate the centered skip tensor, apply two decoder convolutions, and finish with a per-pixel linear output projection. The weights dictionary contains enc_kernel1, enc_bias1, enc_kernel2, enc_bias2, bridge_kernel1, bridge_bias1, bridge_kernel2, bridge_bias2, W_up, b_up, dec_kernel1, dec_bias1, dec_kernel2, dec_bias2, W_out, and b_out. Return raw segmentation logits as a float64 NumPy array.

Loading visualization...

Examples

Input: x = [[[[1],[0]],[[-1],[2]]]], weights = {"enc_kernel1":[[[[1]]]],"enc_bias1":[0],"enc_kernel2":[[[[1]]]],"enc_bias2":[0],"bridge_kernel1":[[[[2]]]],"bridge_bias1":[0],"bridge_kernel2":[[[[0.5]]]],"bridge_bias2":[0],"W_up":[[1]],"b_up":[0],"dec_kernel1":[[[[1],[1]]]],"dec_bias1":[0],"dec_kernel2":[[[[0.5]]]],"dec_bias2":[0],"W_out":[[1,-1]],"b_out":[0.1,-0.1]}

Output: [[[[1.6,-1.6],[1.1,-1.1]],[[1.1,-1.1],[2.1,-2.1]]]]

Explanation: The forward pass connects the high-resolution skip path with the pooled bottleneck path before producing pixel logits.

Input: x = [[[[0.5],[1]],[[1.5],[2]]]], weights = {"enc_kernel1":[[[[1]]]],"enc_bias1":[0.2],"enc_kernel2":[[[[0.5]]]],"enc_bias2":[0],"bridge_kernel1":[[[[1]]]],"bridge_bias1":[-0.1],"bridge_kernel2":[[[[1]]]],"bridge_bias2":[0],"W_up":[[1]],"b_up":[0],"dec_kernel1":[[[[0.25],[0.5]]]],"dec_bias1":[0.1],"dec_kernel2":[[[[1]]]],"dec_bias2":[0],"W_out":[[2]],"b_out":[-0.2]}

Output: [[[[1.175],[1.3]],[[1.425],[1.55]]]]

Input: x = [[[[1,-1],[0,1]],[[2,0],[-1,2]]]], weights = {"enc_kernel1":[[[[1],[0.5]]]],"enc_bias1":[0],"enc_kernel2":[[[[1]]]],"enc_bias2":[0],"bridge_kernel1":[[[[1]]]],"bridge_bias1":[0],"bridge_kernel2":[[[[1]]]],"bridge_bias2":[0],"W_up":[[1]],"b_up":[0],"dec_kernel1":[[[[0.5],[1]]]],"dec_bias1":[0],"dec_kernel2":[[[[1]]]],"dec_bias2":[0],"W_out":[[1]],"b_out":[0]}

Output: [[[[2.25],[2.25]],[[3],[2]]]]

Hint 1

Keep the encoder skip tensor before applying 2 by 2 max pooling.

Hint 2

Reuse the same convolution operation in the encoder, bottleneck, and decoder.

Hint 3

Apply the final W_out projection without ReLU.

Requirements

  • Use NumPy and every supplied weight exactly once in the documented stage.
  • Preserve the encoder skip tensor before pooling.
  • Use nearest-neighbor upsampling and centered skip concatenation.
  • Apply ReLU after every convolution except the output projection.
  • Return a float64 NumPy array of raw logits.

Constraints

  • x uses NHWC layout, has even spatial dimensions, and has dtype float64.
  • Every convolution kernel has positive odd spatial size and compatible channels.
  • The weights dictionary contains exactly the documented arrays.
  • Every supplied numeric array has dtype float64.