torch的安裝 DenseCap依賴的庫
轉載請註明出處:
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),如nn和dpnn
說明:安裝先安裝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
torch的安裝 DenseCap依賴的庫