MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / BasicBlock

Class BasicBlock

segmentation/backbones/resnet.py:14–96  ·  view source on GitHub ↗

Basic block for ResNet.

Source from the content-addressed store, hash-verified

12
13
14class BasicBlock(BaseModule):
15 """Basic block for ResNet."""
16
17 expansion = 1
18
19 def __init__(self,
20 inplanes,
21 planes,
22 stride=1,
23 dilation=1,
24 downsample=None,
25 style='pytorch',
26 with_cp=False,
27 conv_cfg=None,
28 norm_cfg=dict(type='BN'),
29 dcn=None,
30 plugins=None,
31 init_cfg=None):
32 super(BasicBlock, self).__init__(init_cfg)
33 assert dcn is None, 'Not implemented yet.'
34 assert plugins is None, 'Not implemented yet.'
35
36 self.norm1_name, norm1 = build_norm_layer(norm_cfg, planes, postfix=1)
37 self.norm2_name, norm2 = build_norm_layer(norm_cfg, planes, postfix=2)
38
39 self.conv1 = build_conv_layer(
40 conv_cfg,
41 inplanes,
42 planes,
43 3,
44 stride=stride,
45 padding=dilation,
46 dilation=dilation,
47 bias=False)
48 self.add_module(self.norm1_name, norm1)
49 self.conv2 = build_conv_layer(
50 conv_cfg, planes, planes, 3, padding=1, bias=False)
51 self.add_module(self.norm2_name, norm2)
52
53 self.relu = nn.ReLU(inplace=True)
54 self.downsample = downsample
55 self.stride = stride
56 self.dilation = dilation
57 self.with_cp = with_cp
58
59 @property
60 def norm1(self):
61 """nn.Module: normalization layer after the first convolution layer"""
62 return getattr(self, self.norm1_name)
63
64 @property
65 def norm2(self):
66 """nn.Module: normalization layer after the second convolution layer"""
67 return getattr(self, self.norm2_name)
68
69 def forward(self, x):
70 """Forward function."""
71

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected