utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:WaveNet-Enhancement 作者: auspicious3000 项目源码 文件源码
def make_batch_padded(path, num_layers = 14):
    rate, data = wavfile.read(path)
    #only use the 1st channel
    data = data[:, 0]
    data_ = normalize(data)
    bins, bins_center = mu_law_bins(256)
    inputs = np.digitize(data_[0:-1], bins, right=False)
    inputs = bins_center[inputs][None, :, None]
    #predict sample 1 to end using 0 to end-1
    targets = np.digitize(data_[1::], bins, right=False)[None, :]

    base = 2 ** num_layers
    _, width, _ = inputs.shape
    #crop the width to make it multiple of base
    width_cropped = int(np.floor(width * 1.0 / base) * base)
    inputs_padded = np.pad(inputs[:, 0:width_cropped, :], ((0, 0), (base - 1, 0), (0, 0)), 'constant')
    targets_padded = targets[:, 0:width_cropped]

    return (inputs_padded, targets_padded)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号