Skip to content

Instantly share code, notes, and snippets.

@Sivaram46
Created June 12, 2021 17:38
Show Gist options
  • Save Sivaram46/c1d7eeb4cb1c178fe2b57678a0507d7b to your computer and use it in GitHub Desktop.
Save Sivaram46/c1d7eeb4cb1c178fe2b57678a0507d7b to your computer and use it in GitHub Desktop.
# a block consists of initial conv layers followed by 6 dense layers
dense_block = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=7, padding=3, stride=2, bias=False),
nn.BatchNorm2d(64),
nn.MaxPool2d(3, 2),
Dense_Block(6, 64, growthrate=32, bn_size=4),
)
inputs = torch.rand(1, 3, 100, 100)
outputs = dense_block(inputs)
print(outputs.shape) # shape would be (1, 256, 24, 24)
# one could also use pretrained weights of DenseNet trained on ImageNet
densenet121 = torchvision.models.densenet121(pretrained=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment