【问题标题】:IndexError: list index out of range while trying to use TF-GPUIndexError:尝试使用 TF-GPU 时列出超出范围的索引
【发布时间】:2021-10-18 02:07:25
【问题描述】:

我在 Python 中尝试将 TF-GPU 用于我的人脸检测代码时遇到以下错误。

错误: tf.config.experimental.set_memory_growth(gpus[0], True)

IndexError: 列表索引超出范围

我的设置:

Python:Ananconda 3 与 Python 3.7

使用 pip install tensorflow-gpu==2.1.0 安装的 Tensorflow-GPU 2.1

Keras:2.3.1

CUDA:10.1,

Cudnn:7.6.5

谁能提供任何解决这个问题的方法?

提前致谢。

【问题讨论】:

  • 谢谢。我用 pip3 install --upgrade tensorflow-gpu==2.1.0 试过这个,因为我的代码需要 tf-gpu-2.1。但这并没有解决我的问题。如果我使用“XLA_GPU”,则会显示另一个错误,即无法设置非 GPU 的内存增长。

标签: python tensorflow index-error


【解决方案1】:

你可以试试下面的方法。

import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
  for gpu in gpus:
    tf.config.experimental.set_memory_growth(gpu, True)
else:
  print("No GPU device found")

如果没有检测到 gpu 设备,则将您的 tensorflow、CUDA 和 CuDNN 升级到最新版本并尝试。由于之前的版本中报告了一些bugs

如果您使用的是XLA GPU,请参阅this 文档以获取信息。

【讨论】:

  • 感谢您的宝贵回复
猜你喜欢
  • 2017-04-20
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-31
  • 2015-06-26
相关资源
最近更新 更多