LoginSignup
9
18

More than 5 years have passed since last update.

MacへのCSLAIERインストールの方法(CUDA/OpenCV含む)

Posted at

この記事はMacでのChainerインストールに必要なものの説明とまとめの続きの記事です。

目次

1.筆者の開発環境
2.インストールするもの
3.CUDAのインストール
4.OpenCVのインストール
5.CSLAIERのインストール

筆者の開発環境

・MacBook Pro (Retina, 13inch, Early 2015)
・macOS Sierra (バージョン 10.12.2)
・プロセッサ (2.7 GHz Intel Core i5)
・メモリ (8 GB 1867 MHz DDR3)
・グラフィックス (Intel Iris Graphics 6100 1536 MB)

・Homebrew、pyenv、anaconda2-4.2.0/anaconda3-4.2.0(anacondaの中にNumpy、Six、Pillow)、Chainerはインストールされている前提です。もしインストールされいない方、インストールしてあるかわからない方は、MacでのChainerインストールに必要なものの説明とまとめを読んでみてください。

インストールするもの

この記事でインストールするものは、

・CUDA
・OpenCV
・CSLAIER

の3つです。

CUDAのインストール

それでは最初にCUDAをインストールしていきましょう。CUDAについての詳しい説明は、前回の記事をご覧ください。

CUDAは、このサイトからダウンロードすることができます。

DOWNLOADボタンを押すと、ダウンロード画面に行きます。
Select Target Platformの欄から、

Mac OSX を選択

Version 10.12 を選択し、
(自分のMacのバージョンに合わせてください。筆者のMacはバージョン 10.12.2なので10.12)

InstallerType dmg(local) を選択し、

Download(1.4GB) を押すとダウンロードがはじまります。
ダウンロードが終わったら、ダウンロードしたパッケージを開いて自分のマックのアプリケーションに追加します。

次に環境変数を通します(環境変数/.bash_profile/viコマンドについてわからない方はこの記事をお読みください)。この時に変更するファイルは前回までに使っていた、.bash_profileだけではなく、.bashrcにも変更を加えます。

.bash_profileはログイン時に1度だけ読み込まれ、.bashrcはbashを起動するたびに読み込まれます(両者の違いについては下記記事が詳しいです)。

「ユーザーの環境変数を設定するbashの設定ファイルと、カスタムプロンプトについて」
http://oxynotes.com/?p=5418#3

初期状態では、.bashrcファイルは存在しないためviコマンドで作成します。

.bashrc作成のコマンド、ホームディレクトリにて実行
$ vi .bashrc

作成した、.bashrcに環境変数を通します。.bashrcファイルを開いて、下記の通りに入力すれば大丈夫です。

.bashrcへの環境変数の追加
export PATH=/Developer/NVIDIA/CUDA-8.0/bin:$PATH
export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-7.5/lib:$DYLD_LIBRARY_PATH

最後に新しく作成した、.bashrcが、.bash_profileから読み込まれるように.bash_profileに変更を加えます。下記の通りに追加しましょう。書き加える場所はどこでも大丈夫です。

.bash_profileへの書き込み
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

「Mac(OSX)で.bashrcを編集する」
https://gist.github.com/disktnk/4104284

これでCUDAのインストールは終わりです。

OpenCVのインストール

次にOpenCVをインストールしていきます。
OpenCVは、画像や動画処理に必要ないろいろな機能が実装されているオープンソースのライブラリです。

「OpenCV入門【3.0対応】(1)」
http://www.buildinsider.net/small/opencv/001

OpenCVは、OpenCV2とOpenCV3があります。
この記事では、OpenCV2のインストール方法を説明していきます(現在使用しているpythonのバージョンが2系で、OpenCV3はpython3系でしか使うことができないためです)。
しかし、OpenCV3もインストール方法はほとんど変わりません。それでは早速OpenCV2をインストールしてみましょう。

まずは、Homebrewをアップデートします。

Homebrewを最新のバージョンにする
$ brew update
$ brew install -v cmake

次にTapを行います。これを行うことによって、Homebrewでもコンピュータサイエンス向けのライブラリ(OpenCVとか)をインストールできるようになります。

「これは便利!Homebrewに追加されたtapコマンドはリポジトリを追加して簡単にフォーミュラを増やせる」
http://tukaikta.blog135.fc2.com/blog-entry-204.html

$ brew tap homebrew/science

次に、OpenCVをインストールします。

OpenCVのインストール
$ brew install opencv

OpenCVをインストールするのに必要なものは、下記のコマンドを実行することで、見ることができます。もし、エラーが出てインストールできなかった場合は、実行してみてください。

OpenCVをインストールするために必要なものの情報
$ brew info opencv

homebrew/science/opencv: stable 2.4.13.2 (bottled), HEAD
Open source computer vision library
http://opencv.org/
/usr/local/Cellar/opencv/2.4.13.2 (278 files, 35.6M) *
Poured from bottle on 2016-12-24 at 10:52:11
From: https://github.com/Homebrew/homebrew-science/blob/master/opencv.rb
==> Dependencies
Build: cmake ✔, pkg-config ✔
Required: jpeg ✔, libpng ✔, libtiff ✔
Recommended: eigen ✔, openexr ✔, homebrew/python/numpy ✔
Optional: jasper ✘, gstreamer ✘, libdc1394 ✘, openni ✘, tbb ✔, vtk ✘, ffmpeg ✔
==> Requirements
Optional: cuda ✔, java ✔
==> Options
--c++11
Build using C++11 mode
--universal
Build a universal binary
--with-cuda
Build with cuda support
--with-ffmpeg
Build with ffmpeg support
--with-gstreamer
Build with gstreamer support
--with-jasper
Build with jasper support
--with-java
Build with Java support
--with-libdc1394
Build with libdc1394 support
--with-opengl
Build with OpenGL support
--with-openni
Build with openni support
--with-tbb
Enable parallel code in OpenCV using Intel TBB
--with-vtk
Build with vtk support
--with-ximea
Build with XIMEA support
--without-eigen
Build without eigen support
--without-numpy
Use your own numpy instead of Homebrew's numpy
--without-opencl
Disable GPU code in OpenCV using OpenCL
--without-openexr
Build without openexr support
--without-python
Build without python support
--without-test
Build without accuracy and performance tests
--HEAD
Install HEAD version
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/yuya/.local/lib/python2.7/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/yuya/.local/lib/python2.7/site-packages/homebrew.pth

筆者の場合は、このように表示されます。
この表示の、チェックがついているものがインストール済みで、✖️がついているものがインストールしていないものです。
Optional以外のものはインストールされていないと、エラーになるかもしれません。

また、MacのOSがSierraだとエラーになる可能性があります。もしエラーになったら、インストールコマンドを変更してください。

変更後のインストールコマンド
$ brew install opencv --HEAD

「macOS Sierra でOpenCVがインストールできない」
http://qiita.com/tellusium/items/57c829a1afb6b64ec65b

無事にインストールできたら、.bash_profileに環境変数を通します。

OpenCVを環境変数に通す
export PYTHONPATH="/usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/:$PYTHONPATH"

python2.7のところは自分が使用しているpythonのバージョンを書いてください。

多くのサイトには、

brew link opencv3 --force

でリンクを通すと書いてあるのですが、筆者はこれではうまくいきませんでした。

import cv2 と記入して、エラーにならなければ成功です。

OpenCVがインストールできたかの確認
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:43:17) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
>>> 

CSLAIERのインストール

CSLAIERは、GUIで深層学習を行うことができるブラウザベースのツールです。

ソースコードをダウンロードして、
https://github.com/SonyCSL/CSLAIER

ターミナルで、ダウンロードしたファイルのあるディレクトリに移動して、入力します。

CSLAIERの実行コマンド
$ ./setup.sh
$ pip install -r requirements.txt
$ ./run.sh

./run.shがうまくいけば、http://localhost:8080に、アクセスすることでCSLAIERを使うことができます。

うまくいかなかった点等、コメントして頂ければ幸いです。
次回は、TensorFlowのインストールをしてみたいと思います。

9
18
4

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
9
18