DL学习笔记【14】Mac10.11.6+torch7+itorch

来源:互联网 发布:在淘宝上买吃的靠谱吗 编辑:程序博客网 时间:2024/05/04 08:55

Mac创建虚拟环境再安装会使各个框架或者程序的安装包比较独立,互不影响,很实用,来一个教程:

http://www.marinamele.com/2014/05/install-python-virtualenv-virtualenvwrapper-mavericks.html


特别提醒一句:安装过程中输入一个语句然后回车,过了几秒没反应不要着急,也不要输入别的,就等一会儿就好啦。

xcode7.3.1,没装cuda


本来以为这是无脑安装,今天重装了个系统发现,以下安装过程是需要带着脑子的:

安装的4个步骤参考:http://blog.rainy.im/2016/01/02/lua-and-torch7-on-jupyter/,具体方法稍有修改

1. 安装 torch 

参考:http://torch.ch/docs/getting-started.html

下边安装的语句中.profile这个文件名字必须一模一样(原因不详)

我的电脑没有,所以要自己先建一个。这个文件一定要先建好,否则运行后边的语句就不能自动写入一句话(. /Users/Ruoqi/torch/install/bin/torch-activate)

vim ~/.profile

然后里边随便写点什么,比如一个空格,然后shift+双击z保存退出就算是新建这个文件夹了,可以用ls -a查看一下

之后运行的时候如果出现

error: your user does not have write permissions in /usr/local/

--you may want to run as a privileged user or use your local tree with --local

就用下边的方法修改一下文件夹/usr/local/的权限

1. cd你的文件夹路径的上一级目录。 

2. sudo chmod -R 777 你的文件夹名。 (777是指可以读写等,就是权限扩大啦)

3. 输入密码。 

4.成功。


下边的语句依次放到terminal中运行,要下很多库,可能得等半个多小时吧

git clone https://github.com/torch/distro.git ~/torch --recursivecd ~/torch/bash install-deps./install.shsource ~/.profile luarocks install imageluarocks list

(选)安装lua--因为我安装之后显示没有lua,所以要重新自己安装:

brew install lua --with-completion

测试一下:

如果出现下边的情况那就没问题了

$th  ------一堆符号-------th>

退出方法:

ctrl+c 两次 或者 os.exit()

提醒:

每次开启terminal想要运行torch的时候都要先输入下边这句话,算是激活torch吧:

source ~/.profile


2. 安装 jupyter

毕竟每次都用命令行来运行确实比较麻烦,所以,我们需要一个编辑器

我之前安装过anaconda2,所以已经有了jupyter,因此这一步还是需要再查查咯

网址: https://www.continuum.io/downloads


3. 安装 itorch 

参考:https://github.com/facebook/iTorch

我也不知道jupyter是不是ok哈,只是按照步骤,直接安装了,无脑安装过程如下:

以下语句均在terminal中运行

brew install zeromqbrew install opensslluarocks install luacrypto OPENSSL_DIR=/usr/local/opt/openssl/git clone https://github.com/facebook/iTorch.gitcd iTorchluarocks make #安装完成luarocks list #查看都安装了哪些包

启动:
itorch notebook 

如果提示没有ipython,就运行:

pip install ipython

如果提示找不到notebook,再运行:

pip install ipython[notebook]

测试语句:

require ‘nn’

会有一堆out...但是没有error就对啦

如果后边加了 ;  就不会有输出啦,如:

require ‘nn’;


4. 其实安装完上边那些已经可以用了~但是不知道这个教程为什么还有下边这个步骤,如果不放心,也可以一起无脑到底:

ls ~/.jupyter  # 如果没有 jupyter_notebook_config.py 则执行jupyter notebook --generate-configIPython#下边这两句是在ipython中输入的from notebook.auth import passed  passwd('mypassword')  # 这个是你电脑的output,例子:Output => 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'# 去掉 c.NotebookApp.password 注释c.NotebookApp.password =u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'  c.NotebookApp.ip ='*'  #前边都无公害,但是下边这句明显是不让用浏览器啊,加上了就神马也弹不出来了,不知道神马作用,我就给注释了,然后运行没问题c.NotebookApp.open_browser =False


问题:

如果运行模型的时候需要加载caffe模型&缺少hdf5之类的文件,可能会用到下边这几句话

brew install gcc48
brew install protobuf
luarocks install loadcaffeluarocks install hdf5

如果使用类似qlua run_trans.lua这样的语句,而报错没有qlua的话,就可以在terminal中运行下边的语句进行安装。如果显示Found unsuitable Qt version 5.6.2 from ...而不是版本4之类的。那就去相应文件夹下(我的是:/Users/Ruoqi/anaconda2/bin/)把qmake文件取出来,安装之后再复制回去。 下边的语句如果安装不成功,可能需要 sudo

luarocks install qtlua

如果想要运行.sh文件,直接拖入终端即可


在安装过程中可能会遇到需要显示隐藏文件的情况,比如编辑.profile文件时,我觉得图形界面更直观

在终端中执行如下代码并重启动Finder。

显示隐藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool TRUE

停止显示隐藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool FALSE

 

注:重启Finder的方法:

按住option+command,dock上右键->“Relanch”/“重新开启”。


出自:

https://github.com/karpathy/neuraltalk2/issues/10

安装clnn

https://github.com/hughperkins/distro-cl

torch7 可以调用caffe模型,像Matlab一样

下边这个是安装了caffe版

https://github.com/szagoruyko/torch-caffe-binding  

下边这个是不必安装caffe版

https://github.com/szagoruyko/loadcaffe


安装完了还得会用是吧

可以先看看lua教程,了解这个语言的特点,对于学习torch很有帮助:

http://www.jellythink.com/archives/882

顺手再来几个帅气的torch教程~

https://github.com/soumith/cvpr2015/blob/master/Deep%20Learning%20with%20Torch.ipynb


http://blog.csdn.net/u010946556/article/details/51329208 这个应该是入门级的

https://github.com/torch/torch7/wiki/Cheatsheet 这个应该是最全的

https://www.cs.ox.ac.uk/people/nando.defreitas/machinelearning/practicals/practical1.pdf 这个课件里边的lua和torch教程很好


感觉下边的教程更好一些,比较全比较系统

torch教程

https://github.com/torch/torch7/tree/master/doc

nn 教程

https://github.com/torch/nn/tree/master/doc


有关损失函数的文章

http://blog.csdn.net/zr459927180/article/details/50750736




1 0