(self, item)
| 225 | return len(self.data_dict) - self.pointer |
| 226 | |
| 227 | def __getitem__(self, item): |
| 228 | idx = self.pointer + item |
| 229 | data = self.data_dict[self.name_list[idx]] |
| 230 | motion, m_length, text_list = data['motion'], data['length'], data['text'] |
| 231 | # Randomly select a caption |
| 232 | text_data = random.choice(text_list) |
| 233 | caption, tokens = text_data['caption'], text_data['tokens'] |
| 234 | |
| 235 | if len(tokens) < self.opt.max_text_len: |
| 236 | # pad with "unk" |
| 237 | tokens = ['sos/OTHER'] + tokens + ['eos/OTHER'] |
| 238 | sent_len = len(tokens) |
| 239 | tokens = tokens + ['unk/OTHER'] * (self.opt.max_text_len + 2 - sent_len) |
| 240 | else: |
| 241 | # crop |
| 242 | tokens = tokens[:self.opt.max_text_len] |
| 243 | tokens = ['sos/OTHER'] + tokens + ['eos/OTHER'] |
| 244 | sent_len = len(tokens) |
| 245 | pos_one_hots = [] |
| 246 | word_embeddings = [] |
| 247 | for token in tokens: |
| 248 | word_emb, pos_oh = self.w_vectorizer[token] |
| 249 | pos_one_hots.append(pos_oh[None, :]) |
| 250 | word_embeddings.append(word_emb[None, :]) |
| 251 | pos_one_hots = np.concatenate(pos_one_hots, axis=0) |
| 252 | word_embeddings = np.concatenate(word_embeddings, axis=0) |
| 253 | |
| 254 | # Crop the motions in to times of 4, and introduce small variations |
| 255 | if self.opt.unit_length < 10: |
| 256 | coin2 = np.random.choice(['single', 'single', 'double']) |
| 257 | else: |
| 258 | coin2 = 'single' |
| 259 | |
| 260 | if coin2 == 'double': |
| 261 | m_length = (m_length // self.opt.unit_length - 1) * self.opt.unit_length |
| 262 | elif coin2 == 'single': |
| 263 | m_length = (m_length // self.opt.unit_length) * self.opt.unit_length |
| 264 | idx = random.randint(0, len(motion) - m_length) |
| 265 | motion = motion[idx:idx+m_length] |
| 266 | |
| 267 | "Z Normalization" |
| 268 | motion = (motion - self.mean) / self.std |
| 269 | |
| 270 | if m_length < self.max_motion_length: |
| 271 | motion = np.concatenate([motion, |
| 272 | np.zeros((self.max_motion_length - m_length, motion.shape[1])) |
| 273 | ], axis=0) |
| 274 | return word_embeddings, pos_one_hots, caption, sent_len, motion, m_length, '_'.join(tokens) |
| 275 | |
| 276 | |
| 277 | def get_dataset_motion_loader(opt_path, batch_size, device): |
nothing calls this directly
no outgoing calls
no test coverage detected