windows系统下安装theano和keras

本文详细介绍了在Windows 7 64位系统上安装Theano和Keras的步骤,包括所需的基础环境Anaconda3的配置,以及解决安装过程中可能出现的问题。

 学习深度学习也有一段时间了,从在最开始的python安装,到后来的Anaconda3,再到tensorflow,这一路的安装过程就费了很大的劲;虽然网络的相关安装指导也一大堆,但是一到自己动手安装时总会出现这样或那样的错误,导致最后的安装失败。最近,想尝试一下theano框架的深度学习,于是就又安装了theano和keras。以下是记录安装的过程:(本人的环境:Windows7  64位)


鉴于本人的所有相关框架,都是基于Anaconda3进行的,因此首先需要安装Anaconda3,可参考:

Anaconda3安装指导:http://blog.csdn.net/ywx1832990/article/details/78830154


一. mingw 和 libpython安装

按照上面博客中的离线安装,很容易将Anaconda3安装成功。由于Anaconda3中没有MinGW、libpython安装包,因此在安装theano之前我们还需要先安装它们俩:


1. 如果你当前的网速比较好,可以采用在线安装,操作简单;但如果网络不好,就很容易报错。

在线安装时,只需要打开cmd命令行,在命令行中输入:

pip install mingw libpython   或    conda install mingw libpython


如果在线安装不好,也可是在先添加镜像源,再安装;打开cmd命令行,在命令行中输入:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64

conda config --set show_channel_urls yes

执行完上面的命令后,在执行 “Windows键 + r ”,输入“ .condarc ”,再回车“ enter ”,会弹回一个窗口,我的如下:


此时,说明镜像源添加成功,接下来在利用cmd命令行执行以下命令:

pip install mingw libpython   或    conda install mingw libpython


2. 由于在线安装容易出错,因此可以先下载MinGW、libpython安装包,然后离线安装:

MinGW下载地址:https://sourceforge.net/projects/mingw-w64/

libpython下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/

将下载的mingw文件解压后,将其中的MinGW文件拷贝到Anaconda3的文件下面即可;

对于下载的libpython文件,将其拷贝到Anaconda3\Lib\site-packages文件下,然后再在利用cmd命令行切换到该目录下,接着再执行: pip install libpython‑3.4.3‑cp34‑none‑win_amd64.whl


当MinGW和libpython都安装完成后,需要手动设置变量环境 (我的Anaconda3安装在D盘下):

在系统变量的path中添加:D:\Anaconda3\MinGW\bin;D:\Anaconda3\MinGW\x86_64-w64-mingw32\lib;


二. theano安装

在线安装,直接在cmd命令行执行:

pip install theano   或  conda  install  theano


同样的问题,在线安装需要良好的网速,本人选择离线安装,即先下载theano安装包:

theano下载地址:https://github.com/Theano/Theano

下载后将theano.zip进行解压,取出解压后theano-master文件中的子文件夹theano,如下图所示:


将子文件theano复制到 D:\Anaconda3\Lib\site-packages目录下即可。


或者是将解压的theano-master文件拷贝到D:\Anaconda3中,然后利用cmd命令行切换到 D:\Anaconda3\theano-master目录下,并执行:python setup.py install 即可,如下所示:


安装完theano后,需要对其进行环境配置,在系统变量的path中添加:D:\Anaconda3\Lib\site-packages\theano;

然后,再执行 “ Windows键 + r ”,输入“ .theanorc.txt ”,然后回车,就会弹出如下窗口:


按照上面内容修改好,保存关闭。全部完成后,建议重启电脑,然后在cmd命令行中输入python,进入python应用下,输入:import theano ,如果仅显示 ’>>>‘,则说明安装完成。


三. keras安装

在线安装,直接在cmd命令行执行:

pip install keras   或  conda  install  keras


离线安装,先下载keras安装包,下载地址:https://github.com/keras-team/keras

下载后将keras.zip解压,和theano安装类似,将解压后等文件keras-master复制到D:\Anaconda3中,然后利用cmd命令行切换到 D:\Anaconda3\keras-master目录下,并执行:python setup.py install 即可,如下所示:


keras安装完毕后,需要设置操作后端,一般默认后端为TensoeFlow。具体操作:

执行 “ Windows键 + r ”,输入“ .keras ”,然后回车,就会弹出如下窗口:


然后在VS2013(本人安装的13版)打开,显示如下:


其中“ backend ”默认为“ tensorflow ”;此处我已将其改为 “ theano ”,然后保存关闭即可。

建议重启电脑,然后利用cmd命令行进入python界面,并输入:import keras ,显示如下:


到此,所有操作完成。如果有什么建议,欢迎评论!

参考文献:

http://blog.csdn.net/window23/article/details/55105736

http://blog.csdn.net/sxf1061926959/article/details/54094356

http://blog.csdn.net/niuwei22007/article/details/47684673

Deep Learning with Theano by Christopher Bourez English | 31 July 2017 | ISBN: 1786465825 | ASIN: B073ZFBQQJ | 300 Pages | AZW3 | 6.98 MB Develop deep neural networks in Theano with practical code examples for image classification, machine translation, reinforcement agents, or generative models. About This Book Learn Theano basics and evaluate your mathematical expressions faster and in an efficient manner Learn the design patterns of deep neural architectures to build efficient and powerful networks on your datasets Apply your knowledge to concrete fields such as image classification, object detection, chatbots, machine translation, reinforcement agents, or generative models. Who This Book Is For This book is indented to provide a full overview of deep learning. From the beginner in deep learning and artificial intelligence, to the data scientist who wants to become familiar with Theano and its supporting libraries, or have an extended understanding of deep neural nets. Some basic skills in Python programming and computer science will help, as well as skills in elementary algebra and calculus. What You Will Learn Get familiar with Theano and deep learning Provide examples in supervised, unsupervised, generative, or reinforcement learning. Discover the main principles for designing efficient deep learning nets: convolutions, residual connections, and recurrent connections. Use Theano on real-world computer vision datasets, such as for digit classification and image classification. Extend the use of Theano to natural language processing tasks, for chatbots or machine translation Cover artificial intelligence-driven strategies to enable a robot to solve games or learn from an environment Generate synthetic data that looks real with generative modeling Become familiar with Lasagne and Keras, two frameworks built on top of Theano In Detail This book offers a complete overview of Deep Learning with Theano, a Python-based library that makes optimizing numerical expressions and deep learning models easy on CPU or GPU. The book provides some practical code examples that help the beginner understand how easy it is to build complex neural networks, while more experimented data scientists will appreciate the reach of the book, addressing supervised and unsupervised learning, generative models, reinforcement learning in the fields of image recognition, natural language processing, or game strategy. The book also discusses image recognition tasks that range from simple digit recognition, image classification, object localization, image segmentation, to image captioning. Natural language processing examples include text generation, chatbots, machine translation, and question answering. The last example deals with generating random data that looks real and solving games such as in the Open-AI gym. At the end, this book sums up the best -performing nets for each task. While early research results were based on deep stacks of neural layers, in particular, convolutional layers, the book presents the principles that improved the efficiency of these architectures, in order to help the reader build new custom nets. Style and approach It is an easy-to-follow example book that teaches you how to perform fast, efficient computations in Python. Starting with the very basics-NumPy, installing Theano, this book will take you to the smooth journey of implementing Theano for advanced computations for machine learning and deep learning.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值