python - 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
任何人都可以为这个问题提供任何解决方案吗?
提前致谢。
解决方案
你可以试试下面的方法。
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
,请参阅此文档以获取信息。
推荐阅读
- c# - C# 是否存在无效(脏)JSON 解析器?
- wcf - WCF 如何更改 X.509 证书私钥的加密提供程序
- android - 如何使用渲染操作在 React-native-Gifted-chat 中发送图像/视频和语音消息?
- python - 如何让我的 python discord bot 每 0.10 秒说一次相同的消息
- php - 如何在 Woocommerce 中添加以下短代码添加到购物车
- python - 你能在 Python 中编辑俄罗斯方块,这样你就不必反复按箭头键来移动对象了吗?
- attributes - 如何在 Items.xml Hybris 中为项目的 Map 属性设置默认值?
- java - Java Android NullPointerException。不知道有什么问题吗?
- javascript - React npm run build 每次都失败
- vbscript - 如何将文本文件的内容复制到剪贴板?