in ResNetBasic.py [0:0]
def __init__(self,block,list_of_num_layers, list_of_out_dims, num_classes=1000, only_trunk=False ):
# list_of_num_layers specifies number of layers in each stage
# list_of_out_dims specifies number of output channel for each stage
super(ResNet,self).__init__()
self.grads = []
self.fmaps = []
assert len(list_of_num_layers)==4, 'Can have only four stages'
conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
bias=False)
bn1 = nn.BatchNorm2d(64)
relu = nn.ReLU()
pool1 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
init_layer(conv1)
init_layer(bn1)
trunk = [conv1, bn1, relu, pool1]
indim = 64
for i in range(4):
for j in range(list_of_num_layers[i]):
half_res = (i>=1) and (j==0)
B = block(indim, list_of_out_dims[i], half_res)
trunk.append(B)
indim = list_of_out_dims[i]
self.only_trunk=only_trunk
if not only_trunk:
avgpool = nn.AvgPool2d(7)
trunk.append(avgpool)
self.trunk = nn.Sequential(*trunk)
self.final_feat_dim = indim
if not only_trunk:
self.classifier = nn.Linear(indim, num_classes)
self.classifier.bias.data.fill_(0)