我正在编写代码以训练模型,我不确定此代码以后是否可以在具有或不具有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'
尝试使用tf.config.experimental中的list_physical_devices
,您的警告提示您使用。该代码对我有用。
list_physical_devices