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

Method __init__

ADHMR/lib/models/scorenet.py:116–166  ·  view source on GitHub ↗
(self, cfg, neighbour_matrix=None)

Source from the content-addressed store, hash-verified

114
115class ScoreNet(nn.Module):
116 def __init__(self, cfg, neighbour_matrix=None):
117 super(ScoreNet, self).__init__()
118 self.joint_ch = cfg.scorenet.joint_ch
119 self.joints = cfg.hyponet.num_joints
120 self.num_twists = cfg.hyponet.num_twists
121 self.num_item = self.num_twists+self.joints
122 self.num_blocks = cfg.scorenet.num_blocks
123 self.dropout_rate = 0.25
124 self.neighbour_matrix = neighbour_matrix
125 self.mask = self.init_mask(self.neighbour_matrix[0])
126 self.mask_twist = self.init_mask(self.neighbour_matrix[1])
127 self.mask_joints = self.init_mask(self.neighbour_matrix[2])
128 self.atten_knn = cfg.scorenet.atten_knn
129 self.local_ch = cfg.hrnet.local_ch
130 self.parents_idx = torch.tensor(parents[1:1+self.num_twists])
131 self.child_idx = torch.arange(start=1,end=1+self.num_twists)
132 self.emb_h , self.emb_w = int(cfg.hrnet.image_size[0]/ 32), int(cfg.hrnet.image_size[1]/ 32)
133 self.mask_list = []
134 assert len(self.atten_knn) == self.num_blocks
135 for i in range(self.num_blocks):
136 mask_i = np.linalg.matrix_power(neighbour_matrix[3], self.atten_knn[i])
137 mask_i = np.array(mask_i!=0, dtype=np.float32)
138 mask_i = self.init_mask(mask_i)
139 mask_i = 1 - mask_i
140 self.mask_list.append(mask_i.bool())
141 self.mask_list_cross_atten = [None for i in range(self.num_blocks)]
142
143 self.ch = self.joint_ch + self.local_ch
144
145
146 # first layer
147 # joints
148 self.linear_start_j = nn.Linear(self.joints*3, self.joints*self.joint_ch)
149 self.bn_start_j = nn.GroupNorm(32, num_channels=self.joints*self.joint_ch)
150 self.activation_start_j = nn.LeakyReLU(negative_slope=0.2)
151 self.dropout_start_j = nn.Dropout(p=self.dropout_rate)
152 # twist
153 self.linear_start_t = nn.Linear(self.num_twists*2, self.num_twists*self.joint_ch)
154 self.bn_start_t = nn.GroupNorm(32, num_channels=self.num_twists*self.joint_ch)
155 self.activation_start_t = nn.LeakyReLU(negative_slope=0.2)
156 self.dropout_start_t = nn.Dropout(p=self.dropout_rate)
157
158 self.linear_mlp = nn.Sequential(
159 nn.Linear(self.num_item*self.ch, 1024),
160 nn.GroupNorm(32, num_channels=1024),
161 nn.LeakyReLU(negative_slope=0.2),
162 nn.Dropout(p=self.dropout_rate),
163 nn.Linear(1024,1)
164 )
165 #blocks
166 self.blocks = nn.ModuleList([DecoderLayer(cfg,self.ch) for i in range(self.num_blocks)])
167
168 def init_mask(self,neighbour_matrix):
169 """

Callers 1

__init__Method · 0.45

Calls 2

init_maskMethod · 0.95
DecoderLayerClass · 0.70

Tested by

no test coverage detected