MCPcopy Index your code
hub / github.com/MotrixLab/MotionDiffuse / __init__

Method __init__

text2motion/datasets/evaluator.py:140–213  ·  view source on GitHub ↗
(self, opt, mean, std, split_file, w_vectorizer)

Source from the content-addressed store, hash-verified

138'''For use of training text motion matching model, and evaluations'''
139class Text2MotionDatasetV2(Dataset):
140 def __init__(self, opt, mean, std, split_file, w_vectorizer):
141 self.opt = opt
142 self.w_vectorizer = w_vectorizer
143 self.max_length = 20
144 self.pointer = 0
145 self.max_motion_length = opt.max_motion_length
146 min_motion_len = 40 if self.opt.dataset_name =='t2m' else 24
147
148 data_dict = {}
149 id_list = []
150 with cs.open(split_file, 'r') as f:
151 for line in f.readlines():
152 id_list.append(line.strip())
153
154 new_name_list = []
155 length_list = []
156 for name in tqdm(id_list):
157 try:
158 motion = np.load(pjoin(opt.motion_dir, name + '.npy'))
159 if (len(motion)) < min_motion_len or (len(motion) >= 200):
160 continue
161 text_data = []
162 flag = False
163 with cs.open(pjoin(opt.text_dir, name + '.txt')) as f:
164 for line in f.readlines():
165 text_dict = {}
166 line_split = line.strip().split('#')
167 caption = line_split[0]
168 tokens = line_split[1].split(' ')
169 f_tag = float(line_split[2])
170 to_tag = float(line_split[3])
171 f_tag = 0.0 if np.isnan(f_tag) else f_tag
172 to_tag = 0.0 if np.isnan(to_tag) else to_tag
173
174 text_dict['caption'] = caption
175 text_dict['tokens'] = tokens
176 if f_tag == 0.0 and to_tag == 0.0:
177 flag = True
178 text_data.append(text_dict)
179 else:
180 try:
181 n_motion = motion[int(f_tag*20) : int(to_tag*20)]
182 if (len(n_motion)) < min_motion_len or (len(n_motion) >= 200):
183 continue
184 new_name = random.choice('ABCDEFGHIJKLMNOPQRSTUVW') + '_' + name
185 while new_name in data_dict:
186 new_name = random.choice('ABCDEFGHIJKLMNOPQRSTUVW') + '_' + name
187 data_dict[new_name] = {'motion': n_motion,
188 'length': len(n_motion),
189 'text':[text_dict]}
190 new_name_list.append(new_name)
191 length_list.append(len(n_motion))
192 except:
193 print(line_split)
194 print(line_split[2], line_split[3], f_tag, to_tag, name)
195 # break
196
197 if flag:

Callers

nothing calls this directly

Calls 2

reset_max_lenMethod · 0.95
loadMethod · 0.80

Tested by

no test coverage detected