MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / collater

Method collater

tasks/tts/fs2_utils.py:105–152  ·  view source on GitHub ↗
(self, samples)

Source from the content-addressed store, hash-verified

103 return sample
104
105 def collater(self, samples):
106 if len(samples) == 0:
107 return {}
108 id = torch.LongTensor([s['id'] for s in samples])
109 item_names = [s['item_name'] for s in samples]
110 text = [s['text'] for s in samples]
111 txt_tokens = utils.collate_1d([s['txt_token'] for s in samples], 0)
112 f0 = utils.collate_1d([s['f0'] for s in samples], 0.0)
113 pitch = utils.collate_1d([s['pitch'] for s in samples])
114 uv = utils.collate_1d([s['uv'] for s in samples])
115 energy = utils.collate_1d([s['energy'] for s in samples], 0.0)
116 mel2ph = utils.collate_1d([s['mel2ph'] for s in samples], 0.0) \
117 if samples[0]['mel2ph'] is not None else None
118 mels = utils.collate_2d([s['mel'] for s in samples], 0.0)
119 txt_lengths = torch.LongTensor([s['txt_token'].numel() for s in samples])
120 mel_lengths = torch.LongTensor([s['mel'].shape[0] for s in samples])
121
122 batch = {
123 'id': id,
124 'item_name': item_names,
125 'nsamples': len(samples),
126 'text': text,
127 'txt_tokens': txt_tokens,
128 'txt_lengths': txt_lengths,
129 'mels': mels,
130 'mel_lengths': mel_lengths,
131 'mel2ph': mel2ph,
132 'energy': energy,
133 'pitch': pitch,
134 'f0': f0,
135 'uv': uv,
136 }
137
138 if self.hparams['use_spk_embed']:
139 spk_embed = torch.stack([s['spk_embed'] for s in samples])
140 batch['spk_embed'] = spk_embed
141 if self.hparams['use_spk_id']:
142 spk_ids = torch.LongTensor([s['spk_id'] for s in samples])
143 batch['spk_ids'] = spk_ids
144 if self.hparams['pitch_type'] == 'cwt':
145 cwt_spec = utils.collate_2d([s['cwt_spec'] for s in samples])
146 f0_mean = torch.Tensor([s['f0_mean'] for s in samples])
147 f0_std = torch.Tensor([s['f0_std'] for s in samples])
148 batch.update({'cwt_spec': cwt_spec, 'f0_mean': f0_mean, 'f0_std': f0_std})
149 elif self.hparams['pitch_type'] == 'ph':
150 batch['f0'] = utils.collate_1d([s['f0_ph'] for s in samples])
151
152 return batch
153
154 def load_test_inputs(self, test_input_dir, spk_id=0):
155 inp_wav_paths = glob.glob(f'{test_input_dir}/*.wav') + glob.glob(f'{test_input_dir}/*.mp3')

Callers

nothing calls this directly

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected