當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.load_spectrograms方法代碼示例

本文整理匯總了Python中utils.load_spectrograms方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.load_spectrograms方法的具體用法?Python utils.load_spectrograms怎麽用?Python utils.load_spectrograms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在utils的用法示例。


在下文中一共展示了utils.load_spectrograms方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: eval

# 需要導入模塊: import utils [as 別名]
# 或者: from utils import load_spectrograms [as 別名]
def eval(): 
    # Load graph
    g = Graph(mode="eval"); print("Evaluation Graph loaded")

    # Load data
    fpaths, text_lengths, texts = load_data(mode="eval")

    # Parse
    text = np.fromstring(texts[0], np.int32) # (None,)
    fname, mel, mag = load_spectrograms(fpaths[0])

    x = np.expand_dims(text, 0) # (1, None)
    y = np.expand_dims(mel, 0) # (1, None, n_mels*r)
    z = np.expand_dims(mag, 0) # (1, None, n_mfccs)

    saver = tf.train.Saver()
    with tf.Session() as sess:
        saver.restore(sess, tf.train.latest_checkpoint(hp.logdir)); print("Restored!")

        writer = tf.summary.FileWriter(hp.logdir, sess.graph)

        # Feed Forward
        ## mel
        y_hat = np.zeros((1, y.shape[1], y.shape[2]), np.float32)  # hp.n_mels*hp.r
        for j in range(y.shape[1]):
            _y_hat = sess.run(g.y_hat, {g.x: x, g.y: y_hat})
            y_hat[:, j, :] = _y_hat[:, j, :]

        ## mag
        merged, gs = sess.run([g.merged, g.global_step], {g.x:x, g.y:y, g.y_hat: y_hat, g.z: z})
        writer.add_summary(merged, global_step=gs)
        writer.close() 
開發者ID:Kyubyong,項目名稱:tacotron,代碼行數:34,代碼來源:eval.py

示例2: proc

# 需要導入模塊: import utils [as 別名]
# 或者: from utils import load_spectrograms [as 別名]
def proc(fpath, hp):
    
    if not os.path.isfile(fpath):
        return
        
    fname, mel, mag, full_mel = load_spectrograms(hp, fpath)
    np.save("{}/{}".format(hp.coarse_audio_dir, fname.replace("wav", "npy")), mel)
    np.save("{}/{}".format(hp.full_audio_dir, fname.replace("wav", "npy")), mag)
    np.save("{}/{}".format(hp.full_mel_dir, fname.replace("wav", "npy")), full_mel) 
開發者ID:CSTR-Edinburgh,項目名稱:ophelia,代碼行數:11,代碼來源:prepare_acoustic_features.py

示例3: evaluate

# 需要導入模塊: import utils [as 別名]
# 或者: from utils import load_spectrograms [as 別名]
def evaluate():
    # Load graph
    g = Graph(mode="evaluate"); print("Graph loaded")

    # Load data
    fpaths, _, texts = load_data(mode="evaluate")
    lengths = [len(t) for t in texts]
    maxlen = sorted(lengths, reverse=True)[0]
    new_texts = np.zeros((len(texts), maxlen), np.int32)
    for i, text in enumerate(texts):
        new_texts[i, :len(text)] = [idx for idx in text]
    #new_texts = np.split(new_texts, 2)
    new_texts = new_texts[:evaluate_wav_num]
    half_size = int(len(fpaths)/2)
    print(half_size)
    #new_fpaths = [fpaths[:half_size], fpaths[half_size:]]
    fpaths = fpaths[:evaluate_wav_num]
    saver = tf.train.Saver()
    with tf.Session() as sess:
        saver.restore(sess, tf.train.latest_checkpoint(hp.logdir)); print("Evaluate Model Restored!")
        """
        err = 0.0

        for i, t_split in enumerate(new_texts):
            y_hat = np.zeros((t_split.shape[0], 200, hp.n_mels*hp.r), np.float32)  # hp.n_mels*hp.r
            for j in tqdm.tqdm(range(200)):
                _y_hat = sess.run(g.y_hat, {g.x: t_split, g.y: y_hat})
                y_hat[:, j, :] = _y_hat[:, j, :]

            mags = sess.run(g.z_hat, {g.y_hat: y_hat})
            for k, mag in enumerate(mags):
                fname, mel_ans, mag_ans = load_spectrograms(new_fpaths[i][k])
                print("File {} is being evaluated ...".format(fname))
                audio = spectrogram2wav(mag)
                audio_ans = spectrogram2wav(mag_ans)
                err += calculate_mse(audio, audio_ans)

        err = err/float(len(fpaths))
        print(err)

        """
        # Feed Forward
        ## mel
        y_hat = np.zeros((new_texts.shape[0], 200, hp.n_mels*hp.r), np.float32)  # hp.n_mels*hp.r
        for j in tqdm.tqdm(range(200)):
            _y_hat = sess.run(g.y_hat, {g.x: new_texts, g.y: y_hat})
            y_hat[:, j, :] = _y_hat[:, j, :]
        ## mag
        mags = sess.run(g.z_hat, {g.y_hat: y_hat})
        err = 0.0
        for i, mag in enumerate(mags):
            fname, mel_ans, mag_ans = load_spectrograms(fpaths[i])
            print("File {} is being evaluated ...".format(fname))
            #audio = spectrogram2wav(mag)
            #audio_ans = spectrogram2wav(mag_ans)
            #err += calculate_mse(audio, audio_ans)
            err += calculate_mse(mag, mag_ans)
        err = err/float(len(fpaths))
        print(err)
        opf.write(hp.logdir  + " spectrogram mse: " + str(err) + "\n") 
開發者ID:HappyBall,項目名稱:tacotron,代碼行數:62,代碼來源:evaluate.py


注:本文中的utils.load_spectrograms方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。