本人配置:window10+GTX 1650+tensorflow-gpu 1.14+keras-gpu 2.2.5+python 3.6,亲测可行

一.Anaconda安装

直接到清华镜像网站下载(什么版本都可以):https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

这是我下载的版本,自带python版本为3.6

下载后直接安装即可,可参考:https://www.cnblogs.com/maxiaodoubao/p/9854595.html

二.建立开发环境

1.打开Prompt

点击开始,选择Anaconda Prompt(anaconda3)

 

2.更换conda源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

按照这么写的话,后续创建环境会报错:

所以直接打开.condarc文件,改为如下(将https改为http,去掉了default,末尾添加了/win-64/):

ssl_verify: true
show_channel_urls: true
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/

3.创建虚拟环境

创建一个名为tensorflow ,python版本为3.6的虚拟环境

conda create -n tensorflow python=3.6

查看虚拟环境

conda info -e

激活开发环境

activate tensorflow

三.安装tensorflow-gpu和keras-gpu

首先,这里有两种安装方式,一种是conda,一种是pip,conda下载较慢,但会自动安装适合的CUDA和CuDnn,pip安装快,但是需要手动安装CUDA和CuDnn,这里重点介绍pip安装方式

1.conda安装

输入命令,需要下载一些包,直到done,自动下载了gpu,直接可以使用,比较方便和简单

conda install tensorflow-gpu==xxx.xxx.xx你想要的版本号

本人一开始使用这种方法,结果在下载时经常卡住,中断,主要还是因为网络问题,需要多试几次,可以安装成功,因此需要使用国内镜像,但是使用镜像后,依然安装不成功,所以放弃了这种方法。

2.pip安装(有很多坑)

(1)打开计算机管理

   点击查看gpu算力:CUDA GPUs | NVIDIA Developer

  算力高于3.1就行,就可以跑深度程序。

(2)打开NVIDIV控制面板

  

  

  

   可以看到最大支持CUDA版本是11.4,只要下载的版本没有超过最大值即可。

(3)安装CUDA

  CUDA下载地址:CUDA Toolkit Archive | NVIDIA Developer (亲测,官网下载不慢)

  注意:cuda和cudnn安装要注意版本搭配,以及和python版本的搭配,然后根据自己的需要安装

  

  以下是我的下载

  下载之后:按照步骤安装

  

  

  

  

  

  配置环境变量:

  

  

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp

  不要直接在path里面配置,会显示太大

(4)安装cuDNN:

  cuDNN下载地址:cuDNN Archive | NVIDIA Developer(亲测,官网下载不慢)

  注意:cuDNN要跟CUDA版本搭配好,不能随便下载

  

    安装时,可能需要注册NVIDIA账户,花一点时间注册一下即可下载。

  下载完后,将文件解压,将里面的文件全部导入到CUDA/v10.0路径下。

(5)安装tensorflow-gpu和keras-gpu

可以对照表格安装对应版本tensorflow和keras

pip install tensorflow-gpu==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install keras-gpu==2.2.5 -i https://pypi.tuna.tsinghua.edu.cn/simple

(6)安装其他库

pip install -i https://pypi.doubanio.com/simple/ opencv-python
pip install -i https://pypi.doubanio.com/simple/ pillow
pip install -i https://pypi.doubanio.com/simple/ matplotlib
pip install -i https://pypi.doubanio.com/simple/ sklearn

四.测试是否使用了GPU

进入python编译环境,输入一下代码,如果结果是True,表示GPU可用

import tensorflow as tf
print(tf.test.is_gpu_available())

若为True,使用命令查看gpu是否在运行

nvidia-smi

五.jupyter使用虚拟环境

其实使用虚拟环境非常简单,只需要安装一个nb_conda包就可以直接使用了

conda install nb_conda 

在你的新环境上安装ipykernel,重启jupyter之后就可以用了

conda install -n tensorflow ipykernel

正好可以测试tensorflow和keras是否在GPU上运行

来段代码测试一下:

import numpy as np

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
import matplotlib.pyplot as plt
from sklearn import datasets # 样本数据集,两个特征列,两个分类二分类不需要onehot编码,直接将类别转换为0和1,分别代表正样本的概率。
X,y=datasets.make_classification(n_samples=200, n_features=2, n_informative=2, n_redundant=0,n_repeated=0, n_classes=2, n_clusters_per_class=1) # 构建神经网络模型
model = Sequential()
model.add(Dense(input_dim=2, units=1))
model.add(Activation('sigmoid')) # 选定loss函数和优化器
model.compile(loss='binary_crossentropy', optimizer='sgd') # 训练过程
print('Training -----------')
for step in range(501):
cost = model.train_on_batch(X, y)
if step % 50 == 0:
print("After %d trainings, the cost: %f" % (step, cost)) # 测试过程
print('\nTesting ------------')
cost = model.evaluate(X, y, batch_size=40)
print('test cost:', cost)
W, b = model.layers[0].get_weights()
print('Weights=', W, '\nbiases=', b) # 将训练结果绘出
Y_pred = model.predict(X)
Y_pred = (Y_pred*2).astype('int') # 将概率转化为类标号,概率在0-0.5时,转为0,概率在0.5-1时转为1
# 绘制散点图 参数:x横轴 y纵轴
plt.subplot(2,1,1).scatter(X[:,0], X[:,1], c=Y_pred[:,0])
plt.subplot(2,1,2).scatter(X[:,0], X[:,1], c=y)
plt.show()

结果:

到此说明已经彻底成功安装上tensorflow和keras了

七.可能的问题

1.安装1.14.0版本的tensorflow后,运行时出现了错误

Using TensorFlow backend.
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\tools\_virtualenv_dir\myproject_2_quchumasaike\env2_py36_quchumasaike\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])

解决方法:

这个问题意思就是numpy的版本过低或者过高都会出现警告,只需要先卸载重新指定版本的numpy即可解决此问题

pip uninstall numpy
pip install numpy==1.16.4

2.anaconda卸载不干净:

解决办法:

(1)执行命令

conda config --remove-key channels
conda install anaconda-clean
anaconda-clean --yes

(2)运行安装目录下的 Uninstall-Anaconda3.exe 程序即可,这样就成功地将anaconda完全卸载干净了

3.利用镜像安装tensorflow-gpu

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu

4.高版本可能出现错误:AttributeError: module ‘tensorflow_core._api.v2.config’ has no attribute ‘experimental_list_devices’

解决方法:解决module ‘tensorflow_core._api.v2.config‘ has no attribute ‘experimental_list_devices‘_sinysama的博客 (亲测有效)

八.网盘下载

1.anaconda下载(5.2.0和5.3.1):

链接:https://pan.baidu.com/s/1-iw1hjfL2u4CumCW0b0Zvg
提取码:hort

2.cuDNN和CUDA下载(10.0,10.1,11.4):

链接:https://pan.baidu.com/s/1-06nzKI8CrlWOsKfeuY3Gw
提取码:8v05

参考文章:

FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version

如何完全卸载Anaconda(如何下载Anaconda-Clean package)_托马斯-酷涛的博客

利用镜像安装tensorflow_不知方向的鸵鸟的博客

怎么查看keras 或者 tensorflow 正在使用的GPU_Thinker_and_FKer的博客

Jupyter Notebook运行指定的conda虚拟环境_我是天才很好的博客

Anaconda镜像安装tensorflow-gpu1.14及Keras超详细版_Xnion的博客

win10完整Tensorflow-GPU环境搭建教程-附CUDA+cuDNN安装过程_尤利乌斯.X的博客

cuda安装教程+cudnn安装教程_hw@c14h10的博客

tensorflow版本对应关系_蠕动的爬虫的博客

Anaconda安装tensorflow和keras(gpu版,超详细)的更多相关文章

  1. win10+anaconda安装tensorflow和keras遇到的坑小结

    win10下利用anaconda安装tensorflow和keras的教程都大同小异(针对CPU版本,我的gpu是1050TI的MAX-Q,不知为啥一直没安装成功),下面简单说下步骤. 一 Anaco ...

  2. Anaconda 安装 tensorflow 和 keras

    说明:此操作是在 Anaconda Prompt 窗口完成的 CPU版 tensorflow 的安装. 1.用 conda 创建虚拟环境 tensorflow python=3.6 conda cre ...

  3. windows安装TensorFlow和Keras遇到的问题及其解决方法

    安装TensorFlow在Windows上,真是让我心力交瘁,想死的心都有了,在Windows上做开发真的让人发狂. 首先说一下我的经历,本来也就是起初,网上说python3.7不支持TensorFl ...

  4. 保姆级教程——Ubuntu16.04 Server下深度学习环境搭建:安装CUDA8.0,cuDNN6.0,Bazel0.5.4,源码编译安装TensorFlow1.4.0(GPU版)

    写在前面 本文叙述了在Ubuntu16.04 Server下安装CUDA8.0,cuDNN6.0以及源码编译安装TensorFlow1.4.0(GPU版)的亲身经历,包括遇到的问题及解决办法,也有一些 ...

  5. 使用anaconda安装tensorflow (windows10环境)

    版权声明:勤学 修德 明辨 笃实 - CSDN周雄伟 https://blog.csdn.net/ebzxw/article/details/80701613 已有环境:python3.7.1 ana ...

  6. 我在Suse 11 Sp3上使用anaconda安装TensorFlow的过程记录

    我在Suse 11 Sp3上使用anaconda安装TensorFlow的过程记录 准备安装包: gcc48 glibc--SP4-DVD-x86_64-GM-DVD1.iso tensorflow_ ...

  7. 基于Anaconda安装Tensorflow 并实现在Spyder中的应用

    基于Anaconda安装Tensorflow 并实现在Spyder中的应用 Anaconda可隔离管理多个环境,互不影响.这里,在anaconda中安装最新的python3.6.5 版本. 一.安装 ...

  8. VMware安装Ubuntu20(图文教程,超详细)

    VMware安装Ubuntu20(图文教程,超详细) 此文讲述使用 VMware 工具安装 Ubuntu 系列虚拟机,不同位数和不同版本的 Ubuntu 安装过程相差无几,这里以 Ubuntu20 6 ...

  9. 【吴恩达课程使用】keras cpu版安装【接】- anaconda (python 3.7) win10安装 tensorflow 1.8 cpu版

    一.确认tensorflow的版本: 接上一条tensorflow的安装,注意版本不匹配会出现很多问题!:[吴恩达课程使用]anaconda (python 3.7) win10安装 tensorfl ...

随机推荐

  1. 为 CmakeLists.txt 添加 boost 组件

    目录 为 CmakeLists.txt 添加 boost 组件 Boost 常用组件 1.时间与日期 timer, date_time, chrono 2.内存管理 system 3.实用工具库 4. ...

  2. JAVA_Scanner 键盘输入

    键盘输入语句 介绍:在编程中,需要接收用户输入的数据,就可以使用键盘输入语句来获取.Input.java , 需要一个 扫描器(对象), 就是 Scanner 步骤: 导入该类的所在包, java.u ...

  3. 2022最新IntellJ IDEA诺依开发部署文档

    前景提示 若伊是国内一款很好的开源项目,非常的便于学习,而且它是开源免费的,但是,它的开发部署文档实在是没法按照那个文档,快速高效的在本地搭建一套可以运行的项目,对于学习开发和使用实在是一大难题,为此 ...

  4. Python:pyglet学习(2)图形的旋转&batch

    这次讲讲图形的旋转和批量渲染(rotate.batch) 1:图形旋转 先看看上次的代码中的一段: glRotatef(rot_y, 0, 1, 0) glRotatef(rot_z,0,0,1) g ...

  5. 自己的markdown笔记

    markdown一些语法 记录自己会用的一些markdown语法,不定期更新,用的软件是hroopad,hroopad下载地址点击跳转.这个书写软件对新手还有中文用户比较友好,左边是markdown语 ...

  6. 数据备份RAID1 和RAID5详解和对比

    数据备份RAID1 和RAID5详解和对比 RAID 全称 Redundant Array of Independent Disks,中文意思"独立的冗余磁盘列队". RAID 一 ...

  7. pandas常用操作详解——.loc与.iloc函数的使用及区别

    loc与iloc功能介绍:数据切片.通过索引来提取数据集中相应的行数据or列数据(可以是多行or多列) 总结: 不同:1. loc函数通过调用index名称的具体值来取数据2. iloc函数通过行序号 ...

  8. 最小生成树MST算法(Prim、Kruskal)

    最小生成树MST(Minimum Spanning Tree) (1)概念 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边,所谓一个 ...

  9. python学习之scipy实战1(积分用法)

    import numpy as np def main(): #1-- Integral积分 from scipy.integrate import quad, dblquad, nquad prin ...

  10. WPF中Enter 焦点转移方法

    1.Set the TabIndex="16"2. private void detailGrid_Keydown(object sender, KeyEventArgs e) { ...