当前位置:网站首页>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
边栏推荐
- Shiny02---Shiny exception solution
- 【Dynamic type detection Objective-C】
- [Shanghai] Hiring .Net Senior Software Engineer & BI Data Warehouse Engineer (Urgent)
- [NOIP2010 提高组] 机器翻译
- 爬虫从入门到入牢
- An IP conflict is reported after installing the software on a dedicated computer terminal
- Use of thread pool (combined with Future/Callable)
- Redis实现分布式锁-原理-问题详解
- 线程池的创建及参数设置详解
- 二叉树进阶复习1
猜你喜欢
随机推荐
C-Eighty seven(背包+bitset)
Redis实现分布式锁-原理-问题详解
字符串提取 中文、英文、数字
Qt编写自定义控件:文字聚光灯效果之一
小本创业者的致胜法宝!
v-if/v-else根据计算判断是否显示
[Shanghai] Hiring .Net Senior Software Engineer & BI Data Warehouse Engineer (Urgent)
JVM运行流程,运行时数据区,类加载,垃圾回收,JMM解析
SVG星球大战样式Toggle切换开关按钮
2022.7.29好题选讲(计数专题)
二叉树进阶复习1
【结构体内功修炼】结构体内存对齐(一)
[NOIP2010 提高组] 机器翻译
unity urp 渲染管线顶点偏移的实现
Fiddler工具讲解
版本号命名规则
Invalid operator for data type.The operator is add and the type is text.
【win7】NtWaitForKeyedEvent
Win10 设置锁屏壁纸提示尝试其它图片
TRACE32——外设寄存器查看与修改