(原)ubuntu上安装Torch7及nn及dpnn

转载请注明出处:

http://www.cnblogs.com/darkknightzh/p/5653864.html

参考网址:

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

http://deepdish.io/2015/02/20/local-torch-installation/

160714说明:如果需要使用torch及GraphicsMagick并读取jpg图像的话,最好先安装libjpeg的库,然后在安装GraphicsMagick,最后再安装torch。

因为刚才GraphicsMagick调用jpeg没有错误,但是torch里面的某个模块又提示找不到libjpeg.so的库了,之后只能先强制卸载image包:luarocks remove image --force,再重新luarocks install image。之后正常了。。。

1. 先安装luarocks

sudo apt-get install luarocks

2. 安装torch

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

1) 终端中输入:

git clone https://github.com/torch/distro.git ~/torch --recursive 
cd ~/torch; bash install-deps;
./install.sh

说明: ~/torch应该就是终端当前所在的文件夹(默认时为/home/XXX/,加了~/torch后就变成了/home/XXX/torch

2) 将torch添加到PATH中

source ~/.bashrc

160713说明:今天在另一台电脑上安装了torch7和ZeroBrane,启动ZeroBrane后,程序第一句require 'image'就错误,提示找不到image包。后来网上搜了一下,也有人遇到了这个问题。主要就是环境变量

http://deepdish.io/2015/02/20/local-torch-installation/说了,可以将以下语句加入到~/.bashrc中:

export TORCH_DIR=$HOME/torch
export LUA_PATH="$TORCH_DIR/install/share/lua/5.1/?.lua;$TORCH_DIR/install/share/lua/5.1/?/init.lua;$TORCH_DIR/install/share/luajit-2.1.0-alpha/?.lua"
export LUA_CPATH="$TORCH_DIR/install/lib/lua/5.1/?.so"

自己发现,执行完source ~/.bashrc后,~/.bashrc中多了一条语句:

. /home/XXX/program/torch/install/bin/torch-activate

这条语句中torch-activate就是包含torch安装的库目录的文件。然后重启电脑,再使用ZeroBrane的话,就不会提示找不到image包了。。。

由于没有重启电脑,害的我卸了torch又重新装了几次。。。哎。。。

现在感觉,如果再碰到这个问题,实在不行的话,就自己手动把torch-activate文件的路径加到.bashrc中,然后重启电脑试试。不行的话,额,不行再想办法吧。。。

3) 如果需要的话,卸载torch

rm -rf ~/torch

说明:上面安装的是torch和LuaJIT,如果希望安装torch和Lua5.2,而不是LuaJIT,则:

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch

# clean old torch installation
./clean.sh
# optional clean command (for older torch versions)
# curl -s https://raw.githubusercontent.com/torch/ezinstall/master/clean-old.sh | bash

# https://github.com/torch/distro : set env to use lua
TORCH_LUA_VERSION=LUA52 ./install.sh

5) 安装完torch后输入th:

3. 安装torch的包(packages),如nndpnn

说明:安装先安装nn,再安装dpnn

1) 下载nn和dpnn:

https://github.com/torch/nn

https://github.com/nicholas-leonard/dpnn

2) 解压这两个文件夹。

3) 终端中cd到这两个文件夹上一级目录。

4) 使用luarocks install命令进行安装

luarocks install nn-master/rocks/nn-scm-1.rockspec
luarocks install dpnn-master/rocks/dpnn-scm-1.rockspec

说明:① 官网中说直接使用命令luarocks install dpnn进行安装,但是会提示:

No results matching query were found

② nn和dpnn都有依赖的包,需要先安装好。具体都有啥,忘了。。。不过dpnn依赖的比nn多。

③ 官网说可以使用Luarocks在终端中安装packages,比如:

luarocks install image

但是如果安装失败的话,就按照3中①-④的步骤,先下载下来,然后再安装。。。

④ 查看都安装了哪些包:

luarocks list
原文地址:https://www.cnblogs.com/darkknightzh/p/5653864.html