Skip to content

Instantly share code, notes, and snippets.

@seanbenhur
Created November 9, 2020 12:19
Show Gist options
  • Save seanbenhur/0cb981a9b991b9d65e1ea196855e8ba0 to your computer and use it in GitHub Desktop.
Save seanbenhur/0cb981a9b991b9d65e1ea196855e8ba0 to your computer and use it in GitHub Desktop.
def _make_layer(self,block,num_res_blocks,int_channels,stride):
identity_downsample = None
layers = []
if stride!=1 or self.in_channels != int_channels*4:
identity_downsample = nn.Sequential(nn.Conv2d(self.in_channels,int_channels*4,
kernel_size=1,stride=stride),
nn.BatchNorm2d(int_channels*4))
layers.append(ResBlock(self.in_channels,int_channels,identity_downsample,stride))
#this expansion size will always be 4 for all the types of ResNets
self.in_channels = int_channels*4
for i in range(num_res_blocks-1):
layers.append(ResBlock(self.in_channels,int_channels))
return nn.Sequential(*layers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment