MCPcopy Create free account
hub / github.com/Vegetebird/GraphMLP / HighResolutionModule

Class HighResolutionModule

demo/lib/hrnet/lib/models/pose_hrnet.py:101–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99
100
101class HighResolutionModule(nn.Module):
102 def __init__(self, num_branches, blocks, num_blocks, num_inchannels,
103 num_channels, fuse_method, multi_scale_output=True):
104 super(HighResolutionModule, self).__init__()
105 self._check_branches(
106 num_branches, blocks, num_blocks, num_inchannels, num_channels)
107
108 self.num_inchannels = num_inchannels
109 self.fuse_method = fuse_method
110 self.num_branches = num_branches
111
112 self.multi_scale_output = multi_scale_output
113
114 self.branches = self._make_branches(
115 num_branches, blocks, num_blocks, num_channels)
116 self.fuse_layers = self._make_fuse_layers()
117 self.relu = nn.ReLU(True)
118
119 def _check_branches(self, num_branches, blocks, num_blocks,
120 num_inchannels, num_channels):
121 if num_branches != len(num_blocks):
122 error_msg = 'NUM_BRANCHES({}) <> NUM_BLOCKS({})'.format(
123 num_branches, len(num_blocks))
124 logger.error(error_msg)
125 raise ValueError(error_msg)
126
127 if num_branches != len(num_channels):
128 error_msg = 'NUM_BRANCHES({}) <> NUM_CHANNELS({})'.format(
129 num_branches, len(num_channels))
130 logger.error(error_msg)
131 raise ValueError(error_msg)
132
133 if num_branches != len(num_inchannels):
134 error_msg = 'NUM_BRANCHES({}) <> NUM_INCHANNELS({})'.format(
135 num_branches, len(num_inchannels))
136 logger.error(error_msg)
137 raise ValueError(error_msg)
138
139 def _make_one_branch(self, branch_index, block, num_blocks, num_channels,
140 stride=1):
141 downsample = None
142 if stride != 1 or \
143 self.num_inchannels[branch_index] != num_channels[branch_index] * block.expansion:
144 downsample = nn.Sequential(
145 nn.Conv2d(
146 self.num_inchannels[branch_index],
147 num_channels[branch_index] * block.expansion,
148 kernel_size=1, stride=stride, bias=False
149 ),
150 nn.BatchNorm2d(
151 num_channels[branch_index] * block.expansion,
152 momentum=BN_MOMENTUM
153 ),
154 )
155
156 layers = []
157 layers.append(
158 block(

Callers 1

_make_stageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected