环境!Anaconda3配置Spyder3.6及TensorFlow,keras和相关库

在Anaconda3(Python3.7)的官方版本下,配置另一个环境python3.6
本机系统:WIN10
PS:本系统已装了cuda9了,这里就不教学了,
参考官网https://developer.nvidia.com/cuda-downloads(CUDA)

为什么需要配置python3.6?

在使用机器学习中,TensorFlow(下面简称:TF)是不可或缺的一项工具,而TF需要对应的python版本,因此在Anaconda3已推出的python3.7的时候,我们的TF依旧不能及时支持,需要回调到python3.6的版本。
在这里插入图片描述
在这里插入图片描述
参考官网:https://tensorflow.google.cn/install/source_windows(Tensorflow的官网)

下载和安装最新的Anaconda

在这里插入图片描述
目前,最新的是2018.12更新的python3.7,直接选择下载

在这里插入图片描述
跟着步骤,第一次的,也要安装与喜爱VS code
参考官网:https://www.anaconda.com/distribution/

配置python3.6

开始菜单栏——选择Anaconda——打开Anaconda Navigator
在这里插入图片描述
选择Packages,这次我们是要选择Python3.6
在这里插入图片描述
点击Create就可以自动创建了

下载spyder(3.6)

开始菜单栏——选择Anaconda——打开Anaconda Prompt
(此时的命令基本以conda为首)
运行命令:activate python3.6
此命令为运行python3.6的环境,然后在此命令下说安装的东西会直接在python3.6中
在这里插入图片描述
出现(python3.6)即为成功
然后,下载spyder
运行命令:conda install spyder
回复:Y
等待安装过程
在这里插入图片描述
这边说一下为什么选择spyder,
笔者之前是使用过matlab,可惜matlab的机器学习环境并不是很好,因而转战python。在数据可视化方面,spyder的可视化和习惯几乎和matlab相同,可以直接看到参数变量,是比较方面和直观的。

安装完成。
看看菜单栏,有spyder(python3.6)即可(spyder 3.3.1)
在这里插入图片描述

库的安装

注意:库的安装都在python3.6的环境下
ps:以后需要啥包,pip install xxx即可。
比如需要numpy,则pip install numpy
需要pandas,则pip install pandas
查看安装了什么库: pip list
在这里插入图片描述
GPU-版本
numpy
tensorflow-gpu
scipy
PyYAML
keras
html5lib
Pillow
scikit-image
注意:留意您的tensorflow-GPU版本,笔者下载的是TensorFlow-gpu==1.12
在Anaconda Prompt (python3.6)下输入

import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

查看有没有使用到GPU

打开spyder。
在左侧的代码框中输入如下代码:

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print (sess.run(hello))

如果右侧的仿真输出窗口顺利输出:
‘Hello, Tensorflow!’
那就代表Tensorflow安装成功。

在命令行中依次输入如下命令:

conda install git # 安装git工具
git clone https://github.com/fchollet/keras.git #下载工程内容
cd keras/examples/  #进入代码路径
python mnist_mlp.py  #用python运行程序

然后就会发现正在运行程序,是典型的机器学习入门的例子,识别手写数字。
总共训练二十次。
每次都会输出误差及准确率。
完成20次训练后,进行test,再给出test的误差及准确率。
到此,keras验证完毕。
bingo!!!

参考博客:https://blog.csdn.net/evolone/article/details/79072714

猜你喜欢

转载自blog.csdn.net/qq_42321818/article/details/88953489