如何检查是否存在GPU而不在张量流中生成警告

问题描述 投票:0回答:1
  • 我正在编写代码以训练模型,我不确定此代码以后是否可以在具有或不具有GPU的计算机上运行,​​因此我正在使用该代码。

  • 我的问题是:代码正在生成此警告:

    • is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use tf.config.list_physical_devices('GPU') instead.

所以我的问题是:

如何以简单明了的方式检查是否有GPU,而不会产生警告。

import os

# Check if there is valid GPU to be used
if(tf.test.is_gpu_available(cuda_only=True)):
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'
python python-3.x tensorflow gpu
1个回答
1
投票

尝试使用tf.config.experimental中的list_physical_devices,您的警告提示您使用。该代码对我有用。

list_physical_devices
© www.soinside.com 2019 - 2024. All rights reserved.