MCPcopy Create free account
hub / github.com/CausalLearning/robust-unlearnable-examples / WRN

Class WRN

models/resnet.py:109–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107
108
109class WRN(nn.Module):
110 def __init__(self, num_blocks, in_dims, out_dims, wide=10):
111 super(WRN, self).__init__()
112 self.in_planes = 16
113 self.wide = wide
114
115 block = BasicBlock
116
117 self.conv1 = nn.Conv2d(in_dims, self.in_planes, kernel_size=3, stride=1, padding=1, bias=False)
118 self.bn1 = nn.BatchNorm2d(16)
119 self.layer1 = self._make_layer(block, 16, num_blocks[0], stride=1)
120 self.layer2 = self._make_layer(block, 32, num_blocks[1], stride=2)
121 self.layer3 = self._make_layer(block, 64, num_blocks[2], stride=2)
122 self.avgpool = nn.AdaptiveAvgPool2d((1,1))
123 self.linear = nn.Linear(64*wide, out_dims)
124
125 def _make_layer(self, block, planes, num_blocks, stride):
126 strides = [stride] + [1]*(num_blocks-1)
127 layers = []
128 for stride in strides:
129 layers.append(block(self.in_planes, planes, stride, self.wide))
130 self.in_planes = planes * self.wide * block.expansion
131
132 return nn.Sequential(*layers)
133
134 def forward(self, x):
135 out = F.relu(self.bn1(self.conv1(x)))
136 out = self.layer1(out)
137 out = self.layer2(out)
138 out = self.layer3(out)
139 # out = F.avg_pool2d(out, 8)
140 # out = out.view(out.shape[0], -1)
141 out = self.avgpool(out)
142 out = torch.flatten(out, 1)
143 out = self.linear(out)
144 return out
145
146
147def resnet18(in_dims, out_dims):

Callers 1

wrn34_10Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected