【问题标题】:Solving SVHN using Tensorflow Error: "Resource exhausted: OOM when allocating tensor.."使用 Tensorflow 解决 SVHN 错误:“资源耗尽:分配张量时 OOM ..”
【发布时间】:2016-03-01 22:45:18
【问题描述】:

我试图使用此处提供的卷积神经网络来解决“SVHN”数据集分类问题https://www.tensorflow.org/versions/0.6.0/tutorials/deep_cnn/index.html#convolutional-neural-networks

我以这种方式读取数据并对其进行格式化:

read_input = scipy.io.loadmat('data/train_32x32.mat')
converted_label = tf.cast(read_input['y'], tf.int32)
converted_image = tf.cast(read_input['X'], tf.float32)
reshaped_image = tf.transpose(converted_image, [3, 0, 1, 2])

_generate_image_and_label_batch 函数中,我稍微修改了代码,因为train_32X32.mattext_32X32.mat 的输入图像已经是4D 格式了。

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

我最终遇到了这些错误:

Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4
W tensorflow/core/kernels/cast_op.cc:66] Resource exhausted: OOM when allocating tensor with shapedim { size: 32 } dim { size: 32 } dim { size: 3 } dim { size: 73257 }
W tensorflow/core/common_runtime/executor.cc:1027] 0x7f1c180015a0 Compute status: Resource exhausted: OOM when allocating tensor with shapedim { size: 32 } dim { size: 32 } dim { size: 3 } dim { size: 73257 }
     [[Node: Cast_1 = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, _device="/job:localhost/replica:0/task:0/cpu:0"](Cast_1/x)]]
W tensorflow/core/kernels/cast_op.cc:66] Resource exhausted: OOM when allocating tensor with shapedim { size: 32 } dim { size: 32 } dim { size: 3 } dim { size: 73257 }
W tensorflow/core/common_runtime/executor.cc:1027] 0x7f1c280ea810 Compute status: Resource exhausted: OOM when allocating tensor with shapedim { size: 32 } dim { size: 32 } dim { size: 3 } dim { size: 73257 }
     [[Node: Cast_1 = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, _device="/job:localhost/replica:0/task:0/cpu:0"](Cast_1/x)]]
Killed

如果我在任何逻辑上犯了任何错误,请告诉我。

谢谢

莎拉

【问题讨论】:

  • 您有多少可用内存?你这样做的方式可能需要 3GB 的 RAM(你有 1GB 的浮点数,然后 1GB 来自演员,然后又 1GB 来自转置)
  • 我有 3.8 GB 的总内存,但只有 1.5 GB 的可用内存。这可能是原因。我将减小 train_32X32.mat 的大小,然后再试一次。非常感谢@YaroslavBulatov

标签: linux tensorflow deep-learning


【解决方案1】:

请注意,您的数据包含 2*32*3*73257 个条目,即浮点数为 900 MB,双精度数为 1800MB。所以你在read_input['X'] 分配了 1800MB,然后 TF 将其转换为张量以馈入cast,这又是 900MB。 tf.cast 的输出是另一个 900MB 的张量,transpose 的输出是另一个 900MB 的张量。

因此,您可能需要 4.5GB 的 RAM 才能正常工作。

一般来说,这种方法(转换为Constant 节点)只推荐用于“小”问题。您可以将 2GB 的硬限制放入一个常量中,但如果您使用 GPU,即使是更小的值(即 >100MB)也可能会导致问题(例如 here

另一种可扩展的方式是使用 Cifar 示例中的输入管道

【讨论】:

  • 再次感谢您的解释。这将是一个很大的帮助。我也将尝试管道方法,因为我计划使用 GPU 和非常大的问题。
猜你喜欢
  • 2018-03-21
  • 1970-01-01
  • 2016-12-28
  • 2019-08-02
  • 1970-01-01
  • 2018-04-05
  • 1970-01-01
  • 2019-10-11
  • 1970-01-01
相关资源
最近更新 更多