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

标签 machine-learning tensorflow deep-learning tensorboard

最近开始学习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/

相关文章:

python - Tensorflow 中的预定采样

opencv - 如何保存 Tensorflow 模型(不包含任何变量)以将其移植到 OpenCV 中

python - 在 TensorFlow 中使用 CNN 进行信号处理。类型错误 : DataType float32 for attr 'Tlabels' not in list of allowed values: int32, int64

image-processing - 跟踪与人脸检测相关的人体 Blob

java - R中的自定义距离度量,用于聚集聚类

artificial-intelligence - 社交网络 FOAF 数据集上的关联规则挖掘

python - 当我只在行中获得聚类时,如何微调 K 均值聚类?

machine-learning - TensorFlow 二元分类任务精度较差,但 SciKit-Learn GBM 效果良好

machine-learning - 是否可以使用具有编译设置 USE_CUDNN := 1? 的 CPP 代码

python - Docker 从守护进程获取事件时出错 : EOF