2016-05-16 54 views
0

我最近開始學習tensorflow。我想輸入我的自定義Python代碼作爲訓練數據。我產生了隨機指數信號,並希望網絡從中學習。這是我用於生成信號的代碼 -如何在張量流中使用自定義數據集?

import matplotlib.pyplot as plt 
import random 
import numpy as np 

lorange= 1 
hirange= 10 
amplitude= random.uniform(-10,10) 
t= 10 
random.seed() 
tau=random.uniform(lorange,hirange) 
x=np.arange(t) 

plt.xlabel('t=time") 
plt.ylabel('x(t)') 
plt.plot(x, amplitude*np.exp(-x/tau)) 
plt.show() 

如何將此圖用作張量流中的輸入向量?

回答

2

你必須使用tf.placeholder功能(see the doc):

# Your input data 
x = np.arange(t) 
y = amplitude*np.exp(-x/tau) 

# Create a corresponding tensorflow node 
x_node = tf.placeholder(tf.float32, shape=(t,)) 
y_node = tf.placeholder(tf.float32, shape=(t,)) 

然後可以使用x_node和y_node在tensorflow代碼(例如使用x_node作爲神經網絡的輸入,並試圖預測y_node) 。
使用sess.run()然後當你有一個feed_dict參數養活輸入數據xy

with tf.Session() as sess: 
    sess.run([...], feed_dict={x_node: x, y_node: y}) 
+0

謝謝。我現在正在嘗試這個@olivier – zerogravty

相關問題