本人配置: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. git命令合集

    ##快捷键 ##一. 快捷键 1. 清屏快捷键 control+L 2. vim快捷操作 * control+b 往上翻页 * Control+f 往下翻页 * shift+g 回到末尾 3. oh ...

  2. WPF-GridView设置列宽按比例分配

    将ListView包裹在一个父Grid中 写一个与ListView平行的Grid,设置该Grid的列数与ListView中GridView的列数相同,将该Grid各列设置列宽按比例分配 将ListVi ...

  3. Springboot循环依赖实践纪实

    测试的Springboot版本: 2.6.4,禁止了循环依赖,但是可以通过application.yml开启(哈哈) @Lazy注解解决循环依赖 情况一:只有简单属性关系的循环依赖 涉及的Bean: ...

  4. go RWMutex 的实现

    Overview go 里面的 rwlock 是 write preferred 的,可以避免写锁饥饿. 读锁和写锁按照先来后到的规则持有锁,一旦有协程持有了写锁,后面的协程只能在写锁被释放后才能得到 ...

  5. 实践2:如何使用word2vec和k-means聚类寻找相似的城市

    理解业务 一个需求:把相似的目的地整理出来,然后可以通过这些相似目的地做相关推荐,或者是相关目的地的推荐 准备数据 Word2Vec算法:可以学习输入的文本,并输出一个词向量模型 对数据进行清洗,去出 ...

  6. SuperEdge: 使用WebAssembly扩展边缘计算场景

    作者 SuperEdge 开发者团队 概要 SuperEdge 是 一个开源的分布式边缘计算容器管理系统,用于管理多个云边区域中的计算资源和容器应用. 在当前架构中,这些资源和应用能够作为一个 Kub ...

  7. Mock平台3-初识Antd React 开箱即用中台前端框架

    微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. 内容提要 首先说下为啥这次测试开发系列教程前端选择Antd React,其实也是纠结对比过最终决定挑战一把,想法大概有几下几点: 笔者自己 ...

  8. 工程师计划3 -> 项目管理2 | 项目组织与团队管理

    前几天才收到这门课的教材,发现网课的周和课本的章节不完全对应,我以教材的章节为单位进行总结和思考.这篇就是对于第二章的梳理. 0317附:这篇压了很久了,已经落后课程进度了.整理下来觉得有些偏理论,后 ...

  9. 什么是SaaS?

    SaaS的定义 SaaS,是Software-as-a-Service的缩写名称,意思为软件即服务,即通过网络提供软件服务. SaaS平台供应商将应用软件统一部署在自己的服务器上,客户可以根据工作实际 ...

  10. SQL基础语法_周志城

    一:建库建表语法,字段数据类型 1:建库建表语法 create  (创建,关键字) database (数据库,关键字) IF NOT EXISTS  作用:如果需要创建的库已存在,将不会创建 DEF ...