Ubuntu 直接安装
下载caffe
git clone https://github.com/weiliu89/caffe.git
安装预编译的Caffe
对于仅CPU版本
sudo apt install caffe-cpu
对于CUDA版本
sudo apt install caffe-cuda
从源代码安装Caffe
sudo apt build-dep caffe-cpu # dependencies for CPU-only version
sudo apt build-dep caffe-cuda # dependencies for CUDA version
用make编译
通过复制和修改设置示例Makefile.config
来配置构建。默认值应该起作用,但是如果使用Anaconda Python,请取消注释相关行。
cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)
make all
make test
make runtest
- 对于CPU和GPU加速的Caffe,不需要进行任何更改。
- 对于使用NVIDIA专有cuDNN软件的cuDNN加速,请取消注释中的
USE_CUDNN := 1
开关Makefile.config
。cuDNN有时但并非总是比Caffe的GPU加速快。 - 对于仅CPU的Caffe,
CPU_ONLY := 1
在中取消注释Makefile.config
。
为了更快地构建,请执行并行编译,make all -j8
其中8是要编译的并行线程数(线程数的一个不错的选择是计算机中的内核数)。
make all的时候有一个错误
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::put_mem_block(void*)'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::get_mem_block()'
.build_release/lib/libcaffe.so: undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
.build_release/lib/libcaffe.so: undefined reference to `boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<Makefile:619: recipe for target '.build_release/tools/extract_features.bin' failed
char, std::make: *** [.build_release/tools/extract_features.bin] Error 1
char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
.build_release/lib/libcaffe.so: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
collect2: error: ld returned 1 exit status
Makefile:619: recipe for target '.build_release/tools/convert_annoset.bin' failed
make: *** [.build_release/tools/convert_annoset.bin] Error 1
解决方法:
修改 Makefile 文件
添加 boost_regex 到 LIBRARIES += 的最后
LIBRARIES += boost_thread stdc++
变成:
LIBRARIES += boost_thread stdc++ boost_regex