都是经验血的教训,全部原创太多不想写,截取很多博客的正确部分,补充一点,具体还是根据自己的实际情况而定
补充:
各个环境的兼容性,查看链接https://tensorflow.google.cn/install/source
CUDA9.0 +cuDNN v7.0参考链接
其中
选择cuDNN时选择 cudnn v7 Library for linux
anaconda 安装
其中要不要在最后加环境变量,,,,可先执行 source ~/.bashrc 这样就是更新环境变量,后 conda list 有反应,不是提示没有该命令,则不需添加环境变量,,如果没有反应,根据链接添加环境变量,记住是自己的用户名
ubuntu16.04使用anaconda创建python虚拟环境
新建环境、安装tensorflow-gpu
#要打开anaconda,终端输入
anaconda-navigator
#创建新环境 环境名 yolo 安装python3.6版本的
conda create -n yolo python=3.6
#激活环境
source activate yolo
pip install --upgrade pip
pip3 install --upgrade tensorflow-gpu
报错:
ERROR: tensorboard 1.14.0 has requirement setuptools>=41.0.0, but you'll have setuptools 36.4.0 which is incompatible.
解决:pip install --upgrade setuptools
ubuntu中PyCharm的安装与卸载
import tensorflow as tf
import numpy as np
x = tf.placeholder("float",shape=[None,1])
W = tf.Variable(tf.zeros([1,1]))
b = tf.Variable(tf.zeros([1]))
y = tf.matmul(x,W) +b
y_ = tf.placeholder("float",[None,1])
cost = tf.reduce_sum(tf.pow((y_-y),2))
train_step = tf.train.GradientDescentOptimizer(0.001).minimize(cost)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
All_x = np.empty(shape=[1,1])
All_y = np.empty(shape=[1,1])
for i in range(1000):
x_s = np.random.rand(1,1)
y_s = np.dot([[0.33]],np.random.rand(1,1)) + 0.33
feed = {x: x_s, y_: y_s}
sess.run(train_step,feed_dict=feed)
print("After %d iteration:"%i)
print("W : %f"%sess.run(W))
print("b : %f"%sess.run(b))
All_x = np.concatenate((All_x,x_s))
All_y = np.concatenate((All_y,y_s))
print(All_x)
print(All_y)