要在 Ubuntu 16.04 上跑 char-cnn 這類基於 Torch 的字元級卷積網路實驗,得先把 Torch7 環境搭起來。以下記錄完整流程與過程中碰到的錯誤。
# in a terminal, run the commands curl -sk https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash cd ~/torch; ./install.sh
安裝成功的判斷依據是最後出現這行訊息:
==> Torch7's dependencies have been installed
git clone https://github.com/torch/distro.git ~/torch --recursive cd ~/torch; ./install.sh
問題一:找不到 cmake
./install.sh: line 59: cmake: command not found
顧名思義就是 cmake 沒裝,補上即可:
sudo apt install cmake
裝好後回到 cd ~/torch; ./install.sh 繼續。
問題二:子模組 clone 失敗
error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received. fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed fatal: clone of 'https://github.com/torch/cutorch.git' into submodule path 'extra/cutorch' failed
這類錯誤多半是網路因素。切到 Torch 的安裝目錄重新 clone:
git clone https://github.com/torch/distro.git ~/torch --recursive
反覆重試直到成功,再回到 cd ~/torch; ./install.sh。
編譯完成後,讓安裝過程中被修改的 PATH 生效:
source ~/.bashrc
接著輸入 th 驗證:
看到上圖那樣的互動式 Lua 提示,就代表 Torch 裝好了。
若不再需要,直接刪除目錄即可:
rm -rf ~/torch
之後要安裝其他 Torch 套件,則改用 luarocks:
$ luarocks install image $ luarocks list
$ luarocks install nngraph $ luarocks install optim
這兩個套件搞定,char-cnn 的執行環境就完整了,接著即可下載專案原始碼開始訓練。