【问题标题】:How to use custom dataset in tensorflow?如何在张量流中使用自定义数据集?
【发布时间】:2016-05-16 05:52:34
【问题描述】:

我最近开始学习 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()

如何在 tensorflow 中将此图用作输入向量?

【问题讨论】:

    标签: machine-learning tensorflow deep-learning tensorboard


    【解决方案1】:

    你必须使用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,))
    

    然后您可以在 tensorflow 代码中使用 x_node 和 y_node(例如,使用 x_node 作为神经网络的输入并尝试预测 y_node)。
    然后在使用sess.run() 时,您必须使用feed_dict 参数提供输入数据xy

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多