Implement U-Net crop and concatenate in NHWC layout. Center-crop encoder_features to the decoder height and width, then concatenate the cropped encoder features before decoder_features along the channel axis. When a spatial difference is odd, discard the extra row or column from the bottom or right. Return the merged result as a float64 NumPy array with shape (B, H_decoder, W_decoder, C_encoder + C_decoder).
Examples
Input: encoder_features = [[[[1],[2],[3],[4]],[[5],[6],[7],[8]],[[9],[10],[11],[12]],[[13],[14],[15],[16]]]], decoder_features = [[[[20,21],[22,23]],[[24,25],[26,27]]]]
Output: [[[[6,20,21],[7,22,23]],[[10,24,25],[11,26,27]]]]
Explanation: The centered encoder region is selected before its channels are joined with the decoder channels.
Input: encoder_features = [[[[1,2],[3,4]],[[5,6],[7,8]]]], decoder_features = [[[[9],[10]],[[11],[12]]]]
Output: [[[[1,2,9],[3,4,10]],[[5,6,11],[7,8,12]]]]
Input: encoder_features = [[[[1],[2],[3],[4]],[[5],[6],[7],[8]]]], decoder_features = [[[[9],[10]]]]
Output: [[[[2,9],[3,10]]]]
Hint 1
Use half the spatial shape difference as each starting offset.
Hint 2
Slice to the decoder size before np.concatenate along axis -1.
Requirements
- Use NumPy.
- Compute the centered spatial crop from the shape difference.
- Preserve batch order and all channels.
- Concatenate encoder channels before decoder channels.
- Return a float64 NumPy array.
Constraints
- Both inputs use NHWC layout and dtype float64.
- Batch sizes are equal.
- Encoder height and width are at least the decoder height and width.
- Channel counts are positive.
All steps in U-Net
- U-Net Encoder Block
- U-Net Decoder Block
- U-Net Skip Connections
- U-Net Bottleneck
- U-Net Output Layer
- Complete U-Net
Accepts: array
Accepts: array
U-Net Skip Connections
Implement U-Net crop and concatenate in NHWC layout. Center-crop encoder_features to the decoder height and width, then concatenate the cropped encoder features before decoder_features along the channel axis. When a spatial difference is odd, discard the extra row or column from the bottom or right. Return the merged result as a float64 NumPy array with shape (B, H_decoder, W_decoder, C_encoder + C_decoder).
Examples
Input: encoder_features = [[[[1],[2],[3],[4]],[[5],[6],[7],[8]],[[9],[10],[11],[12]],[[13],[14],[15],[16]]]], decoder_features = [[[[20,21],[22,23]],[[24,25],[26,27]]]]
Output: [[[[6,20,21],[7,22,23]],[[10,24,25],[11,26,27]]]]
Explanation: The centered encoder region is selected before its channels are joined with the decoder channels.
Input: encoder_features = [[[[1,2],[3,4]],[[5,6],[7,8]]]], decoder_features = [[[[9],[10]],[[11],[12]]]]
Output: [[[[1,2,9],[3,4,10]],[[5,6,11],[7,8,12]]]]
Input: encoder_features = [[[[1],[2],[3],[4]],[[5],[6],[7],[8]]]], decoder_features = [[[[9],[10]]]]
Output: [[[[2,9],[3,10]]]]
Hint 1
Use half the spatial shape difference as each starting offset.
Hint 2
Slice to the decoder size before np.concatenate along axis -1.
Requirements
- Use NumPy.
- Compute the centered spatial crop from the shape difference.
- Preserve batch order and all channels.
- Concatenate encoder channels before decoder channels.
- Return a float64 NumPy array.
Constraints
- Both inputs use NHWC layout and dtype float64.
- Batch sizes are equal.
- Encoder height and width are at least the decoder height and width.
- Channel counts are positive.
All steps in U-Net
- U-Net Encoder Block
- U-Net Decoder Block
- U-Net Skip Connections
- U-Net Bottleneck
- U-Net Output Layer
- Complete U-Net
Accepts: array
Accepts: array