MCPcopy
hub / github.com/princeton-vl/RAFT / __init__

Method __init__

core/extractor.py:119–157  ·  view source on GitHub ↗
(self, output_dim=128, norm_fn='batch', dropout=0.0)

Source from the content-addressed store, hash-verified

117
118class BasicEncoder(nn.Module):
119 def __init__(self, output_dim=128, norm_fn='batch', dropout=0.0):
120 super(BasicEncoder, self).__init__()
121 self.norm_fn = norm_fn
122
123 if self.norm_fn == 'group':
124 self.norm1 = nn.GroupNorm(num_groups=8, num_channels=64)
125
126 elif self.norm_fn == 'batch':
127 self.norm1 = nn.BatchNorm2d(64)
128
129 elif self.norm_fn == 'instance':
130 self.norm1 = nn.InstanceNorm2d(64)
131
132 elif self.norm_fn == 'none':
133 self.norm1 = nn.Sequential()
134
135 self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3)
136 self.relu1 = nn.ReLU(inplace=True)
137
138 self.in_planes = 64
139 self.layer1 = self._make_layer(64, stride=1)
140 self.layer2 = self._make_layer(96, stride=2)
141 self.layer3 = self._make_layer(128, stride=2)
142
143 # output convolution
144 self.conv2 = nn.Conv2d(128, output_dim, kernel_size=1)
145
146 self.dropout = None
147 if dropout > 0:
148 self.dropout = nn.Dropout2d(p=dropout)
149
150 for m in self.modules():
151 if isinstance(m, nn.Conv2d):
152 nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
153 elif isinstance(m, (nn.BatchNorm2d, nn.InstanceNorm2d, nn.GroupNorm)):
154 if m.weight is not None:
155 nn.init.constant_(m.weight, 1)
156 if m.bias is not None:
157 nn.init.constant_(m.bias, 0)
158
159 def _make_layer(self, dim, stride=1):
160 layer1 = ResidualBlock(self.in_planes, dim, self.norm_fn, stride=stride)

Callers 3

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 1

_make_layerMethod · 0.95

Tested by

no test coverage detected