Homework IntroToDL
Homework IntroToDL
Homework IntroToDL
class ResNet(nn.Module):
def __init__(self, block, layers, planes, num_classes = 10):
super(ResNet, self).__init__()
self.inplanes = 64
self.conv1 = nn.Sequential(
nn.Conv2d(3, 64, kernel_size = 7, stride = 2, padding = 3),
nn.BatchNorm2d(64),
nn.ReLU())
self.maxpool = nn.MaxPool2d(kernel_size = 3, stride = 2, padding = 1)
self.layer0 = self._make_layer(block, planes[0], layers[0], stride = 1)
self.layer1 = self._make_layer(block, planes[1], layers[1], stride = 2)
self.layer2 = self._make_layer(block, planes[2], layers[2], stride = 2)
self.layer3 = self._make_layer(block, planes[3], layers[3], stride = 2)
self.avgpool = nn.AdaptiveAvgPool2d((1,1))
self.fc = nn.Linear(512, num_classes)
downsample = nn.Sequential(
nn.Conv2d(self.inplanes, planes, kernel_size=1, stride=stride),
nn.BatchNorm2d(planes),
)
layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
self.inplanes = planes
for i in range(1, blocks):
layers.append(block(self.inplanes, planes))
return nn.Sequential(*layers)
return x
ResNet34 = ResNet(ResidualBlock,[3,4,6,3],[64,128,256,512])
Modify 1 line of code to make a ResNet-18 model instead of ResNet-34
2, Data Augmentation
Refer to https://pytorch.org/vision/0.15/transforms.html
Given the following image (you can download it via this link). Firstly, resize it to 256x256.
List of augmentation methods used in this exercise
0 RandomCrop
1 Pad (zero)
2 Random rotation
3 Random affine
4 ElasticTransform
5 Horizontal Flip
6 Vertical Flip
7 Color Jitter
8 RandomInvert(p=1)
9 Gaussian Blur (kernel size = 7)
E1 Pad (edge)
E2 RandomAdjustSharpness
E3 Pad (symmetric)
0 ExponentialLR
1 StepLR (step size = 10)
2 CosineAnnealingLR (T max = 10)
3 CyclicLR (mode = “triangular2”)
- From the last 2 digits of your student ID, take the remainder of each by 4 and it will
be the 2 learning rates you will have to plot
- For example, 20237672 -> 72 -> 7 % 4 = 3 (CyclicLR) and 2 % 4 = 2
(CosineAnnealingLR) ; if you get the same number twice, do the n+1 one, e.g. 37 -> 3
and 3 -> 3 and 0
- Except from the mentioned parameters, everything else will be of your choice
- Note:get_last_lr() or optimizer.__dict__['param_groups'][0]['lr'] can be helpful
4,
a, Implement VGG 16 with a 224x224 input, adding BatchNorm2d after each conv+ReLU
layer except for the ones before max pool layers(as shown in the image)
b, How many extra learnable parameters are there compared to the one without
batchnorm?