Tensorflow:从variab输入占位符

2024-06-25 22:55:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用输入队列和 tf.train.batch用数据准备巨大张量的函数。 我有另一个队列,其中包含测试数据,我想每隔50步将其发送给graph。在

问题

考虑到输入(张量)的形式,我是否必须为测试数据计算定义单独的测试图或者我可以以某种方式重用训练图?在

# 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,这就是我从队列中得到的东西。 应该怎么做?在

我才刚刚开始。在


Tags: imageimgsize队列tfstepbatchtrain
1条回答
网友
1楼 · 发布于 2024-06-25 22:55:05

看看在MNIST example中是如何做到的:您需要使用一个占位符和数据的非张量形式的初始值设定项(如文件名或CSV),然后在图形内部使用slice_input_producer->;deocdu jpeg(或其他…)->;训练批处理()创建批处理并将其输入计算图。在

所以你的图表看起来像:

  • 用大文件名列表/CSV/range初始化的占位符
  • tf.slice_input_producer
  • tf.image.decode_jpegtf.py_func-加载实际数据
  • tf.train.batch-创建小批量培训
  • 提供给你的模型

相关问题 更多 >