您的位置:首页 > 其它

深度学习算法实践1---开发环境搭建

2017-04-21 16:09 405 查看
本文将在Mac环境下,配置深度学习算法的开发环境,我们会采用python3.x作为开发语言,在深度学习框架方面,没有选择最为流行的TensorFlow,而是在研究者中比较流行的Theano。主要是因为TensorFlow虽然很热,但是将基础理论与框架结合的文档较少,Theano作为教学框架,这方面的资料非常丰富,所以以学习和实现为目的的项目,采用Theano会有较大的优势。而我们知道,目前深度学习的应用,大多是试验性质的,因此采用Theano可以在学习深度学习基本理论的同时,动手实验各种算法,对实际项目的帮助应该更大一些。

虽然Theano推荐的开发环境是64位Linux,但是在Mac下配置起来也是非常简单的。

首先安装Python开发环境,其实Mac自带了python 2.7.x的python系统,但是本人更喜欢python 3.x系统,因此我们还是要自己安装python
3.x系统。直接运行如下命令即可:

[plain] view
plain copy

 





sudo brew install python3  

sudo pip install bumpy scipy  

[plain] view
plain copy

 





sudo pip install nose  

但是需要注意,以后再启动python需要使用如下命令:python3,否则启动的将是系统内置的python 2.7.x。

因为需要与Theano项目组一起工作,所以我们必须符合他们代码规范。我们就需要下载Vim的插件。先运行如下命令:

[plain] view
plain copy

 





sudo pip3 install fake8  

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim  

编辑~/.vimrc文件,将下列内容添加到文件中:

[plain] view
plain copy

 





set nocompatible              " be iMproved, required  

filetype off                  " required  

" set the runtime path to include Vundle and initialize  

set rtp+=~/.vim/bundle/Vundle.vim  

call vundle#begin()  

  

Plugin 'gmarik/Vundle.vim' " let Vundle manage Vundle (required!)  

Plugin 'scrooloose/syntastic'  

Plugin 'jimf/vim-pep8-text-width'  

  

" Syntastic settings  

" You can run checkers explicitly by calling :SyntasticCheck <checker  

let g:syntastic_python_checkers = ['flake8'] "use one of the following checkers:  

                                             " flake8, pyflakes, pylint, python (native checker)  

let g:syntastic_enable_highlighting = 1  "highlight errors and warnings  

let g:syntastic_style_error_symbol = ">>" "error symbol  

let g:syntastic_warning_symbol = ">>" "warning symbol  

let g:syntastic_check_on_open = 1  

let g:syntastic_auto_jump = 0  "do not jump to errors when detected  

下面需要进行Vim插件安装,运行:vim,进入vim后,在命令模式下,执行   :PluginInstall

完成以上步聚后,就可以开始下载Theano源码了。但是Theano源码在Github上,需要采用Git获取,而公司项目也有可能使用Git,多数情况下,你的Github账号与公司项目有所不同,因此就需要为Github建立单独的公钥和私钥文件。

运行:ssh-keygen -t rsa -C "your_git_hub_eamil@aaa.com",在输入文件名处,输入~/.ssh/id_rsa_github,其他可以取缺省设置。

运行:ssh-add ~/.ssh/id_rsa_github

将Github加入到已知主机列表:ssh -T git@github.com

登录Theano在Github上的主页,先Fork该项目,此时Github会在你自己的Github下创建Theano项目,以我的为例就是https://github.com/yt7589/Theano。

进入你自己的Github主页,以我为例是https://github.com/yt7589,点击Edit Profile,然后选择SSH and GPG keys,然后点击添加按钮,将~/.ssh/id_rsa_github.pub文件中的内容拷贝到Key中。

下面开始正式下载Theano源码,运行命令:

sudo git clone git@github.com:yt7589/Theano.git

sudo git remote add central git://github.com/Theano/Theano.git

我们需要与Theano项目进行合作,因此需要与其进行关联:

git fetch central

git branch trunk central/master

接下来我们获取最新的源码:

git checkout trunk

git pull

全部代码下载完成之后,我们需要安装源码。进入到Theano源码目录,运行:sudo python3 setup.py develop。

然后运行sudo python3,在python3下输入:

import theano

theano.test()

这些将执行Theano所有测试用例,会花费很长时间,需要耐心等待。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: