3 回答

TA貢獻1842條經驗 獲得超13個贊
首先,您需要找到 GPU 設備:
physical_device = tf.config.experimental.list_physical_devices('GPU') print(f'Device found : {physical_device}')
然后您可以使用以下代碼檢查您的 GPU 設備是否已用于訓練:
tf.config.experimental.get_memory_growth(physical_device[0])
如果此代碼返回False
或什么都沒有,那么您可以運行下面的代碼來設置 GPU 進行訓練
tf.config.experimental.set_memory_growth(physical_device[0],True)

TA貢獻1824條經驗 獲得超5個贊
首先讓我們確保 tensorflow 正在檢測您的 GPU。運行下面的代碼。如果 GPU 數量=0,則表示未檢測到您的 GPU。要讓 tensorflow 使用 GPU,您需要安裝 Cuda 工具包和 Cudnn。如果未檢測到 GPU 并且您正在使用 Anaconda,請使用 Conda 重新安裝 tensorflow。它會自動安裝工具包和 Cudnn。當您使用它來安裝 tensorflow 時,pip 不會安裝這些。
import tensorflow as tf
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
print(tf.__version__)
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
tf.test.is_gpu_available()
!python --version

TA貢獻1797條經驗 獲得超4個贊
這是參考演示:
import tensorflow as tf
physical_device = tf.config.experimental.list_physical_devices('GPU')
print(f'Device found : {physical_device}')
添加回答
舉報