Win10搭建tensorflow环境笔记

Win10搭建tensorflow环境笔记

    • 版本记录
    • Hardware
    • Choose the right version suitable for you device
    • Anaconda 环境搭建
    • Create new project in Pycharm based on the environment built before
    • Remark
    • 参考博文
    • 更新

版本记录

Anaconda :
CUDA Toolkit : v10.1
cudnn: v7.6.4
tensorflow : tensorflow-gpu 2.1.0

Hardware

显卡 :NVIDIA GeForce GTX 1050
Driver Version : 442.
Note:查看显卡及驱动版本

nvidia-smi

Choose the right version suitable for you device

Win10搭建tensorflow环境笔记_第1张图片
tensorflow-gpu 2.0要求CUDA v10.0及以上, cudnn>=7.4.1
tensorflow-gpu 2.1要求CUDA v10.1及以上, cudnn>=7.6

Anaconda 环境搭建

#优先命名用清华conda 镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
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/fastai/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

# 搜索时显示通道地址
conda config --set show_channel_urls yes
conda create -n tf2 python=3.6

# check if the environment has been created successfully
conda info --env
# activate the environment
conda activate tf2
# install the gpu version
conda install cudatoolkit=10.1 cudnn=7.6
conda install tensorflow-gpu=2.1.0
# to install the cpu version: 

# check if tensorflow has been installed succesfully
python
import tensorflow as tf
# check if gpu version has been built succesfully
tf.test.is_built_with_gpu()
# remember to exit
exit()

# if the AttributeError comes
# use the following command:
conda list # to check whether the tensorflow-gpu and tensorflow-gpu estimator
# are version-matched
# If not matched, use following command to install the matched estimator
conda install tensorflow-estimator=2.1.0

# when everything is done, deactivate the environment
conda deactivate

Create new project in Pycharm based on the environment built before

FIle -> Settings
Win10搭建tensorflow环境笔记_第2张图片
Project -> Python Interpreter -> 小齿轮 -> Add -> 添加环境下的python.exe文件
Win10搭建tensorflow环境笔记_第3张图片
为了更直观的调试,可以将文件设置为在console下运行:
Run -> Edit Configurations
Win10搭建tensorflow环境笔记_第4张图片
Python -> run with console
Win10搭建tensorflow环境笔记_第5张图片

Remark

若设备无独立显卡,或显卡不是NVIDIA,则不能通过下载CUDA Toolkit来搭载tensorflow-gpu环境,可以搭建tensorflow环境。

参考博文

Tensorflow2.x教程

CUDA及cudnn安装


19/11/2020

更新

20/11/2020
安装matplotlib库时报错:
error location of failed script: F:\Anaconda\envs\tf2\Scripts.qt-post-link.bat>
Win10搭建tensorflow环境笔记_第6张图片解决方法:
参考:问答

没找到回答中的文件,故在
F:\Anaconda\pkgs\qt-5.9.7-vc14h73c81de_0\Scripts里修改.qt-post-link.bat文件:
@echo off 下方添加

set PATH=%PATH%;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;

Win10搭建tensorflow环境笔记_第7张图片再次安装,安装成功但是会因为文件字长不匹配报warning:
Win10搭建tensorflow环境笔记_第8张图片

你可能感兴趣的:(深度学习,cuda,tensorflow,gpu)