Skip to content

Commit 8132e7e

Browse files
Merge pull request #8 from ai-mbl/ed-review
Ed review aimbl 2025
2 parents 68876ee + fce8f4f commit 8132e7e

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

exercise.ipynb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,11 @@
860860
" <h4>Task 6: U-Net Implementation</h4>\n",
861861
" <p>Now we will implement our U-Net! We have written some of it for you - follow the steps below to fill in the missing parts.</p>\n",
862862
" <ol>\n",
863-
" <li>Declare a list of encoder (left) and decoder (right) ConvBlocks. Carefully consider the input and output feature maps for each ConvPass!</li>\n",
863+
" <li>Declare a list of encoder (left) and decoder (right) ConvBlocks. Carefully consider the input and output feature maps for each ConvPass!\n",
864+
" <ul>\n",
865+
" <li><strong>Hint:</strong> Consider implementing helper functions to calculate the encoder and decoder blocks separately - this will make your code more readable and easier to debug.</li>\n",
866+
" </ul>\n",
867+
" </li>\n",
864868
" <li>Declare an Upsample, Downsample, CropAndConcat, and OutputConv block.</li>\n",
865869
" <li>Implement the <code style=\"color: black\">forward</code> function, applying the modules you declared above in the proper order.</li>\n",
866870
" </ol>\n",
@@ -943,7 +947,8 @@
943947
" # TASK 6.1A: Initialize list here\n",
944948
" # Loop through each level of the encoder from top (level=0) to bottom (level=self.depth - 1)\n",
945949
" for level in range(self.depth): \n",
946-
" # conv = \n",
950+
" input_features,output_features = ...\n",
951+
" conv = ...\n",
947952
" # Adding conv module to the list\n",
948953
" self.left_convs.append(conv)\n",
949954
" # right convolutional passes\n",
@@ -952,7 +957,8 @@
952957
" # Loop through each level of the decoder from top (level=0) to one above bottom (level=self.depth - 2)\n",
953958
" for level in range(self.depth - 1):\n",
954959
" # Initialize conv module\n",
955-
" # conv = \n",
960+
" input_features,output_features = ...\n",
961+
" conv = ... \n",
956962
" # Adding conv module to the list\n",
957963
" self.right_convs.append(conv)\n",
958964
" \n",
@@ -973,7 +979,20 @@
973979
" # TASK 6.3C: Implement decoder here\n",
974980
" ...\n",
975981
" # TASK 6.3D: Apply the final convolution and return the output\n",
976-
" return"
982+
" return\n",
983+
"\n",
984+
" def compute_fmaps_encoder(self, level: int) -> tuple[int, int]:\n",
985+
" \"\"\"Compute the number of input and output feature maps for\n",
986+
" a conv block at a given level of the UNet encoder (left side).\n",
987+
" \"\"\"\n",
988+
" return ...\n",
989+
" \n",
990+
" def compute_fmaps_decoder(self, level: int) -> tuple[int, int]:\n",
991+
" \"\"\"Compute the number of input and output feature maps for a conv block\n",
992+
" at a given level of the UNet decoder (right side).\n",
993+
" \"\"\"\n",
994+
" \n",
995+
" return ..."
977996
]
978997
},
979998
{

solution.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,11 @@
877877
" <h4>Task 6: U-Net Implementation</h4>\n",
878878
" <p>Now we will implement our U-Net! We have written some of it for you - follow the steps below to fill in the missing parts.</p>\n",
879879
" <ol>\n",
880-
" <li>Declare a list of encoder (left) and decoder (right) ConvBlocks. Carefully consider the input and output feature maps for each ConvPass!</li>\n",
880+
" <li>Declare a list of encoder (left) and decoder (right) ConvBlocks. Carefully consider the input and output feature maps for each ConvPass!\n",
881+
" <ul>\n",
882+
" <li><strong>Hint:</strong> Consider implementing helper functions to calculate the encoder and decoder blocks separately - this will make your code more readable and easier to debug.</li>\n",
883+
" </ul>\n",
884+
" </li>\n",
881885
" <li>Declare an Upsample, Downsample, CropAndConcat, and OutputConv block.</li>\n",
882886
" <li>Implement the <code style=\"color: black\">forward</code> function, applying the modules you declared above in the proper order.</li>\n",
883887
" </ol>\n",

solution.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,11 @@ def forward(self, x):
588588
# <h4>Task 6: U-Net Implementation</h4>
589589
# <p>Now we will implement our U-Net! We have written some of it for you - follow the steps below to fill in the missing parts.</p>
590590
# <ol>
591-
# <li>Declare a list of encoder (left) and decoder (right) ConvBlocks. Carefully consider the input and output feature maps for each ConvPass!</li>
591+
# <li>Declare a list of encoder (left) and decoder (right) ConvBlocks. Carefully consider the input and output feature maps for each ConvPass!
592+
# <ul>
593+
# <li><strong>Hint:</strong> Consider implementing helper functions to calculate the encoder and decoder blocks separately - this will make your code more readable and easier to debug.</li>
594+
# </ul>
595+
# </li>
592596
# <li>Declare an Upsample, Downsample, CropAndConcat, and OutputConv block.</li>
593597
# <li>Implement the <code style="color: black">forward</code> function, applying the modules you declared above in the proper order.</li>
594598
# </ol>
@@ -661,7 +665,8 @@ def __init__(
661665
# TASK 6.1A: Initialize list here
662666
# Loop through each level of the encoder from top (level=0) to bottom (level=self.depth - 1)
663667
for level in range(self.depth):
664-
# conv =
668+
input_features,output_features = ...
669+
conv = ...
665670
# Adding conv module to the list
666671
self.left_convs.append(conv)
667672
# right convolutional passes
@@ -670,7 +675,8 @@ def __init__(
670675
# Loop through each level of the decoder from top (level=0) to one above bottom (level=self.depth - 2)
671676
for level in range(self.depth - 1):
672677
# Initialize conv module
673-
# conv =
678+
input_features,output_features = ...
679+
conv = ...
674680
# Adding conv module to the list
675681
self.right_convs.append(conv)
676682

@@ -693,6 +699,19 @@ def forward(self, x):
693699
# TASK 6.3D: Apply the final convolution and return the output
694700
return
695701

702+
def compute_fmaps_encoder(self, level: int) -> tuple[int, int]:
703+
"""Compute the number of input and output feature maps for
704+
a conv block at a given level of the UNet encoder (left side).
705+
"""
706+
return ...
707+
708+
def compute_fmaps_decoder(self, level: int) -> tuple[int, int]:
709+
"""Compute the number of input and output feature maps for a conv block
710+
at a given level of the UNet decoder (right side).
711+
"""
712+
713+
return ...
714+
696715

697716
# %% tags=["solution"]
698717
class UNet(torch.nn.Module):

0 commit comments

Comments
 (0)