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

Method __getitem__

text2motion/datasets/dataset.py:121–164  ·  view source on GitHub ↗
(self, item)

Source from the content-addressed store, hash-verified

119 return self.real_len() * self.times
120
121 def __getitem__(self, item):
122 idx = item % self.real_len()
123 data = self.data_dict[self.name_list[idx]]
124 motion, m_length, text_list = data['motion'], data['length'], data['text']
125 # Randomly select a caption
126 text_data = random.choice(text_list)
127 caption = text_data['caption']
128
129 max_motion_length = self.opt.max_motion_length
130 if m_length >= self.opt.max_motion_length:
131 idx = random.randint(0, len(motion) - max_motion_length)
132 motion = motion[idx: idx + max_motion_length]
133 else:
134 padding_len = max_motion_length - m_length
135 D = motion.shape[1]
136 padding_zeros = np.zeros((padding_len, D))
137 motion = np.concatenate((motion, padding_zeros), axis=0)
138
139 assert len(motion) == max_motion_length
140 "Z Normalization"
141 motion = (motion - self.mean) / self.std
142
143 if self.eval_mode:
144 tokens = text_data['tokens']
145 if len(tokens) < self.opt.max_text_len:
146 # pad with "unk"
147 tokens = ['sos/OTHER'] + tokens + ['eos/OTHER']
148 sent_len = len(tokens)
149 tokens = tokens + ['unk/OTHER'] * (self.opt.max_text_len + 2 - sent_len)
150 else:
151 # crop
152 tokens = tokens[:self.opt.max_text_len]
153 tokens = ['sos/OTHER'] + tokens + ['eos/OTHER']
154 sent_len = len(tokens)
155 pos_one_hots = []
156 word_embeddings = []
157 for token in tokens:
158 word_emb, pos_oh = self.w_vectorizer[token]
159 pos_one_hots.append(pos_oh[None, :])
160 word_embeddings.append(word_emb[None, :])
161 pos_one_hots = np.concatenate(pos_one_hots, axis=0)
162 word_embeddings = np.concatenate(word_embeddings, axis=0)
163 return word_embeddings, pos_one_hots, caption, sent_len, motion, m_length
164 return caption, motion, m_length

Callers

nothing calls this directly

Calls 1

real_lenMethod · 0.95

Tested by

no test coverage detected