Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
norm(nf * 4, momentum=alpha),
nn.LeakyReLU(0.1),
nn.ConvTranspose2d(nf * 4, nf, kernel_size=4, stride=2, padding=1),
norm(nf, momentum=alpha),
nn.LeakyReLU(0.1),
nn.Conv2d(nf, nf, kernel_size=3, stride=1, padding=1),
norm(nf, momentum=alpha),
nn.LeakyReLU(0.1),
nn.ConvTranspose2d(nf, nf // 4, kernel_size=4, stride=2, padding=1),
norm(nf // 4, momentum=alpha),
nn.LeakyReLU(0.1),
nn.Conv2d(nf // 4, nf // 4, kernel_size=3, stride=1, padding=1),
norm(nf // 4, momentum=alpha),
nn.LeakyReLU(0.1),
nn.Conv2d(nf // 4, 3, kernel_size=3, stride=1, padding=1),
)
def test_given_params(self, mock_clip):
model = nn.Sequential(nn.Conv2d(3, 3, 3))
model.parameters = Mock(return_value=-1)
state = {torchbearer.MODEL: model}
clipper = GradientNormClipping(5, params=model.parameters())
clipper.on_start(state)
clipper.on_backward(state)
self.assertTrue(mock_clip.mock_calls[0][1][0] == -1)
activation_fn,
nn.Conv2d(1024, 2048, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
nn.BatchNorm2d(2048),
),
Lambda(lambda x: x), # Identity,
),
LambdaReduce(lambda x, y: x + y), # CAddTable,
activation_fn,
),
nn.Sequential( # Sequential,
LambdaMap(lambda x: x, # ConcatTable,
nn.Sequential( # Sequential,
nn.Conv2d(2048, 1024, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
nn.BatchNorm2d(1024),
activation_fn,
nn.Conv2d(1024, 1024, (3, 3), (1, 1), (1, 1), 1, 1, bias=False),
nn.BatchNorm2d(1024),
activation_fn,
nn.Conv2d(1024, 2048, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
nn.BatchNorm2d(2048),
),
Lambda(lambda x: x), # Identity,
),
LambdaReduce(lambda x, y: x + y), # CAddTable,
activation_fn,
),
),
)
return features
def __init__(self, inplanes, planes, groups, reduction, stride=1, downsample=None):
super(SEResNetBottleneck, self).__init__()
self.conv1 = nn.Conv2d(
inplanes, planes, kernel_size=1, bias=False, stride=stride
)
self.bn1 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(
planes, planes, kernel_size=3, padding=1, groups=groups, bias=False
)
self.bn2 = nn.BatchNorm2d(planes)
self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
self.bn3 = nn.BatchNorm2d(planes * 4)
self.relu = nn.ReLU(inplace=True)
self.se_module = SEModule(planes * 4, reduction=reduction)
self.downsample = downsample
self.stride = stride
Args:
baseWidth: baseWidth for AIRX.
cardinality: number of convolution groups.
layers: config of layers, e.g., [3, 4, 6, 3]
num_classes: number of classes
"""
super(AIRX, self).__init__()
block = AIRXBottleneck
self.cardinality = cardinality
self.baseWidth = baseWidth
self.inplanes = 64
self.head7x7 = head7x7
if self.head7x7:
self.conv1 = nn.Conv2d(3, 64, 7, 2, 3, bias=False)
self.bn1 = nn.BatchNorm2d(64)
else:
self.conv1 = nn.Conv2d(3, 32, 3, 2, 1, bias=False)
self.bn1 = nn.BatchNorm2d(32)
self.conv2 = nn.Conv2d(32, 32, 3, 1, 1, bias=False)
self.bn2 = nn.BatchNorm2d(32)
self.conv3 = nn.Conv2d(32, 64, 3, 1, 1, bias=False)
self.bn3 = nn.BatchNorm2d(64)
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
self.layer1 = self._make_layer(block, 64, layers[0])
self.layer2 = self._make_layer(block, 128, layers[1], 2)
self.layer3 = self._make_layer(block, 256, layers[2], 2)
self.layer4 = self._make_layer(block, 512, layers[3], 2)
self.avgpool = nn.AdaptiveAvgPool2d(1)
"""
Convolutional NAS model.
"""
c1, c2 = h1, h2
one = Convolution(in_size=(1, 28, 28), out_channels=c1, k=arg.k[0], kernel_size=7,
gadditional=arg.gadditional[0], radditional=arg.radditional[1], rprop=arg.range[0],
min_sigma=arg.min_sigma, sigma_scale=arg.sigma_scale,
fix_values=arg.fix_values, has_bias=True)
two = Convolution(in_size=(c1, 14, 14), out_channels=c2, k=arg.k[1], kernel_size=7,
gadditional=arg.gadditional[1], radditional=arg.radditional[1], rprop=arg.range[1],
min_sigma=arg.min_sigma, sigma_scale=arg.sigma_scale,
fix_values=arg.fix_values, has_bias=True)
three = nn.Conv2d(c2, numcls, kernel_size=3, padding=1)
model = nn.Sequential(
one, nn.Sigmoid(), nn.MaxPool2d(2),
two, nn.Sigmoid(), nn.MaxPool2d(2),
three, nn.Sigmoid(), nn.MaxPool2d(2),
util.Lambda(lambda x : x.mean(dim=-1).mean(dim=-1)), # global average pool
nn.Softmax()
)
else:
raise Exception('Method {} not recognized'.format(arg.method))
if arg.cuda:
model.cuda()
return model, one, two, three
def __init__(self, inplanes, planes, stride=1, downsample=None):
super(Bottleneck, self).__init__()
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,
padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)
self.conv3 = nn.Conv2d(planes, planes * self.expansion, kernel_size=1,
bias=False)
self.bn3 = nn.BatchNorm2d(planes * self.expansion,
momentum=BN_MOMENTUM)
self.relu = nn.ReLU(inplace=True)
self.downsample = downsample
self.stride = stride
def __init__(self):
super(VGGFeature, self).__init__()
self.conv1_1 = torch.nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1)
self.conv1_2 = torch.nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1)
self.conv2_1 = torch.nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)
self.conv2_2 = torch.nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1)
self.conv3_1 = torch.nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1)
self.conv3_2 = torch.nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
self.conv3_3 = torch.nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
self.conv4_1 = torch.nn.Conv2d(256, 512, kernel_size=3, stride=1, padding=1)
self.conv4_2 = torch.nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)
self.conv4_3 = torch.nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)
self.conv5_1 = torch.nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)
self.conv5_2 = torch.nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)
self.conv5_3 = torch.nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)
def __init__(self, opt):
super(AlexSal, self).__init__()
self.features = nn.Sequential(
*list(torch.load(opt.placesmodelpath).features.children())[:-2]
)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
self.conv6 = nn.Conv2d(256, 1, kernel_size=(1, 1), stride=(1, 1))
def __init__(self, in_channels, out_channels, dropout=False):
super(_EncoderBlock, self).__init__()
layers = [
nn.Conv2d(in_channels, out_channels, kernel_size=3),
nn.BatchNorm2d(out_channels),
nn.ReLU(inplace=True),
nn.Conv2d(out_channels, out_channels, kernel_size=3),
nn.BatchNorm2d(out_channels),
nn.ReLU(inplace=True),
]
if dropout:
layers.append(nn.Dropout())
layers.append(nn.MaxPool2d(kernel_size=2, stride=2))
self.encode = nn.Sequential(*layers)