1.安装好所有的工具,在代码主要部分前面加上os.environ[“CUDA_VISIBLE_DEVICES”] = '0’如果失败
用win+R打开运行界面输入cmd,将路径位于C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi拖到cmd界面里,回车查看gpu的信息
2.安装gpu版tensorflow时
遇到ImportError: Could not find ‘cudart64_100.dll’
就是你的cuda的版本过低,建议安装cuda10.0以上的版本
3.判断你的tensorflow-gpu使用cpu还是gpu运行?
运行以下代码,观察输出的日志,有cpu就是使用cpu,有gpu就是使用gpu
with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
prin