当前位置:网站首页>TensorFlow installation steps
TensorFlow installation steps
2022-08-05 07:54:00 【sheep sheep pig】
环境:Win10,Python 3.8,Anaconda
电脑:GeForce RTX 2060, NVIDIA CUDA 11.1.4
官方教程:在 Windows 上安装 TensorFlow
1. 下载安装cuda和cudnn
1.1 下载
在官网上下载对应的cuda和cudnn,The version can be lower but not higher than the version supported by the computer
cuda下载地址:cuda-toolkit-archive
cudnn下载地址:cudnn-archive
常见问题: 下载cudnn的时候有提示:NVIDIA Developer Program Membership Required
解决方法: 右键选择【复制链接地址】,Copy the link to Thunder Downloader or other download software to download
1.2 安装
CUDA安装:选自定义安装→默认安装路径→安装结束
安装完成后,Two system variables are generated by default.
View system variables:此电脑→右键选属性→高级系统设置→环境变量→系统变量
CuDNN安装
解压→将三个文件夹复制到cuda的安装目录下,Just choose to overwrite the file.
安装完了,测试cuda版本.
打开cmd,输入指令:nvcc -V
2. 创建 tensorflow 环境
2.1 创建 tensorflow 环境
conda create -n tensorflow python=3.8
常见问题
ERROR:Collecting package metadata (current——repodata.json): failed
我的解决方法:将C:\Users\Lenovo下的.condarc文件作如下修改(Modify your path here)
ssl_verify: true
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
show_channel_urls: true

2.2 查看环境,You can see that the environment has been created**
conda env list

2.3 进入环境
activate tensorflow

enter the specific path
# Replace here with your own specific path
>cd C:\Users\Lenovo\anaconda3\envs\tensorflow

2.4 安装默认版本的tensorflow-cpu或者tensorflow-gpu.
安装tensorflow-cpu版本的,可以输入命令:pip install --ignore-installed --upgrade tensorflow
安装tensorflow-gpu版本的,可以输入命令:pip install --ignore-installed --upgrade tensorflow-gpu
常见问题
1 网速问题
解决方法:Go directly to the website to download the required files(Download whatever file your computer downloads,我的是tensorflow_gpu-2.9.1-cp38-cp38-win_amd64.whl)
网址 tensorflow-gpu 2.9.1 ,Download the file to your owntensorflow的目录下.
输入命令:pip install tensorflow_gpu-2.9.1-cp38-cp38-win_amd64.whl
2 ERROR: Could not find a version that satisfies the requirement XXX
解决方法:直接选用pip源并且信任它的来源就可以解决这种问题
pip install tensorflow_gpu-2.9.1-cp38-cp38-win_amd64.whl -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
2.5 查看 tensorflow Version information and exit
查看 tensorflow 版本
输入命令:pip show tensorflow-gpu,可以查看tensorflow的版本信息
退出 tensorflow 环境
conda deactivate tensorflow
3. 测试 TensorFlow-gpu 是否安装成功
打开Anaconda,选择tensorflow环境,打开spyder,It needs to be installed for the first timeSpyder,直接点下方的install即可.
测试代码
import tensorflow as tf
a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)
print(tf.__version__)
print(tf.test.gpu_device_name())
print('GPU:',tf.config.list_physical_devices(device_type='GPU'))
print('CPU:',tf.config.list_physical_devices(device_type='CPU'))
print(tf.test.is_gpu_available())
常见问题
Could not load dynamic library ‘cusolver64_11.dll‘; dlerror: cusolver64_11.dll not found
解决方法:
链接:https://pan.baidu.com/s/1W9fR2N_hoVD-7_ODtOiJhg
提取码:u65i
下载文件,把文件cusolver64_11.dlladded to the created environment\Library\bin中
运行代码
安装完成
3. 测试速度
import tensorflow as tf
import timeit
#指定在cpu上运行
def cpu_run():
with tf.device('/cpu:0'):
cpu_a = tf.random.normal([10000, 1000])
cpu_b = tf.random.normal([1000, 2000])
cpu_c = tf.matmul(cpu_a, cpu_b)
# print( "cpu_a: ", cpu_a.device)
# print( "cpu_b: ", cpu_b.device)
# print("cpu_c:", cpu_c.device)
return cpu_c
#指定在gpu上运行
def gpu_run():
with tf.device( '/gpu:0'):
gpu_a = tf.random.normal([ 10000,1000])
gpu_b = tf.random.normal([ 1000, 2000])
gpu_c = tf.matmul(gpu_a, gpu_b)
# print( "gpu_a: ", gpu_a.device)
# print("gpu_b: ", gpu_b.device)
# print("gpu_c: ", gpu_c.device)
return gpu_c
cpu_time = timeit.timeit(cpu_run, number = 10)
gpu_time = timeit.timeit(gpu_run, number = 10)
print('cpu:',cpu_time, 'gpu:',gpu_time)

The speed is still a lot faster
参考来源:
tensorflow详细安装教程(Win10, Anaconda,Python3.9)
绕过NvidiaOfficially required registration or login steps to download directlycuDNN的方法
详解Anaconda安装tensorflow报错问题解决方法
anaconda3There was a problem creating the virtual environment:Collecting package metadata (current——repodata.json): failed
边栏推荐
猜你喜欢

TRACE32——SMP多核调试

Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions

YOLOv3 SPP理论详解(包括CIoU及Focal loss)

SVG Star Wars Style Toggle Toggle Button

Use of thread pool (combined with Future/Callable)

线性代数对角化

【 LeetCode 】 235. A binary search tree in recent common ancestor

SVG星球大战样式Toggle切换开关按钮

TRACE32——通用寄存器查看与修改

关于MP3文件中找不到TAG标签的问题
随机推荐
2006年星座运势全解-射手
Illegal key size 报错问题
长期招聘嵌入式开发-深圳宝安
VXE-Table融合多语言
标准C语言15
版本号命名规则
导出SQLServer数据到Excel中
程序设计中的感悟
Qt编写自定义控件:文字聚光灯效果之一
TRACE32——Go.direct
请问my sql如何把两个表的内容集合在一起啊?
在ASP控制数字及字母输入
二叉树进阶复习1
browserslist 选项的目的是什么?
2022.7.29好题选讲(计数专题)
Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
SQL SERVER关于主从表触发器设计
Win10 设置锁屏壁纸提示尝试其它图片
Chapter3、色调映射
TRACE32——外设寄存器查看与修改