【问题标题】:TensorFlow: Dst tensor is not initializedTensorFlow:Dst张量未初始化
【发布时间】:2016-09-15 18:41:20
【问题描述】:

当我运行 print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})) 时,MNIST For ML Beginners 教程给了我一个错误。其他一切运行良好。

错误和跟踪:

InternalErrorTraceback (most recent call last)
<ipython-input-16-219711f7d235> in <module>()
----> 1 print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    338     try:
    339       result = self._run(None, fetches, feed_dict, options_ptr,
--> 340                          run_metadata_ptr)
    341       if run_metadata:
    342         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
    562     try:
    563       results = self._do_run(handle, target_list, unique_fetches,
--> 564                              feed_dict_string, options, run_metadata)
    565     finally:
    566       # The movers are no longer used. Delete them.

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
    635     if handle is None:
    636       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
--> 637                            target_list, options, run_metadata)
    638     else:
    639       return self._do_call(_prun_fn, self._session, handle, feed_dict,

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)
    657       # pylint: disable=protected-access
    658       raise errors._make_specific_exception(node_def, op, error_message,
--> 659                                             e.code)
    660       # pylint: enable=protected-access
    661 

InternalError: Dst tensor is not initialized.
     [[Node: _recv_Placeholder_3_0/_1007 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_312__recv_Placeholder_3_0", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
     [[Node: Mean_1/_1011 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_319_Mean_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

我刚刚切换到更新版本的 CUDA,所以也许这与此有关?似乎这个错误是关于将张量复制到 GPU。

堆栈:EC2 g2.8xlarge 机器,Ubuntu 14.04

更新:

print(sess.run(accuracy, feed_dict={x: batch_xs, y_: batch_ys})) 运行良好。这让我怀疑问题是我试图将一个巨大的张量传输到 GPU 并且它无法接受。像 minibatch 这样的小张量就可以了。

更新 2:

我已经弄清楚张量有多大才会导致这个问题:

batch_size = 7509 #Works.
print(sess.run(accuracy, feed_dict={x: mnist.test.images[0:batch_size], y_: mnist.test.labels[0:batch_size]}))

batch_size = 7510 #Doesn't work. Gets the Dst error.
print(sess.run(accuracy, feed_dict={x: mnist.test.images[0:batch_size], y_: mnist.test.labels[0:batch_size]}))

【问题讨论】:

  • 我也有同样的问题,虽然型号不同。但是,只有当我尝试使用 td.device() 自己选择 gpus 时才会发生这种情况。您是否使用多个 GPU?

标签: tensorflow


【解决方案1】:

请记住,ec2 g2.8xlarge 只有 4 GB 的 gpu 内存。
https://aws.amazon.com/ec2/instance-types/

除了批量大小为 1 运行模型之外,我没有一个很好的方法来找出模型占用了多少空间,然后您可以减去一张图像占用的空间。

您可以从那里确定最大批量大小。这应该可行,但我认为 tensorflow 动态分配 gpu 内存,类似于 torch 和 caffe 不同,它会从一开始就阻止它所需的最大 gpu 空间。因此,您可能希望对最大批量大小保持保守。

【讨论】:

    【解决方案2】:

    为简洁起见,当没有足够的内存来处理批量大小时会生成此错误消息。

    扩展 Steven 的链接(我还不能发布 cmets),这里有一些技巧可以在 Tensorflow 中监控/控制内存使用情况:

    • 要监控运行期间的内存使用情况,请考虑记录运行元数据。然后,您可以在 Tensorboard 的图表中查看每个节点的内存使用情况。有关更多信息和示例,请参阅Tensorboard information page
    • 默认情况下,Tensorflow 将尝试分配尽可能多的 GPU 内存。您可以使用 GPUConfig 选项更改此设置,以便 Tensorflow 只会根据需要分配尽可能多的内存。请参阅documentation。您还可以在其中找到一个选项,该选项允许您仅分配一部分 GPU 内存(不过我发现这有时会被破坏。)。

    【讨论】:

    【解决方案3】:

    我认为这个链接可以帮助https://github.com/aymericdamien/TensorFlow-Examples/issues/38#issuecomment-223793214。 在我的例子中,GPU 正忙着(93% 忙)在 screen 中训练另一个模型。我需要终止该进程,然后很高兴看到这些东西正常工作。

    【讨论】:

      猜你喜欢
      • 2019-07-30
      • 2017-12-10
      • 1970-01-01
      • 2016-02-16
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多