Skip to content

Commit

Permalink
Merge pull request #123 from cbrom/master
Browse files Browse the repository at this point in the history
Refer to issue #77 
fix #77
  • Loading branch information
r9y9 committed Oct 16, 2018
2 parents af84725 + ea6f98a commit 6be7c72
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 @@ -90,9 +90,9 @@ def _pad(seq, max_len, constant_values=0):
mode='constant', constant_values=constant_values)


def _pad_2d(x, max_len, b_pad=0):
def _pad_2d(x, max_len, b_pad=0, constant_values=0):
x = np.pad(x, [(b_pad, max_len - len(x) - b_pad), (0, 0)],
mode="constant", constant_values=0)
mode="constant", constant_values=constant_values)
return x


Expand Down Expand Up @@ -417,17 +417,19 @@ def collate_fn(batch):
# (B, T, C)
# pad for time-axis
if is_mulaw_quantize(hparams.input_type):
padding_value = P.mulaw_quantize(0, mu=hparams.quantize_channels)
x_batch = np.array([_pad_2d(np_utils.to_categorical(
x[0], num_classes=hparams.quantize_channels),
max_input_len) for x in batch], dtype=np.float32)
max_input_len, padding_value) for x in batch], dtype=np.float32)
else:
x_batch = np.array([_pad_2d(x[0].reshape(-1, 1), max_input_len)
for x in batch], dtype=np.float32)
assert len(x_batch.shape) == 3

# (B, T)
if is_mulaw_quantize(hparams.input_type):
y_batch = np.array([_pad(x[0], max_input_len) for x in batch], dtype=np.int)
padding_value = P.mulaw_quantize(0, mu=hparams.quantize_channels)
y_batch = np.array([_pad(x[0], max_input_len, constant_values=padding_value) for x in batch], dtype=np.int)
else:
y_batch = np.array([_pad(x[0], max_input_len) for x in batch], dtype=np.float32)
assert len(y_batch.shape) == 2
Expand Down

0 comments on commit 6be7c72

Please sign in to comment.