首页 > 解决方案 > IndexError:尝试使用 TF-GPU 时列出超出范围的索引

问题描述

尝试在 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

喀拉斯:2.3.1

CUDA:10.1,

库登:7.6.5

任何人都可以为这个问题提供任何解决方案吗?

提前致谢。

标签: pythontensorflowindex-error

解决方案


你可以试试下面的方法。

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 升级到最新版本并尝试。因为,在以前的版本中报告了一些错误。

如果您正在使用XLA GPU,请参阅文档以获取信息。


推荐阅读