CORDEA blog

Android applications engineer

docker上のUbuntu 14.04にcaffeをinstall

Caffe

Caffeはディープラーニングのフレームワークです。


BVLC/caffe · GitHub


はじめに

今回はDocker上のUbuntuにCaffeをinstallします。
GPUが絡むと面倒なので、今回はCPUモードで使用します。
また、Pythonで使用するための設定やインストールは行いません。
そちらは本家のInstallationを参考にして下さい。

  • 2015/01/26 追記

 CaffeのPython wrapperを使用するための手順を追記したものをQiitaに投稿しました。
 Pythonで使用される方はそちらをご覧ください。

Version

  • Docker version 1.3.2, build 39fa2fa/1.3.2

手順

ユーザーの作成

行わなくても問題ありません

% docker run -it --name="caffe" ubuntu /bin/bash
root@4536d063fc8a:/# adduser --disabled-password --gecos '' cordea
root@4536d063fc8a:/# adduser cordea sudo
root@4536d063fc8a:/# echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers


 

installとか

root@4536d063fc8a:/# su cordea
cordea@4536d063fc8a:/$ cd home/cordea/
cordea@4536d063fc8a:~$ sudo apt-get update
cordea@4536d063fc8a:~$ sudo apt-get install git vim wget make bc libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libblas-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
cordea@4536d063fc8a:~$ mkdir caffe
cordea@4536d063fc8a:~$ cd caffe/


 

CUDA

CPUモードではGraphics Driverは必要ありませんが、CUDA Toolkitは必要なようなのでToolkitだけinstallします。

cordea@4536d063fc8a:~/caffe$ wget http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.14_linux_64.run
cordea@4536d063fc8a:~/caffe$ chmod u+x cuda_6.5.14_linux_64.run 
cordea@4536d063fc8a:~/caffe$ ./cuda_6.5.14_linux_64.run 
Do you accept the previously read EULA? (accept/decline/quit): accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 340.29? ((y)es/(n)o/(q)uit): n
Install the CUDA 6.5 Toolkit? ((y)es/(n)o/(q)uit): y
Enter Toolkit Location [ default is /usr/local/cuda-6.5 ]: 
/usr/local/cuda-6.5 is not writable.
Do you wish to run the installation with 'sudo'? ((y)es/(n)o): y
Do you want to install a symbolic link at /usr/local/cuda? ((y)es/(n)o/(q)uit): y
Install the CUDA 6.5 Samples? ((y)es/(n)o/(q)uit): n
Installing the CUDA Toolkit in /usr/local/cuda-6.5 ...

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-6.5
Samples:  Not Selected

cordea@4536d063fc8a:~/caffe$ sudo ldconfig /usr/local/cuda-6.5/lib64/


 

makeとか

runtestでerrorが出るのはGPUが無いからだ...と思います

cordea@4536d063fc8a:~/caffe$ git clone https://github.com/BVLC/caffe
cordea@4536d063fc8a:~/caffe$ cd caffe/
cordea@4536d063fc8a:~/caffe/caffe$ cp Makefile.config.example Makefile.config         
cordea@4536d063fc8a:~/caffe/caffe$ make all
cordea@4536d063fc8a:~/caffe/caffe$ make test
cordea@4536d063fc8a:~/caffe/caffe$ make runtest
.build_release/test/test_all.testbin 0 --gtest_shuffle
libdc1394 error: Failed to initialize libdc1394
Cuda number of devices: 0
Setting to use device 0
Current device id: 0
Note: Randomizing tests' orders with a seed of 65626 .
[==========] Running 838 tests from 169 test cases.
[----------] Global test environment set-up.
[----------] 7 tests from SyncedMemoryTest
[ RUN      ] SyncedMemoryTest.TestInitialization
[       OK ] SyncedMemoryTest.TestInitialization (0 ms)
[ RUN      ] SyncedMemoryTest.TestAllocationCPU
[       OK ] SyncedMemoryTest.TestAllocationCPU (0 ms)
[ RUN      ] SyncedMemoryTest.TestCPUWrite
[       OK ] SyncedMemoryTest.TestCPUWrite (0 ms)
[ RUN      ] SyncedMemoryTest.TestGPUWrite
F0120 07:23:59.559131 31252 syncedmem.cpp:51] Check failed: error == cudaSuccess (35 vs. 0)  CUDA driver version is insufficient for CUDA runtime version
*** Check failure stack trace: ***
    @     0x2b0c0e68ddaa  (unknown)
    @     0x2b0c0e68dce4  (unknown)
    @     0x2b0c0e68d6e6  (unknown)
    @     0x2b0c0e690687  (unknown)
    @           0x70090b  caffe::SyncedMemory::mutable_gpu_data()
    @           0x5bf8ad  caffe::SyncedMemoryTest_TestGPUWrite_Test::TestBody()
    @           0x65a883  testing::internal::HandleExceptionsInMethodIfSupported<>()
    @           0x651327  testing::Test::Run()
    @           0x6513ce  testing::TestInfo::Run()
    @           0x6514d5  testing::TestCase::Run()
    @           0x654818  testing::internal::UnitTestImpl::RunAllTests()
    @           0x654aa7  testing::UnitTest::Run()
    @           0x41d480  main
    @     0x2b0c114b4ec5  (unknown)
    @           0x4244b7  (unknown)
    @              (nil)  (unknown)
make: *** [runtest] Aborted (core dumped)


 

試す

Tutorialにしたがって動作を確認します。

prototxtを編集しないとエラーが出ますので、"lenet_solver.prototxt"の一番下の行のGPUをCPUに変更して下さい。

cordea@4536d063fc8a:~/caffe/caffe$ vim examples/mnist/lenet_solver.prototxt
cordea@4536d063fc8a:~/caffe/caffe$ ./data/mnist/get_mnist.sh 
cordea@4536d063fc8a:~/caffe/caffe$ ./examples/mnist/create_mnist.sh
cordea@4536d063fc8a:~/caffe/caffe$ ./examples/mnist/train_lenet.sh