def _make_layers(self, cfg): layers = [] in_channels = 3 for layer_index, x in enumerate(cfg): if x == 'M': # append max pooling layer layers += [nn.MaxPool2d(kernel_size=2, stride=2)] else: # append conv->(bn/gn)->activation layer # determine activation function: we use tanh for last layer if self.use_tanh is set to True is_last_layer = True for xx in cfg[layer_index + 1:]: if xx != 'M': is_last_layer = False if self.use_tanh and is_last_layer: activation = nn.Tanh() else: activation = nn.ReLU(inplace=True) layers += [ nn.Conv2d(in_channels, x, kernel_size=3, padding=1), normalization(self.normalization_type, x), activation ] in_channels = x # imagenet vgg13 does not do that # layers += [nn.AvgPool2d(kernel_size=1, stride=1)] return nn.Sequential(*layers)
def normalization16(normalization_type, planes): return normalization(normalization_type, planes, group_size=16)