TensorFlow 您所在的位置:网站首页 anaconda包含tensorflow吗 TensorFlow

TensorFlow

2023-07-29 21:40| 来源: 网络整理| 查看: 265

前言:

看到网上大部分TensorFlowGPU教程都需要看配置需要装一大堆东西,然后就来更新一篇我知道的最简便的安装GPU版本的方法了,不用安装CUDA CUDNN VS啥的,可能目前内容上有点粗糙,后续会慢慢完善的。个人安装的目的就是为了重新下载一个与keras版本匹配的TensorFlow,具体可以通过这个网址查看Keras与TensorFlow的对应版本,然后我卸载了之前的TensorFlowGPU版本,顺便来记录一下安装过程,当然,读者可以根据自己的需要去下载其他的TensorFlow-GPU

 

一、准备阶段

     

设备环境:win10+你电脑上有GPU。。。(虽然听起来有点无脑)安装anaconda,这部分就不多说了,需要下载的请直接到官网下载,然后直接安装,不放心的话去看看其他博客教程卸载TensorFlow-GPU+Keras这一步是我自己需要做的,如果你原先没有Tensorflow-gpu就不用管了,直接跳到下一步。

卸载指令:conda uninstall tensorflow-gpu==1.14.0

                  conda uninstall keras==1.0.8

 

但是这里我用conda卸载报错,应该是默认的镜像源的处理速度太慢导致超时,这里的处理方法是可以考虑换成清华源再卸载,不过我的环境里有pip就测试用pip卸载了,行得通。后面卸载Keras也是一样的原理。

 

二、安装 如果你刚安装好anaconda,或者出于其他原因,第一步就从建立一个虚拟环境开始吧。

按照下图的顺序来,②的命名自己随意,③的选项建议选3.6或7吧,或者有更高版本也好,尽量别选2.X,2.7的据说都快要停止维护了,对python新手而言也不要选版本太高的,可能不稳定。

点击创建之后可能会等一段时间(因为会配备相关必要的库所以可能有点慢)。

虚拟环境建完之后,操作如下图:                                                                                                                                                                                                                                                                   

再点击“open terminal”进入终端界面:

         

 

3.接下来就是重头戏了,安装TensorFlow-GPU:

在终端输入:conda install -c aaronzs tensorflow-gpu

默认应该是下载最新版本,如果要特定版本,就conda install -c aaronzs tensorflow-gpu==xxx

但是我发现这个方法无法下载2.2.0版本,所以我退而求其次地下载了2.2.1了

这个过程可能会报warning什么的,如果可以运行就忽略,有报什么错欢迎在评论区留言。

然后就是漫长地等待了

完成后再输入 conda list看看

4.安装成功!!结束了!!!!对就是这么简单!!!!

但是,最后我们还是测试一下到底有没有配置成功:

因为我用的是Pycharm,这里再附加一下Pycharm配置Anaconda环境的过程:

按照下图所示,或者直接Ctrl+Alt+S

打开设置之后就按照下图操作,选完之后就全点"OK"

 

操作之后,可以看到右下角会显示当前的环境:

 

然后关键的一步测试了!操作如下:

新建一个python文件,然后输入以下代码,然后运行:  

import tensorflow as tf import os #os.environ['TF_CPP_MIN_LOG_LEVEL']='2' a = tf.constant(1.) b = tf.constant(2.) print(a+b) print(tf.__version__) print('GPU:', tf.config.list_physical_devices('GPU')) print(tf.test.is_gpu_available())

 

输出结果为:

tf.Tensor(3.0, shape=(), dtype=float32) 2.1.0 GPU: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] True

当然,,由于是用GPU跑的,所以会有这些信息:

2021-01-06 11:54:57.365737: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2021-01-06 11:55:00.178440: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll 2021-01-06 11:55:00.862896: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce GTX 1050 computeCapability: 6.1 coreClock: 1.493GHz coreCount: 5 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 104.43GiB/s 2021-01-06 11:55:00.863272: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2021-01-06 11:55:00.868083: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll 2021-01-06 11:55:00.872729: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll 2021-01-06 11:55:00.874234: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll 2021-01-06 11:55:00.879152: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll 2021-01-06 11:55:00.881920: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll 2021-01-06 11:55:00.892460: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll 2021-01-06 11:55:00.892777: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0 2021-01-06 11:55:00.893388: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 2021-01-06 11:55:00.895935: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce GTX 1050 computeCapability: 6.1 coreClock: 1.493GHz coreCount: 5 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 104.43GiB/s 2021-01-06 11:55:00.896318: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2021-01-06 11:55:00.896510: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll 2021-01-06 11:55:00.896701: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll 2021-01-06 11:55:00.896891: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll 2021-01-06 11:55:00.897081: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll 2021-01-06 11:55:00.897269: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll 2021-01-06 11:55:00.897458: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll 2021-01-06 11:55:00.897699: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0 2021-01-06 11:55:01.557072: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix: 2021-01-06 11:55:01.557299: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] 0 2021-01-06 11:55:01.557426: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0: N 2021-01-06 11:55:01.557723: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1335 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)

然后就结束了!!!完成!!!✿✿ヽ(°▽°)ノ✿

如果过程有报什么错欢迎在评论区留言!!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有