MCPcopy Create free account
hub / github.com/InternRobotics/EmbodiedScan / MinkResNet

Class MinkResNet

embodiedscan/models/backbones/mink_resnet.py:21–140  ·  view source on GitHub ↗

r"""Minkowski ResNet backbone. See `4D Spatio-Temporal ConvNets `_ for more details. Args: depth (int): Depth of resnet, from {18, 34, 50, 101, 152}. in_channels (int): Number of input channels, 3 for RGB. num_stages (int): Resnet st

Source from the content-addressed store, hash-verified

19
20@MODELS.register_module()
21class MinkResNet(BaseModule):
22 r"""Minkowski ResNet backbone. See `4D Spatio-Temporal ConvNets
23 <https://arxiv.org/abs/1904.08755>`_ for more details.
24
25 Args:
26 depth (int): Depth of resnet, from {18, 34, 50, 101, 152}.
27 in_channels (int): Number of input channels, 3 for RGB.
28 num_stages (int): Resnet stages. Defaults to 4.
29 pool (bool): Whether to add max pooling after first conv.
30 Defaults to True.
31 """
32 arch_settings = {
33 18: (BasicBlock, (2, 2, 2, 2)),
34 34: (BasicBlock, (3, 4, 6, 3)),
35 50: (Bottleneck, (3, 4, 6, 3)),
36 101: (Bottleneck, (3, 4, 23, 3)),
37 152: (Bottleneck, (3, 8, 36, 3))
38 }
39
40 def __init__(self,
41 depth: int,
42 in_channels: int,
43 num_stages: int = 4,
44 pool: bool = True):
45 super(MinkResNet, self).__init__()
46 if ME is None:
47 raise ImportError(
48 'Please follow `get_started.md` to install MinkowskiEngine.`')
49 if depth not in self.arch_settings:
50 raise KeyError(f'invalid depth {depth} for resnet')
51 assert 4 >= num_stages >= 1
52 block, stage_blocks = self.arch_settings[depth]
53 stage_blocks = stage_blocks[:num_stages]
54 self.num_stages = num_stages
55 self.pool = pool
56
57 self.inplanes = 64
58 self.conv1 = ME.MinkowskiConvolution(in_channels,
59 self.inplanes,
60 kernel_size=3,
61 stride=2,
62 dimension=3)
63 # May be BatchNorm is better, but we follow original implementation.
64 self.norm1 = ME.MinkowskiInstanceNorm(self.inplanes)
65 self.relu = ME.MinkowskiReLU(inplace=True)
66 if self.pool:
67 self.maxpool = ME.MinkowskiMaxPooling(kernel_size=2,
68 stride=2,
69 dimension=3)
70
71 for i in range(len(stage_blocks)):
72 setattr(
73 self, f'layer{i + 1}',
74 self._make_layer(block, 64 * 2**i, stage_blocks[i], stride=2))
75
76 def init_weights(self):
77 """Initialize weights."""
78 for m in self.modules():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected