【问题标题】:save ouput file as matrix in tensorflow将输出文件保存为张量流中的矩阵
【发布时间】:2017-08-10 20:21:58
【问题描述】:

我通过 tensorflow 制作去噪自动编码器。

我使用 799x161 矩阵作为输入数据。

这是我的训练代码

training_epochs = 100
batch_size      = 799
display_step    = 10

# Training
if do_train:
print ("Training Start")
for epoch in range(training_epochs):
    avg_cost = 0.
    num_batch = int(X_train.shape[0]/batch_size)
    for i in range(num_batch): 
        batch = X_train[i*batch_size : i*batch_size+batch_size]
        batch_noise = batch + 0.3*np.random.randn(batch.shape[0], 161) #addnoise
        feed1 = {x: batch_noise, y_: batch, keep_prob: 0.5}
        sess.run(optimizer, feed_dict = feed1)
        feed2 = {x: batch_noise, y_: batch, keep_prob: 1}
        avg_cost += sess.run(cost, feed_dict=feed2)/num_batch

    if epoch % display_step == 0:
        print ("Epoch: %03d/%03d cost: %.9f" % (epoch, training_epochs, avg_cost))

和测试代码

# TEST
testspeech = scipy.io.loadmat('data/test_cep.mat')
Y_test = testspeech['ans']
Y_test = np.array(Y_test)  # 799x161 cepstrum matrix
noisyspeech = scipy.io.loadmat('data/reverb_cep.mat')
Y_noisy = noisyspeech['ans']
Y_noisy = np.array(Y_noisy)  # 799x161 cepstrum addnoise matrix

batch = Y_test
batch_noise = Y_noisy

avg_cost += sess.run(cost, feed_dict=feed2)/num_batch

print ("cost: %.9f" % (avg_cost))

测试后,我想将输出文件保存为 799x161 矩阵,以便与干净的数据进行比较并在 matlab 中处理。

我的问题:但我不知道如何将其保存为矩阵。我的意思是我想在我的电脑中将矩阵保存为可读文件。我不确定 matlab 是否可以读取它。

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    不确定我是否理解正确
    您想保存numpy array 以便matlab 阅读吗?

    你正在使用scipy,我认为它可以做到
    假设你要保存Y_testY_noisy

    scipy.io.savemat('test.mat', dict('data'=Y_test, 'res'=Y_noisy))
    

    然后使用matlab加载test.mat,same question

    有意思,你用scipy.io.loadmat却不知道scipy.io.savemat

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 2018-05-24
      • 2016-10-26
      • 2020-11-12
      • 1970-01-01
      • 2018-11-19
      • 2018-12-09
      • 2018-07-05
      • 1970-01-01
      相关资源
      最近更新 更多