| 106 | return self.n_samples |
| 107 | |
| 108 | def get_data(self, idx): |
| 109 | with self.lmdb_env.begin(write=False) as txn: |
| 110 | key = '{:010}'.format(idx).encode('ascii') |
| 111 | sample = txn.get(key) |
| 112 | |
| 113 | sample = pyarrow.deserialize(sample) |
| 114 | word_seq, pose_seq, vec_seq, audio, spectrogram, aux_info = sample |
| 115 | sent = ' '.join([x[0] for x in word_seq]) |
| 116 | |
| 117 | def extend_word_seq(lang, words, end_time=None): |
| 118 | n_frames = self.n_poses |
| 119 | if end_time is None: |
| 120 | end_time = aux_info['end_time'] |
| 121 | frame_duration = (end_time - aux_info['start_time']) / n_frames |
| 122 | |
| 123 | extended_word_indices = np.zeros(n_frames) # zero is the index of padding token |
| 124 | if self.remove_word_timing: |
| 125 | n_words = 0 |
| 126 | for word in words: |
| 127 | idx = max(0, int(np.floor((word[1] - aux_info['start_time']) / frame_duration))) |
| 128 | if idx < n_frames: |
| 129 | n_words += 1 |
| 130 | space = int(n_frames / (n_words + 1)) |
| 131 | for i in range(n_words): |
| 132 | idx = (i+1) * space |
| 133 | extended_word_indices[idx] = lang.get_word_index(words[i][0]) |
| 134 | else: |
| 135 | prev_idx = 0 |
| 136 | for word in words: |
| 137 | idx = max(0, int(np.floor((word[1] - aux_info['start_time']) / frame_duration))) |
| 138 | if idx < n_frames: |
| 139 | extended_word_indices[idx] = lang.get_word_index(word[0]) |
| 140 | # extended_word_indices[prev_idx:idx+1] = lang.get_word_index(word[0]) |
| 141 | prev_idx = idx |
| 142 | return torch.Tensor(extended_word_indices).long() |
| 143 | |
| 144 | def words_to_tensor(lang, words, end_time=None): |
| 145 | indexes = [lang.SOS_token] |
| 146 | for word in words: |
| 147 | if end_time is not None and word[1] > end_time: |
| 148 | break |
| 149 | indexes.append(lang.get_word_index(word[0])) |
| 150 | indexes.append(lang.EOS_token) |
| 151 | return torch.Tensor(indexes).long() |
| 152 | |
| 153 | duration = aux_info['end_time'] - aux_info['start_time'] |
| 154 | do_clipping = True |
| 155 | |
| 156 | if do_clipping: |
| 157 | sample_end_time = aux_info['start_time'] + duration * self.n_poses / vec_seq.shape[0] |
| 158 | audio = utils.data_utils.make_audio_fixed_length(audio, self.expected_audio_length) |
| 159 | spectrogram = spectrogram[:, 0:self.expected_spectrogram_length] |
| 160 | vec_seq = vec_seq[0:self.n_poses] |
| 161 | pose_seq = pose_seq[0:self.n_poses] |
| 162 | else: |
| 163 | sample_end_time = None |
| 164 | |
| 165 | # to tensors |