gpt4 book ai didi

machine-learning - 如何在tensorflow中使用自定义数据集?

转载 作者:行者123 更新时间:2023-11-30 09:36:57 24 4
gpt4 key购买 nike

最近开始学习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 中的输入向量?

最佳答案

您必须使用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})

关于machine-learning - 如何在tensorflow中使用自定义数据集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37247483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com