Python Tensorflow:从变量输入占位符
我正在使用输入队列和Python Tensorflow:从变量输入占位符,python,machine-learning,Python,Machine Learning,我正在使用输入队列和 tf.train.batch用数据准备巨大张量的函数。 我有另一个队列,其中包含测试数据,我希望每50步将其输入到图表中 问题: 给定输入(张量)的形式,我是否必须为测试数据计算定义单独的测试图,或者我可以以某种方式重用训练图 # Prepare data batch = tf.train.batch([train_image, train_label], batch_size=200) batchT = tf.train.batch([test_image, test_l
tf.train.batch
用数据准备巨大张量的函数。
我有另一个队列,其中包含测试数据,我希望每50步将其输入到图表中
问题:
给定输入(张量)的形式,我是否必须为测试数据计算定义单独的测试图,或者我可以以某种方式重用训练图
# Prepare data
batch = tf.train.batch([train_image, train_label], batch_size=200)
batchT = tf.train.batch([test_image, test_label], batch_size=200)
x = tf.reshape(batch[0], [-1, IMG_SIZE, IMG_SIZE, 3])
y_ = batch[1]
xT = tf.reshape(batchT[0], [-1, IMG_SIZE, IMG_SIZE, 3])
y_T = batchT[1]
# Graph definition
train_step = ... # train_step = g(x)
# Session
sess = tf.Session()
sess.run(tf.initialize_all_variables())
for i in range(1000):
if i%50 == 0:
# here i would like reuse train graph but with tensor x replaced by x_t
# train_accuracy = ?
# print("step %d, training accuracy %g"%(i, train_accuracy))
train_step.run(session=sess)
我会使用占位符,但我不能用tf.Tensors
来输入tf.placeholder
,这就是我从队列中得到的东西。
应该怎么做
我真的才刚刚开始。看看这是如何在中完成的:您需要使用占位符和数据的非张量形式的初始值设定项(如文件名或CSV),然后在图形中,使用slice\u input\u producer->deocde\u jpeg(或其他…)->tf.train.batch()创建批并将这些批提供给计算图 因此,您的图形类似于:
- 用大文件名列表/CSV/range初始化占位符
tf.slice\u input\u producer
或tf.image.decode_jpeg
加载实际数据tf.py_func
-为培训创建小批量tf.train.batch
- 输入到您的模型