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

Class Bottleneck

segmentation/backbones/resnet.py:99–307  ·  view source on GitHub ↗

Bottleneck block for ResNet. If style is "pytorch", the stride-two layer is the 3x3 conv layer, if it is "caffe", the stride-two layer is the first 1x1 conv layer.

Source from the content-addressed store, hash-verified

97
98
99class Bottleneck(BaseModule):
100 """Bottleneck block for ResNet.
101
102 If style is "pytorch", the stride-two layer is the 3x3 conv layer, if it is
103 "caffe", the stride-two layer is the first 1x1 conv layer.
104 """
105
106 expansion = 4
107
108 def __init__(self,
109 inplanes,
110 planes,
111 stride=1,
112 dilation=1,
113 downsample=None,
114 style='pytorch',
115 with_cp=False,
116 conv_cfg=None,
117 norm_cfg=dict(type='BN'),
118 dcn=None,
119 plugins=None,
120 init_cfg=None):
121 super(Bottleneck, self).__init__(init_cfg)
122 assert style in ['pytorch', 'caffe']
123 assert dcn is None or isinstance(dcn, dict)
124 assert plugins is None or isinstance(plugins, list)
125 if plugins is not None:
126 allowed_position = ['after_conv1', 'after_conv2', 'after_conv3']
127 assert all(p['position'] in allowed_position for p in plugins)
128
129 self.inplanes = inplanes
130 self.planes = planes
131 self.stride = stride
132 self.dilation = dilation
133 self.style = style
134 self.with_cp = with_cp
135 self.conv_cfg = conv_cfg
136 self.norm_cfg = norm_cfg
137 self.dcn = dcn
138 self.with_dcn = dcn is not None
139 self.plugins = plugins
140 self.with_plugins = plugins is not None
141
142 if self.with_plugins:
143 # collect plugins for conv1/conv2/conv3
144 self.after_conv1_plugins = [
145 plugin['cfg'] for plugin in plugins
146 if plugin['position'] == 'after_conv1'
147 ]
148 self.after_conv2_plugins = [
149 plugin['cfg'] for plugin in plugins
150 if plugin['position'] == 'after_conv2'
151 ]
152 self.after_conv3_plugins = [
153 plugin['cfg'] for plugin in plugins
154 if plugin['position'] == 'after_conv3'
155 ]
156

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected