MCPcopy Create free account
hub / github.com/MotrixLab/MotionDiffuse / Text2MotionDataset

Class Text2MotionDataset

text2motion/datasets/dataset.py:11–164  ·  view source on GitHub ↗

Dataset for Text2Motion generation task.

Source from the content-addressed store, hash-verified

9
10
11class Text2MotionDataset(data.Dataset):
12 """Dataset for Text2Motion generation task.
13
14 """
15 def __init__(self, opt, mean, std, split_file, times=1, w_vectorizer=None, eval_mode=False):
16 self.opt = opt
17 self.max_length = 20
18 self.times = times
19 self.w_vectorizer = w_vectorizer
20 self.eval_mode = eval_mode
21 min_motion_len = 40 if self.opt.dataset_name =='t2m' else 24
22
23 joints_num = opt.joints_num
24
25 data_dict = {}
26 id_list = []
27 with cs.open(split_file, 'r') as f:
28 for line in f.readlines():
29 id_list.append(line.strip())
30
31 new_name_list = []
32 length_list = []
33 for name in tqdm(id_list):
34 try:
35 motion = np.load(pjoin(opt.motion_dir, name + '.npy'))
36 if (len(motion)) < min_motion_len or (len(motion) >= 200):
37 continue
38 text_data = []
39 flag = False
40 with cs.open(pjoin(opt.text_dir, name + '.txt')) as f:
41 for line in f.readlines():
42 text_dict = {}
43 line_split = line.strip().split('#')
44 caption = line_split[0]
45 tokens = line_split[1].split(' ')
46 f_tag = float(line_split[2])
47 to_tag = float(line_split[3])
48 f_tag = 0.0 if np.isnan(f_tag) else f_tag
49 to_tag = 0.0 if np.isnan(to_tag) else to_tag
50
51 text_dict['caption'] = caption
52 text_dict['tokens'] = tokens
53 if f_tag == 0.0 and to_tag == 0.0:
54 flag = True
55 text_data.append(text_dict)
56 else:
57 n_motion = motion[int(f_tag*20) : int(to_tag*20)]
58 if (len(n_motion)) < min_motion_len or (len(n_motion) >= 200):
59 continue
60 new_name = random.choice('ABCDEFGHIJKLMNOPQRSTUVW') + '_' + name
61 while new_name in data_dict:
62 new_name = random.choice('ABCDEFGHIJKLMNOPQRSTUVW') + '_' + name
63 data_dict[new_name] = {'motion': n_motion,
64 'length': len(n_motion),
65 'text':[text_dict]}
66 new_name_list.append(new_name)
67 length_list.append(len(n_motion))
68

Callers 1

train.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected