Ubuntu 18.04 では sudo apt install caffe-cpu
で導入できますが, チュートリアルを実行したいためにコードのビルドから実行
実行環境
- Windows 10 (1903)
- Ubuntu 18.4 on WSL
- No CUDA環境
環境構築
Caffeの各種情報を参考に環境構築
- 必要なツールのインストール
Tutorialの環境のビルドのためsudo apt install caffe-cpu
ではなくてmakeできる環境を準備します.
http://caffe.berkeleyvision.org/install_apt.html を参考に
sudo apt-get install \
libprotobuf-dev \
libleveldb-dev \
libsnappy-dev \
libopencv-dev \
libhdf5-serial-dev \
protobuf-compiler \
libgflags-dev \
libgoogle-glog-dev \
libatlas-base-dev \
liblmdb-dev \
libboost-all-dev \
-y
- caffeのビルド
git clone https://github.com/BVLC/caffe.git
cd ./caffe
cp -a Makefile.config.example Makefile.config
Makefile.configの修正内容 (diff Makefile.config.example Makefile.config
)
8c8
< # CPU_ONLY := 1
---
> CPU_ONLY := 1
97,98c97,98
< INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
< LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
---
> INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
> LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
make all
cv::imreadがないと怒られる...
CXX/LD -o .build_release/tools/caffe.bin
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
collect2: error: ld returned 1 exit status
Makefile:635: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1
USE_PKG_CONFIG=1
を追加して再度makeしたら通った.
make USE_PKG_CONFIG=1 all test runtest
...
[==========] 1162 tests from 152 test cases ran. (43754 ms total)
[ PASSED ] 1162 tests.