Ubuntu + CUDA9.0 +cuDNN v7.0. +anaconda 安装+tensorflow-gpu 安装+PyCharm的安装

本文详细介绍了在Ubuntu 16.04环境下,如何从零开始搭建支持GPU的TensorFlow开发环境。包括CUDA和cuDNN的安装配置,Anaconda的使用,以及如何创建并激活虚拟环境。同时,提供了在PyCharm中验证TensorFlow安装是否成功的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

都是经验血的教训,全部原创太多不想写,截取很多博客的正确部分,补充一点,具体还是根据自己的实际情况而定

补充:

各个环境的兼容性,查看链接https://tensorflow.google.cn/install/source

 CUDA9.0 +cuDNN v7.0参考链接

安装CUDA 参考https://blog.youkuaiyun.com/qq_35976351/article/details/79325476

其中

选择cuDNN时选择 cudnn v7 Library for linux 

安装cuDNN参考 https://blog.youkuaiyun.com/caicaiatnbu/article/details/87626491

anaconda 安装

https://blog.youkuaiyun.com/luojie140/article/details/78696330

其中要不要在最后加环境变量,,,,可先执行  source ~/.bashrc   这样就是更新环境变量,后 conda list 有反应,不是提示没有该命令,则不需添加环境变量,,如果没有反应,根据链接添加环境变量,记住是自己的用户名

ubuntu16.04使用anaconda创建python虚拟环境

https://blog.youkuaiyun.com/ITBigGod/article/details/85692561

新建环境、安装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的安装与卸载

https://blog.youkuaiyun.com/weixin_31484477/article/details/81133590

在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)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值