Skip to content

Commit

Permalink
Sample segment
Browse files Browse the repository at this point in the history
  • Loading branch information
r9y9 committed Jan 1, 2018
1 parent 502c31a commit 58ad07f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,19 @@ def collate_fn(batch):
for idx in range(len(batch)):
x, c, g = batch[idx]
x, c = audio.adjast_time_resolution(x, c)
if max_time_steps is not None:
x, c = x[:max_time_steps], c[:max_time_steps, :]
if max_time_steps is not None and len(x) > max_time_steps:
s = np.random.randint(0, len(x) - max_time_steps)
x, c = x[s:s + max_time_steps], c[s:s + max_time_steps, :]
new_batch.append((x, c, g))
batch = new_batch
else:
new_batch = []
for idx in range(len(batch)):
x, c, g = batch[idx]
x = audio.trim(x)
if max_time_steps is not None:
x = x[:max_time_steps]
if max_time_steps is not None and len(x) > max_time_steps:
s = np.random.randint(0, len(x) - max_time_steps)
x, c = x[s:s + max_time_steps], c[s:s + max_time_steps, :]
new_batch.append((x, c, g))
batch = new_batch

Expand Down

0 comments on commit 58ad07f

Please sign in to comment.