【问题标题】:Tensorflow code breakingTensorFlow 代码破解
【发布时间】:2016-06-07 06:10:35
【问题描述】:

我正在修改 cifar 多 GPU tensorflow 代码以读取 Imagenet 数据集。

我所做的修改是:

Cifar10.py:

1) 改变了 tf.app.flags.DEFINE_string('data_dir',...)

2) 删除了data_dir = os.path.join(FLAGS.data_dir, 'cifar-10-batches-bin')后面的部分

3) 从 maybe_download_and_extract() 中删除了下载部分

cifar10_input.py:

1) 图像大小 = 227

2) result.height = 256 和 result.width = 256

3) 改变

filenames = [os.path.join(data_dir, 'data_batch_%d.bin' % i) for i in xrange(1, 6)]

filenames = [os.path.join(data_dir, i) for i in os.listdir(data_dir)]

但这会引发一个丑陋的错误: tensorflow.python.framework.errors.OutOfRangeError: RandomShuffleQueue '_1_tower_0/shuffle_batch/random_shuffle_queue' 已关闭且元素不足(请求 128,当前大小为 0)

[[节点:tower_0/shuffle_batch = QueueDequeueMany[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](tower_0/ shuffle_batch/random_shuffle_queue, tower_0/shuffle_batch/n/_775)]]

[[节点:tower_1/shuffle_batch/n/_664 = _HostSendT=DT_INT32,client_terminated=false,recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job: localhost/replica:0/task:0/gpu:1", send_device_incarnation=1, tensor_name="edge_170_tower_1/shuffle_batch/n", _device="/job:localhost/replica:0/task:0/gpu:1"] ] 由 op u'tower_0/shuffle_batch' 引起,定义在:

文件“lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10_multi-gpu_train.py”,第 224 行,

tf.app.run()

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/default/_app.py”,第 30 行,运行中

sys.exit(main(sys.argv))

文件“lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10_multi-gpu_train.py”,第 222 行,在 main

train()

文件“lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10_multi-gpu_train.py”,第 150 行,在训练中

loss = tower_loss(scope)

文件“lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10_multi-gpu_train.py”,第 65 行,在 tower_loss 中

images, labels = cifar10.distorted_inputs()

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10.py”,第 119 行,在 distorted_inputs 中

batch_size=FLAGS.batch_size)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10_input.py”,第 153 行,在 distorted_inputs 中

min_queue_examples, batch_size)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/models/image/cifar10/cifar10_input.py”,第 104 行,在 _generate_image_and_label_batch 中

min_after_dequeue=min_queue_examples)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/input.py”,第 496 行,在 shuffle_batch return queue.dequeue_many(batch_size, name=name)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/data_flow_ops.py”,第 287 行,在 dequeue_many 中

self._queue_ref, n, self._dtypes, name=name)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py”,第 319 行,在 _queue_dequeue_many 中

timeout_ms=timeout_ms, name=name)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/op_def_library.py”,第 664 行,在 apply_op op_def=op_def)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py”,第 1834 行,在 create_op 中

original_op=self._default_original_op, op_def=op_def)

文件“/home/saoni.m/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py”,第 1043 行,在 init

self._traceback = _extract_stack()

当我回溯到调用 shuffle_batch() 的那一行时:

images, label_batch = tf.train.shuffle_batch(
      [image, label],
      batch_size=batch_size,
      num_threads=num_preprocess_threads,
      capacity=min_queue_examples + 3 * batch_size,
      min_after_dequeue=min_queue_examples)

传递给它的值是: 批量大小 128,num_threads 16,容量 20384,min_after_deque 20000

【问题讨论】:

    标签: python python-2.7 tensorflow


    【解决方案1】:

    我遇到了类似的问题,我尝试更改 python 列表,比如 [os.path.join(data_dir, i) for i in os.listdir(data_dir)] 到 files=tf.train.match_filenames_once("/path/to/data.tfrecords-*"), 文件队列 = tf.train.input_string_input_producer(文件)。 它对我有用,你可以试试。

    【讨论】:

      【解决方案2】:

      看起来您没有从读者那里获得任何数据输入。

      你变了:

      [os.path.join(data_dir, i) for i in os.listdir(data_dir)]
      

      data_dir/ 中到底有什么? (您确定正在使用正确的目录名等吗?)

      我的建议是在您开始执行时发送给print filenames——这在 tensorflow 中没有做任何事情,只是在 python 中做任何事情,因此您将立即获得易于阅读的答案。如果它看起来有效,我们将从那里开始工作。 :)

      第二个问题是您的更改不足以开始在 imagenet 上工作。 read_cifar10 函数专门用于 cifar 输入格式,但 ImageNet 数据(大部分)是 JPEG,有一个单独的文件指定标签。您可以使用tf.image.decode_jpeg 解码 jpeg,但您还需要合并同义词集标签。

      【讨论】:

      • 感谢您的回答。关于第一个问题,我打印了len(filenames),它有1300个文件(imagenet的一个文件夹是我正在测试的。我在第二个,但看起来很复杂。你能详细说明一下吗?更多?
      • 那么您已经获取了例如 nXXXXXXX 的内容,那就是 data_dir?内容都是nXXXXXXX-YYYY-.JPG吧?
      • 对,这就是评论 2 的内容: cifar10 示例中的管道要求输入文件为 cifar10 二进制格式。根据TensorFlow Cifar10 docs,cifar 文件是固定长度的二进制记录文件,在每个固定长度记录中都有元数据和图像数据。ImageNet 数据的呈现方式完全不同——单独的 JPEG 文件和单独的元数据。
      猜你喜欢
      • 2018-06-15
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多