我正在使用Tensorflow构建标准图像分类模型.为此,我有输入图像,每个图像都分配有一个标签({0,1}中的数字).因此,可以使用以下格式将数据存储在列表中:
/path/to/image_0 label_0
/path/to/image_1 label_1
/path/to/image_2 label_2
...
Run Code Online (Sandbox Code Playgroud)
我想使用TensorFlow的排队系统来读取我的数据并将其提供给我的模型.忽略标签,可以通过使用string_input_producer
和轻松实现这一点wholeFileReader
.这里的代码:
def read_my_file_format(filename_queue):
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
example = tf.image.decode_png(value)
return example
#removing label, obtaining list containing /path/to/image_x
image_list = [line[:-2] for line in image_label_list]
input_queue = tf.train.string_input_producer(image_list)
input_images = read_my_file_format(input_queue)
Run Code Online (Sandbox Code Playgroud)
但是,标签在该过程中丢失,因为图像数据被有意地作为输入管道的一部分混洗.通过输入队列将标签与图像数据一起推送的最简单方法是什么?
我正在尝试运行Tensorflow的CIFAR-10示例.但是在执行时python cifar10.py
我收到下面附带的错误.
我使用pip安装了Tensorflow软件包的0.6.0版本.该框架在其他模型上运行良好,包括MNIST教程和一些自行开发的网络.有人对这个问题的根源有所了解吗?你认为我应该在github上打开一个问题吗?
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcublas.so.7.0 locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcudnn.so.6.5 locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcufft.so.7.0 locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcurand.so.7.0 locally
Traceback (most recent call last):
File "cifar10.py", line 54, in <module>
"""Number of images to process in a batch.""")
File "/disk/no_backup/teichman/tensorflow/gpu_mode/local/lib/python2.7/site-packages/tensorflow/python/platform/default/_flags.py", line 86, in DEFINE_integer
_define_helper(flag_name, default_value, docstring, int)
File "/disk/no_backup/teichman/tensorflow/gpu_mode/local/lib/python2.7/site-packages/tensorflow/python/platform/default/_flags.py", line 60, in _define_helper …
Run Code Online (Sandbox Code Playgroud) 在Tensorflow读数数据教程中,给出了一个示例输入管道.在该管道中,数据被洗牌两次,无论是在内部string_input_producer
还是在内部shuffle batch generator
.这是代码:
def input_pipeline(filenames, batch_size, num_epochs=None):
# Fist shuffle in the input pipeline
filename_queue = tf.train.string_input_producer(
filenames, num_epochs=num_epochs, shuffle=True)
example, label = read_my_file_format(filename_queue)
min_after_dequeue = 10000
capacity = min_after_dequeue + 3 * batch_size
# Second shuffle as part of the batching.
# Requiring min_after_dequeue preloaded images
example_batch, label_batch = tf.train.shuffle_batch(
[example, label], batch_size=batch_size, capacity=capacity,
min_after_dequeue=min_after_dequeue)
return example_batch, label_batch
Run Code Online (Sandbox Code Playgroud)
第二次洗牌是否有用?混洗批量生成器的缺点在于,min_after_dequeue
示例总是被预先存储在存储器中以允许有用的混洗.我的图像数据确实很大,内存消耗很大.这就是我考虑使用的原因normal batch generator
.将数据混洗两次有什么好处吗?
编辑:附加问题,为什么string_input_producer
初始化只有默认容量32?将batch_size的倍数作为容量不是有利的吗?
我知道在构建一个无序的地图时M
,我会准确插入k
元素.我应该如何选择铲斗的数量M
?
我正在考虑n = 10*k
在尺寸和碰撞机会之间进行合理的权衡.