MCPcopy Create free account
hub / github.com/MotrixLab/ADHMR / ScoreNet

Class ScoreNet

HMR-Scorer/common/nets/scorernet.py:119–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117
118
119class ScoreNet(nn.Module):
120 def __init__(self, scorehypo_cfg, neighbour_matrix=None):
121 super(ScoreNet, self).__init__()
122 self.joint_ch = scorehypo_cfg.scorenet.joint_ch
123 self.joints = scorehypo_cfg.hyponet.num_joints
124 self.num_twists = scorehypo_cfg.hyponet.num_twists
125 self.num_item = self.num_twists + self.joints
126 self.num_blocks = scorehypo_cfg.scorenet.num_blocks
127 self.dropout_rate = 0.25
128 self.neighbour_matrix = neighbour_matrix
129 self.mask = self.init_mask(self.neighbour_matrix[0])
130 self.mask_twist = self.init_mask(self.neighbour_matrix[1])
131 self.mask_joints = self.init_mask(self.neighbour_matrix[2])
132 self.atten_knn = scorehypo_cfg.scorenet.atten_knn
133 self.local_ch = scorehypo_cfg.hrnet.local_ch
134 parents = np.array([ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 12, 13, 14, 16, 17, 18, 19, 20, 21, 15, 22, 23, 10, 11], dtype=np.int64)
135 self.parents_idx = torch.tensor(parents[1 : 1+self.num_twists])
136 self.child_idx = torch.arange(start=1,end=1+self.num_twists)
137 self.emb_h , self.emb_w = cfg.output_hm_shape[1:]
138 self.mask_list = []
139 assert len(self.atten_knn) == self.num_blocks
140 for i in range(self.num_blocks):
141 mask_i = np.linalg.matrix_power(neighbour_matrix[3], self.atten_knn[i])
142 mask_i = np.array(mask_i!=0, dtype=np.float32)
143 mask_i = self.init_mask(mask_i)
144 mask_i = 1 - mask_i
145 self.mask_list.append(mask_i.bool())
146 self.mask_list_cross_atten = [None for i in range(self.num_blocks)]
147
148 self.ch = self.joint_ch + self.local_ch
149 self.ctx_dim = cfg.feat_dim
150
151
152 # first layer
153 # joints
154 self.linear_start_j = nn.Linear(self.joints*3, self.joints * self.joint_ch)
155 self.bn_start_j = nn.GroupNorm(32, num_channels=self.joints*self.joint_ch)
156 self.activation_start_j = nn.LeakyReLU(negative_slope=0.2)
157 self.dropout_start_j = nn.Dropout(p=self.dropout_rate)
158 # twist
159 self.linear_start_t = nn.Linear(self.num_twists*2, self.num_twists*self.joint_ch)
160 self.bn_start_t = nn.GroupNorm(32, num_channels=self.num_twists*self.joint_ch)
161 self.activation_start_t = nn.LeakyReLU(negative_slope=0.2)
162 self.dropout_start_t = nn.Dropout(p=self.dropout_rate)
163
164 self.ctx_to_x_conv = nn.Conv2d(in_channels=self.ctx_dim, out_channels=self.ch, kernel_size=1)
165 self.deconv = make_deconv_layers([self.ctx_dim, 256])
166
167 self.linear_mlp = nn.Sequential(
168 nn.Linear(self.num_item*self.ch, 1024),
169 nn.GroupNorm(32, num_channels=1024),
170 nn.LeakyReLU(negative_slope=0.2),
171 nn.Dropout(p=self.dropout_rate),
172 # nn.Linear(1024, 1)
173 nn.Linear(1024, 256),
174 nn.Linear(256, 1)
175 )
176 #blocks

Callers 2

get_scorer_modelFunction · 0.90
get_scorehypo_score_netFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected