我正在编写用于训练模型的代码,不确定该代码是否稍后将在具有或不具有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'
尝试使用list_physical_devices
来自tf.config.experimental的警告提示您使用。该代码对我有用。
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
print('GPU is available')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句