1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【 Macbook環境 】luarocks install torchを実行して、Error: No results matching queryが出たら、github.com/torch/distro.gitから入れてみよう

Last updated at Posted at 2021-08-08

画像ファイルを与えると、AIモデルが認識できた人や物体(オブジェクト)に、それがなんの物体なのかを、短い語句(英文)を添えて表示してくれる__DenseCap__というモデルが提案されています。

画像の内容を説明する文を自動で返してくれるAIは、AI界隈では、「画像キャプション文の自動生成」AIと呼ばれています。
このAIモデルの実装コードが、GitHubに上がっています。Lua言語で書かれています。

今回、このDense Capを動かすために、MacbookでLua環境を構築しようと試みたところ、なぜか__luarocks install torch__が、そのライブラリは見つからないエラーで、前に進めなくなりました。(Lua本体とluarocksは、Macbookにすでに入れてあります)

Error: No results matching query were found for Lua 5.4

調べたところ、次のサイトに助けられました。

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

上にある5行のコードを写経して実行したところ、Macbookにtorchが入りました。
なお、DenseCapとは別のNeural StyleモデルのLua実装コードを動かそうとしている次のサイトでも、同じ方法でMacにtorchを入れていました。

neural-styleは画像をDeep Learningでピカソ風にしたりとかのやつ。 Torch7,loadcaffeが必要だ。

thコマンドはTorch7のコマンドだ。

なお、上のサイトでは、__--recursive torch__をつけて、関連するライブラリをまとめて入れているようです。

clone https://github.com/torch/distro.git --recursive torch
のようにtorchフォルダを指定するのがいい。 recursiveはサブモジュールもインストールするオプション。

なお、DenseCapのGitHubリポジトリでは、事前準備として、次のライブラリを、Luaのパッケージ管理ツール Luarocksを使って入れなさい、と書いてありました。
__torch以外は、すべてluarocks install__ですんなり入りました。

luarocks install torch
luarocks install nn
luarocks install image
luarocks install lua-cjson 
luarocks install https://raw.githubusercontent.com/qassemoquab/stnbhwd/master/stnbhwd-
scm-1.rockspec
luarocks install https://raw.githubusercontent.com/jcjohnson/torch-rnn/master/torch-rnn-scm-1.rockspec

また、今回使う計算機は、GPUを積んでいないMacbookですので、__(Optional) GPU acceleration__と書いてある欄の次のライブラリ入れる必要はないのですが、luarocks install ですべて入りました。

Terminal
luarocks install cutorch
luarocks install cunn
luarocks install cudnn
luarocks install cudnn

ここで、torchが入った後に、__luarocks install torchを再度打ったところ、うまく動きました。笑
GitHubからでもなんでも、一度torchを入れさえすれば、そのあとは
luarocks install torch__で入れ直すことはできる、ということなのだろうか。。

Terminal
 % luarocks install torch 
Installing https://raw.githubusercontent.com/torch/rocks/master/torch-scm-1.rockspec...
Using https://raw.githubusercontent.com/torch/rocks/master/torch-scm-1.rockspec... switching to 'build' mode
Cloning into 'torch7'...
remote: Enumerating objects: 181, done.
remote: Counting objects: 100% (181/181), done.
remote: Compressing objects: 100% (174/174), done.
remote: Total 181 (delta 8), reused 55 (delta 5), pack-reused 0
Receiving objects: 100% (181/181), 335.48 KiB | 775.00 KiB/s, done.
Resolving deltas: 100% (8/8), done.
Warning: unmatched variable LUALIB

( 省略 )

-- Performing Test CXX_HAS_SSE3_1 - Success
-- Performing Test CXX_HAS_SSE4_1_1
-- Performing Test CXX_HAS_SSE4_1_1 - Success
-- Performing Test CXX_HAS_SSE4_2_1

( 省略 )

-- Generating done
-- Build files have been written to: /tmp/luarocks_torch-scm-1-1246/torch7/build
[  2%] Building C object lib/luaT/CMakeFiles/luaT.dir/luaT.c.o
[  5%] Linking C shared library libluaT.dylib
[  5%] Built target luaT
[  7%] Building C object lib/TH/CMakeFiles/TH.dir/THGeneral.c.o
[ 10%] Building C object lib/TH/CMakeFiles/TH.dir/THHalf.c.o
[ 12%] Building C object lib/TH/CMakeFiles/TH.dir/THAllocator.c.o

( 省略 )

[ 89%] Building C object CMakeFiles/torch.dir/TensorOperator.c.o
[ 92%] Building C object CMakeFiles/torch.dir/TensorMath.c.o
[ 94%] Building C object CMakeFiles/torch.dir/random.c.o
[ 97%] Building C object CMakeFiles/torch.dir/Generator.c.o
[100%] Linking C shared module libtorch.so
[100%] Built target torch
cd build && make install
Consolidate compiler generated dependencies of target luaT
[  5%] Built target luaT
Consolidate compiler generated dependencies of target TH
[ 58%] Built target TH
Consolidate compiler generated dependencies of target torch
[100%] Built target torch
Install the project...
-- Install configuration: "Release"
-- Installing: /Users/electron/torch/install/share/cmake/torch/TorchExports.cmake
-- Installing: /Users/electron/torch/install/share/cmake/torch/TorchExports-release.cmake
-- Installing: /Users/electron/torch/install/share/cmake/torch/TorchConfig.cmake
-- Installing: /Users/electron/torch/install/share/cmake/torch/TorchWrap.cmake

-- Installing: /Users/electron/torch/install/include/TH/generic/THTensorMath.h
-- Installing: /Users/electron/torch/install/include/TH/generic/THTensorRandom.c
-- Installing: /Users/electron/torch/install/include/TH/generic/THTensorRandom.h
-- Installing: /Users/electron/torch/install/include/TH/generic/THVectorDispatch.c
-- Installing: /Users/electron/torch/install/include/TH/generic/THVector.h
-- Installing: /Users/electron/torch/install/share/cmake/torch/THConfig.cmake
-- Installing: /Users/electron/torch/install/lib/libluaT.0.dylib
-- Up-to-date: /Users/electron/torch/install/lib/libluaT.dylib
-- Installing: /Users/electron/torch/install/include/luaT.h
-- Installing: /Users/electron/torch/install/share/cmake/torch/luaTConfig.cmake
Updating manifest for /Users/electron/torch/install/lib/luarocks/rocks
torch scm-1 is now built and installed in /Users/ocean/torch/install/ (license: BSD)

%

関連

DenseCapには、Caffe実装もあります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?