安裝了anaconda不需要安裝cuda和cudnn!
我電腦i7 1060,之前一直在找匹配的cuda和cudnn,安裝出現各種問題,直到高人提醒,anaconda自帶cuda和cudnn。
我開啟開始選單裡的anaconda裡的navigator,發現cuda和cudnn狀態是installed,cuda版本是9.0,執行測試程式,證實可以在gpu上執行!
我建了幾個環境,除了系統自帶的base環境,還有自己裝的TensorFlow環境,裝的Python3.7,發現沒有對應的TensorFlow,建了py36環境,裝Python3.6,後來發現裝的是CPU版本,於是建了py36-gpu環境裝GPU版TensorFlow。
測試程式
import tensorflow as tf import numpy as np
# 使用 NumPy 生成假資料(phony data), 總共 100 個點. x_data = np.float32(np.random.rand(2, 100)) # 隨機輸入 y_data = np.dot([0.100, 0.200], x_data) + 0.300
# 構造一個線性模型 # b = tf.Variable(tf.zeros([1])) W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0)) y = tf.matmul(W, x_data) + b
# 最小化方差 loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss)
# 初始化變數 init = tf.initialize_all_variables()
# 啟動圖 (graph) sess = tf.Session() sess.run(init)
# 擬合平面 for step in range(0, 201): sess.run(train) if step % 20 == 0: print (step, sess.run(W), sess.run(b))
# 得到最佳擬合結果 W: [[0.100 0.200]], b: [0.300]
程式碼來自這裡: