7
6

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 5 years have passed since last update.

AWSでOpenCV にてCUDAを使えるようにした

Last updated at Posted at 2018-06-18

必要そうな依存関係インストール (EmscriptenでOpenCV使ったことあれば入ってるはず)

compiler

$ sudo apt-get install build-essential

必須

$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

オプション

$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

ソースダウンロード(拡張も好みで入れる)

$ wget https://github.com/opencv/opencv/archive/3.4.1.tar.gz
$ wget -O cont_3.4.1.tar.gz https://github.com/opencv/opencv_contrib/archive/3.4.1.tar.gz

解凍

$ tar -zxvf 3.4.1.tar.gz
$ tar -zxvf cont_3.4.1.tar.gz

移動

$ cd opencv-3.4.1

ビルド用ディレクトリの作成

$ mkdir build 

移動

$ cd build

インストールしたい仮想環境に入っとく

source activate 環境

CUDA連携用設定 もちろんGPU対応数学ライブラリもONにしとく

$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") \
-D PYTHON3_EXECUTABLE=$(which python) \
-D PYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D WITH_CUBLAS=1 \
-D OPENCV_EXTRA_MODULES_PATH="../../opencv_contrib-3.4.1/modules" \
-D PYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..

仮想環境用の設定忘れてビルドしなおしたやつが居るとか(私です)

make

$ make -j $(nproc)

インストール

$ sudo make install

これでOK。
一応確認

$ python
import cv2
print(cv2.getBuildInformation())

こんな感じで出ればOK
image.png

余談
結構ディスク食うので、EBSは大きめの方がいい

参考
http://dlrecord.hatenablog.com/entry/2017/12/15/145356
https://www.pyimagesearch.com/2016/07/11/compiling-opencv-with-cuda-support/
https://dev.widemeadows.de/2017/08/23/building-opencv-for-anaconda-python-3/

7
6
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
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?