Skip to content

Instantly share code, notes, and snippets.

@Sivaram46
Last active June 12, 2021 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sivaram46/3498ecd8429c9ee6c11afdddfa82a43a to your computer and use it in GitHub Desktop.
Save Sivaram46/3498ecd8429c9ee6c11afdddfa82a43a to your computer and use it in GitHub Desktop.
# downsample using 1 * 1 convolution
downsample = nn.Sequential(
nn.Conv2d(64, 128, kernel_size=1, stride=2, bias=False),
nn.BatchNorm2d(128)
)
# First five layers of ResNet34
resnet_blocks = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False),
nn.MaxPool2d(kernel_size=2, stride=2),
ResidualBlock(64, 64),
ResidualBlock(64, 64),
ResidualBlock(64, 128, stride=[2, 1], downsample=downsample)
)
# checking the shape
inputs = torch.rand(1, 3, 100, 100) # single 100 * 100 color image
outputs = resnet_blocks(inputs)
print(outputs.shape) # shape would be (1, 128, 13, 13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment