1、新手入门

1.1 安装tensorflow环境

1、安装了Anaconda,进入Anaconda Prompt:

关于安装Anaconda的博文参考:python安装、anaconda安装、pycharm安装

2、检测anaconda环境是否安装成功:conda --version

(base) C:\Users\toto>conda --version
conda 4.7.12

3、检测目前安装了哪些环境变量:

(base) C:\Users\toto>conda info --envs
# conda environments:
#
base                  *  D:\installed\Anaconda3

4、执行以下命令(下面的可能不需要执行,下面是看网上博文资料得出的):

(base) C:\Users\toto>conda info --envs
# conda environments:
#
base                  *  D:\installed\Anaconda3

5、先看看有哪些tensorflow的版本可以安装。
在Anaconda Prompt(Anaconda3)中输入:

pip install tensorflow==3.0

发现会出现如下错误:

(base) C:\Users\toto>pip install tensorflow==3.0
ERROR: Could not find a version that satisfies the requirement tensorflow==3.0 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 1.15.2, 1.15.3, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0, 2.1.1, 2.2.0rc0, 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0)
ERROR: No matching distribution found for tensorflow==3.0(base) C:\Users\toto>

出现上面错误的原因是,笔者安装的时候,压根儿都没有tensorflow3.0版本的,通过打印出的可选版本,可以知道最高版本是2.2.0

可以通过以下命令安装tensorflow:

(base) C:\Users\toto>pip install tensorflow==2.2.0 --default-timeout=1000 -i https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: tensorflow==2.2.0 in d:\installed\anaconda3\lib\site-packages (2.2.0)
Requirement already satisfied: absl-py>=0.7.0 in d:\installed\anaconda3\lib\site-packages (from tensorflow==2.2.0) (0.9.0)
Requirement already satisfied: astunparse==1.6.3 in d:\installed\anaconda3\lib\site-packages (from
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Requirement already satisfied: pyasn1>=0.1.3 in d:\installed\anaconda3\lib\site-packages (from rsa<4.1,>=3.1.4->google-auth<2,>=1.6.3->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (0.4.8)
Requirement already satisfied: oauthlib>=3.0.0 in d:\installed\anaconda3\lib\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (3.1.0)
Requirement already satisfied: more-itertools in d:\installed\anaconda3\lib\site-packages (from zipp>=0.5->importlib-metadata; python_version < "3.8"->markdown>=2.6.8->tensorboard<2.3.0,>=2.2.0->tensorflow==2.2.0) (7.2.0)(base) C:\Users\toto>

6、看tensorflow官网,安装命令是:

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

如果在上面过程中出现了如下错误:

Script file 'D:\Anaconda3\Scripts\pip-script.py' is not present

解决办法是:

easy_install pip

要注意的是,上面的过程一定要保证网络比较好,否则资料下载的很慢。

最后执行以下命令:

(base) C:\Users\toto>python
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-05-25 21:24:40.485797: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-25 21:24:40.495018: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
>>> tf.__version__
'2.2.0'
>>>

发现上面输出的内容是:2.2.0,也就是tensorflow 2.2.0版本

如果上面的过程还是出现了:HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out 这种问题。解决办法:
https://blog.csdn.net/chengyq116/article/details/93651619
原因是:

安装超时

网络原因导致的安装超时,重新下载。

设置超时时间延长后重新下载。
下载命令后添加参数 --default-timeout=1000,时间可以自定义。
pip install 默认超时时间是 15s,在安装的过程中可能会超时。我们在执行命令时,可显式指定超时时间。

--default-timeout=1000

更换安装源。
清华大学开源软件镜像 https://mirrors.tuna.tsinghua.edu.cn/

https://pypi.tuna.tsinghua.edu.cn/simple
sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scipy
sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-learn

豆瓣开源镜像

https://pypi.douban.com/simple
sudo pip install -i https://pypi.douban.com/simple scipy
sudo pip3 install -i https://pypi.douban.com/simple scikit-learn

下载离线包,使用 pip install ******.whl 安装。

然后再执行:

pip --default-timeout=1000 install tensorflow==2.2.0  -i https://pypi.tuna.tsinghua.edu.cn/simple   (对于tensorflow2.x CPU的和GPU的包都在此中,1.x的cpu的和gpu的包是分开的)

2 CUDA 10.1 和CUDnn 7.6.5 版本安装

TensorFlow 2.2.0 版本依赖:

Python 3.7:官方下载页面(3.7.7 版)
CUDA 10.1:官方下载页面
CUDnn 7.6.5:官方页面,下载需要注册一个开发者账户

2.1 CUDA下载

(1)、选择Windows > x86_64 > 10 > exe(local)

(2)、下载后是一个exe文件,读者自行安装即可,不要修改其中的路径信息,完全使用默认路径安装即可。
安装过程会出现(另外网友的安装方式是:https://www.cnblogs.com/arxive/p/11198420.html):







(3)、接着是下载和安装对应的cuDNN文件。下载地址为:(https://developer.nvidia.com/rdp/cudnn-archive)
在这个里面,选择window10相关的。在这个过程中,提示注册一个用户,那就按照它的提示进行注册即可。

最后,下载到的软件包:

(4)解压cuDNN,直接将其解压到CUDA安装目录即可。如下图所示:
即路径:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1

3 TensorFlow综述

TensorFlow是一个端到端的开源的机器学习平台。

TensorFlow可以让初学者和专家容易的创建机器学习模块,阅读下面的章节可以开始学习。

Tutorials
这里面包含了端到端的示例来告诉您如何使用TensorFlow,具体:

guide
Guides中解释了TensorFlow中的这些概念和组件。

2.1.1 For beginners(初学者)

最好的起点是用户友好的顺序(Sequential)API。您可以通过将构建块连接在一起来创建模型。运行下面的"Hello World"例子。接着阅读 tutorials以学习更多。

import tensorflow as tf
mnist = tf.keras.datasets.mnist(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0model = tf.keras.models.Sequential([tf.keras.layers.Flatten(input_shape=(28, 28)),tf.keras.layers.Dense(128, activation='relu'),tf.keras.layers.Dropout(0.2),tf.keras.layers.Dense(10, activation='softmax')
])model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

输出:

2020-05-26 19:38:16.347823: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-26 19:38:16.360988: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-05-26 19:38:46.447461: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-05-26 19:38:48.037471: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1060 computeCapability: 6.1
coreClock: 1.6705GHz coreCount: 10 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 178.99GiB/s
2020-05-26 19:38:48.044844: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-26 19:38:48.053003: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-05-26 19:38:48.060887: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2020-05-26 19:38:48.068320: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-05-26 19:38:48.076245: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-05-26 19:38:48.083698: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-05-26 19:38:48.091561: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-05-26 19:38:48.092104: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-05-26 19:38:48.155358: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-05-26 19:38:48.791458: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x19c132f21d0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-26 19:38:48.792138: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-05-26 19:38:48.831546: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-26 19:38:48.831961: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]
Epoch 1/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2933 - accuracy: 0.9151
Epoch 2/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.1411 - accuracy: 0.9582
Epoch 3/5
1875/1875 [==============================] - 3s 1ms/step - loss: 0.1038 - accuracy: 0.9685
Epoch 4/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0883 - accuracy: 0.9725
Epoch 5/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0744 - accuracy: 0.9758
313/313 [==============================] - 0s 1ms/step - loss: 0.0777 - accuracy: 0.9763

2.1.2 For experts (专家)

子类话的API为高级研究提供了一个按运行定义的接口,为您的模型创建一个类,然后命令式地写向前传。轻松创建自定义层、激活函数,和训练循环(training loops)。运行下面的"Hello World"示例。可以通过访问tutorials学习更多的内容

class MyModel(tf.keras.Model):def __init__(self):super(MyModel, self).__init__()self.conv1 = Conv2D(32, 3, activation='relu')self.flatten = Flatten()self.d1 = Dense(128, activation='relu')self.d2 = Dense(10, activation='softmax')def call(self, x):x = self.conv1(x)x = self.flatten(x)x = self.d1(x)return self.d2(x)
model = MyModel()with tf.GradientTape() as tape:logits = model(images)loss_value = loss(logits, labels)
grads = tape.gradient(loss_value, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))

2.1.3 TensorFlow和Keras之间的关系

TensorFlow的高级API基于Keras API标准,用于定义和训练神经网络。Keras支持快速原型设计、最先进的研究和生产——所有这些都具有用户友好的api
Read the Keras Guide for TensorFlow 2

3 常见问题解决

一步一步的探索,以帮助你的项目
初学者的第一个神经网络程序

专家的生成对抗网络

专家的神经网络机器翻译NMT

4 tensorflow社区

TensorFlow on GitHub

在Stack Overflow上问问题

参与社区讨论

打个赏呗,您的支持是我坚持写好博文的动力

02_tensorflow2环境安装、CUDA 10.1 和CUDnn 7.6.5 版本安装、https://tensorflow.google.cn/overview中概述翻译相关推荐

  1. 成功安装CUDA 10.0 和Cudnn 7.4.1

    from Bubbliiiing 网盘下载: 链接: https://pan.baidu.com/s/1znYSRDtLNFLufAuItOeoyQ 提取码: 8ggr 下载完之后得到这两个文件. 或 ...

  2. Win10安装CUDA 10.2

    转载请注明出处:Win10安装CUDA 10.2 文章目录 一.安装VS2015 二.安装CUDA 10.2 2.1 安装前工作 2.2 CUDA 10.2下载安装过程 2.2.1 下载CUDA 10 ...

  3. jetson tx2 安装cuda 10.2或者cuda 9全过程

    目录 1. 检查cuda 2. 提前安装一些必要软件 3. 安装jetson使用的cuda和cudnn 基础环境: jetpack 4.4,python3.6, ubuntu18.04 1. 检查cu ...

  4. CUDA 10.2及CUDNN下载

    CUDA 10.2 WINDOWS 10 X84_64版本下载地址: 链接:https://pan.baidu.com/s/1ZY3CkI-06yBhSTAXXvSL9A  提取码:0zjh CUDN ...

  5. Ubuntu18.04 安装CUDA前应注意的显卡、驱动版本信息

    一.确定显卡. 安装CUDA,首先要确定自己的显卡是N卡(英伟达 NVIDIA的标志),对于笔记本来说,通过键盘右下角贴的标签是AMD(A卡)还是NVIDIA(N卡)就可以判断. 二.查看显卡型号. ...

  6. ubuntu python3.7修改默认pip版本_详解Ubuntu16.04安装Python3.7及其pip3并切换为默认版本 安装python3后使用pip和pip3的区别...

    Python3.4已经默认安装了pip为什么执行不了我的谁说过,念念不忘就该放.但我也记得你说过,爱一个人不是一天两天的事. 如何升级到python3版本并且安装pip3 确保你的系统上已经安装好了 ...

  7. cuda 10.1和 cudnn 7.6.5

    链接:https://pan.baidu.com/s/1GdItUzszaBp5SKTgArZVLg 提取码:miao –来自百度网盘超级会员V1的分享

  8. Windows10安装cuda总是显示“XXX为失败或者XXX未安装”

    1遇到的错误 2解决办法 虽然不知道具体的原因,但是好像是VS的问题,所以在自定义安装的时候,把"Nsight VSE"和"Nsight Visual Studio Ed ...

  9. mysql安装与配置的截图_windows下MySQL5.6版本安装及配置过程附有截图和详细说明...

    随着MYSQL版本的更新以及电脑系统的变化,我们给大家整理了各种电脑环境下安装MYSQL的图解过程,希望我们整理的内容能够帮助到大家:mysql安装图解总结 https://www.jb51.net/ ...

最新文章

  1. 查询x,y之间的素数
  2. Android SlidingMenu 开源项目 侧拉菜单的使用(详细配置)
  3. matlab中如何随机排列,科学网—对图片进行拆分并随机排列的快速算法(MATLAB) - 徐磊的博文...
  4. IDEA 一直不停的scanning files to index解决办法
  5. 百度平台K12人群洞察报告
  6. C++程序的单元测试
  7. 4005基于邻接表的顶点的删除(C++,附思路)
  8. 【等价转换】—— 整数的变换
  9. java属性定义_Java管理扩展指南--几分钟带你理解MBean
  10. 技术出身要创业,容易吗?
  11. java医院门诊管理系统
  12. 蓝桥杯 PREV-10 幸运数
  13. 你有哪些独到的识人技巧?
  14. Crontab 每隔整点1小时2小时执行一次任务
  15. 环境和社会风险分类c类_企业经营风险的定义、种类以及基本分类
  16. PySide2多线程问题示例:创建新线程、子线程发射信号到主界面
  17. 创建Python3虚拟环境失败问题跟进
  18. 随性随笔_201508
  19. ORACLE之NLS的那些事
  20. 量化交易入门----双均线策略

热门文章

  1. Python安装PyOpenGL
  2. python 错误处理 assert
  3. JavaScript实现按位运算符乘以无符号数multiplyUnsigned算法(附完整源码)
  4. OpenCASCADE绘制测试线束:几何命令之Intersections
  5. wxWidgets:wxDataObjectComposite类用法
  6. wxWidgets:wxCalendarCtrl类用法
  7. wxWidgets:Sizer 概览
  8. boost::static_mutex 的测试程序
  9. boost::math模块计算二项式随机变量的概率和分位数的简单示例
  10. VTK:Utilities之Scalars