def __init__(self, args, joint_topology, origin_offsets: torch.Tensor, device, characters): self.args = args self.joint_topology = joint_topology self.edges = build_edge_topology(joint_topology, torch.zeros((len(joint_topology), 3))) self.fk = ForwardKinematics(args, self.edges) self.height = [] # for normalize ee_loss self.real_height = [] for char in characters: if args.use_sep_ee: h = BVH_file(get_std_bvh(dataset=char)).get_ee_length() else: h = BVH_file(get_std_bvh(dataset=char)).get_height() if args.ee_loss_fact == 'learn': h = torch.tensor(h, dtype=torch.float) else: h = torch.tensor(h, dtype=torch.float, requires_grad=False) self.real_height.append( BVH_file(get_std_bvh(dataset=char)).get_height()) self.height.append(h.unsqueeze(0)) self.real_height = torch.tensor(self.real_height, device=device) self.height = torch.cat(self.height, dim=0) self.height = self.height.to(device) if not args.use_sep_ee: self.height.unsqueeze_(-1) if args.ee_loss_fact == 'learn': self.height_para = [self.height] else: self.height_para = [] if not args.simple_operator: self.auto_encoder = AE(args, topology=self.edges).to(device) self.discriminator = Discriminator(args, self.edges).to(device) self.static_encoder = StaticEncoder(args, self.edges).to(device) else: raise Exception('Conventional operator not yet implemented')
def __init__(self, file_path=None, args=None, dataset=None, new_root=None): if file_path is None: file_path = get_std_bvh(dataset=dataset) self.anim, self._names, self.frametime = BVH.load(file_path) if new_root is not None: self.set_new_root(new_root) self.skeleton_type = -1 self.edges = [] self.edge_mat = [] self.edge_num = 0 self._topology = None self.ee_length = [] for i, name in enumerate(self._names): if ':' in name: name = name[name.find(':') + 1:] self._names[i] = name full_fill = [1] * len(corps_names) for i, ref_names in enumerate(corps_names): for ref_name in ref_names: if ref_name not in self._names: full_fill[i] = 0 break if full_fill[3]: self.skeleton_type = 3 else: for i, _ in enumerate(full_fill): if full_fill[i]: self.skeleton_type = i break if self.skeleton_type == 2 and full_fill[4]: self.skeleton_type = 4 if 'Neck1' in self._names: self.skeleton_type = 5 if 'Left_End' in self._names: self.skeleton_type = 6 if 'Three_Arms_Hips' in self._names: self.skeleton_type = 7 if 'Three_Arms_Hips_split' in self._names: self.skeleton_type = 8 if 'LHipJoint' in self._names: self.skeleton_type = 3 if 'HipsPrisoner' in self._names: self.skeleton_type = 9 if 'Spine1_split' in self._names: self.skeleton_type = 10 """ 4. Here, you need to assign self.skeleton_type the corresponding index of your own dataset in corps_names or ee_names list. You can use self._names, which contains the joints name in original bvh file, to write your own if statement. """ # if ...: # self.skeleton_type = 11 if self.skeleton_type == -1: print(self._names) raise Exception('Unknown skeleton') if self.skeleton_type == 0: self.set_new_root(1) self.details = [] for i, name in enumerate(self._names): if ':' in name: name = name[name.find(':') + 1:] if name not in corps_names[self.skeleton_type]: self.details.append(i) self.joint_num = self.anim.shape[1] self.corps = [] self.simplified_name = [] self.simplify_map = {} self.inverse_simplify_map = {} for name in corps_names[self.skeleton_type]: for j in range(self.anim.shape[1]): if name == self._names[j]: self.corps.append(j) break if len(self.corps) != len(corps_names[self.skeleton_type]): for i in self.corps: print(self._names[i], end=' ') print(self.corps, self.skeleton_type, len(self.corps), sep='\n') raise Exception('Problem in file', file_path) self.ee_id = [] for i in ee_names[self.skeleton_type]: self.ee_id.append(corps_names[self.skeleton_type].index(i)) self.joint_num_simplify = len(self.corps) for i, j in enumerate(self.corps): self.simplify_map[j] = i self.inverse_simplify_map[i] = j self.simplified_name.append(self._names[j]) self.inverse_simplify_map[0] = -1 for i in range(self.anim.shape[1]): if i in self.details: self.simplify_map[i] = -1 self.edges = build_edge_topology(self.topology, self.offset)