MCPcopy Create free account
hub / github.com/TorchSSL/TorchSSL / __init__

Method __init__

models/nets/wrn_var.py:72–112  ·  view source on GitHub ↗
(self, first_stride, num_classes, depth=28, widen_factor=2, drop_rate=0.0, is_remix=False)

Source from the content-addressed store, hash-verified

70
71class WideResNetVar(nn.Module):
72 def __init__(self, first_stride, num_classes, depth=28, widen_factor=2, drop_rate=0.0, is_remix=False):
73 super(WideResNetVar, self).__init__()
74 channels = [16, 16 * widen_factor, 32 * widen_factor, 64 * widen_factor, 128 * widen_factor]
75 assert ((depth - 4) % 6 == 0)
76 n = (depth - 4) / 6
77 block = BasicBlock
78 # 1st conv before any network block
79 self.conv1 = nn.Conv2d(3, channels[0], kernel_size=3, stride=1,
80 padding=1, bias=True)
81 # 1st block
82 self.block1 = NetworkBlock(
83 n, channels[0], channels[1], block, first_stride, drop_rate, activate_before_residual=True)
84 # 2nd block
85 self.block2 = NetworkBlock(
86 n, channels[1], channels[2], block, 2, drop_rate)
87 # 3rd block
88 self.block3 = NetworkBlock(
89 n, channels[2], channels[3], block, 2, drop_rate)
90 # 4th block
91 self.block4 = NetworkBlock(
92 n, channels[3], channels[4], block, 2, drop_rate)
93 # global average pooling and classifier
94 self.bn1 = nn.BatchNorm2d(channels[4], momentum=0.001, eps=0.001)
95 self.relu = nn.LeakyReLU(negative_slope=0.1, inplace=False)
96 self.fc = nn.Linear(channels[4], num_classes)
97 self.channels = channels[4]
98
99 # rot_classifier for Remix Match
100 self.is_remix = is_remix
101 if is_remix:
102 self.rot_classifier = nn.Linear(self.channels, 4)
103
104 for m in self.modules():
105 if isinstance(m, nn.Conv2d):
106 nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='leaky_relu')
107 elif isinstance(m, nn.BatchNorm2d):
108 m.weight.data.fill_(1)
109 m.bias.data.zero_()
110 elif isinstance(m, nn.Linear):
111 nn.init.xavier_normal_(m.weight.data)
112 m.bias.data.zero_()
113
114 def forward(self, x, ood_test=False):
115 out = self.conv1(x)

Callers

nothing calls this directly

Calls 2

NetworkBlockClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected