MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / BasicBlock

Class BasicBlock

Image_Classification/src/models/resnet.py:47–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46
47class BasicBlock(nn.Module):
48 expansion = 1
49
50 def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1,
51 base_width=64, dilation=1, norm_layer=None):
52 super(BasicBlock, self).__init__()
53 if norm_layer is None:
54 norm_layer = nn.BatchNorm2d
55 if groups != 1 or base_width != 64:
56 raise ValueError(
57 'BasicBlock only supports groups=1 and base_width=64')
58 if dilation > 1:
59 raise NotImplementedError(
60 "Dilation > 1 not supported in BasicBlock")
61 # Both self.conv1 and self.downsample layers downsample the input when stride != 1
62 self.conv1 = conv3x3(inplanes, planes, stride)
63 self.bn1 = norm_layer(planes)
64 self.relu = nn.ReLU(inplace=False)
65 self.conv2 = conv3x3(planes, planes)
66 self.bn2 = norm_layer(planes)
67 self.downsample = downsample
68 self.stride = stride
69
70 def forward(self, x):
71 identity = x
72
73 out = self.conv1(x)
74 out = self.bn1(out)
75 out = self.relu(out)
76
77 out = self.conv2(out)
78 out = self.bn2(out)
79
80 if self.downsample is not None:
81 identity = self.downsample(x)
82
83 out = out + identity
84 out = self.relu(out)
85
86 return out
87
88
89class Bottleneck(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected