我试图利用队列从Tensorflow中的文件加载数据.
我想在每个时代结束时使用验证数据运行图表,以更好地了解培训的进展情况.
这就是我遇到问题的地方.我似乎无法弄清楚如何在使用队列时在训练数据和验证数据之间进行切换.
我已经将我的代码剥离到一个简单的玩具示例,以便更容易获得帮助.我没有包含加载图像文件的所有代码,执行推理和训练,而是将文件名加载到队列中.
import tensorflow as tf
# DATA
train_items = ["train_file_{}".format(i) for i in range(6)]
valid_items = ["valid_file_{}".format(i) for i in range(3)]
# SETTINGS
batch_size = 3
batches_per_epoch = 2
epochs = 2
# CREATE GRAPH
graph = tf.Graph()
with graph.as_default():
file_list = tf.placeholder(dtype=tf.string, shape=None)
# Create a queue consisting of the strings in `file_list`
q = tf.train.string_input_producer(train_items, shuffle=False, num_epochs=None)
# Create batch of items.
x = q.dequeue_many(batch_size)
# Inference, train op, and accuracy calculation after this point …Run Code Online (Sandbox Code Playgroud)