Preface
After dozens of caffe installation experiences, I finally have a deeper understanding of its installation process and know how to avoid some bug s. Let me restart it first. If we can get into ubuntu normally, let's describe the configuration process in detail. (Because the previous configuration was successful, even ubuntu can't get in after restart. God bless me!)
Okay, I restarted it and came back successfully. It seems that this time it's really well configured.
Key points of configuration
To sum up, you want to configure it successfully.
1) I think the most important thing is to have a certain understanding of environmental variables.
2) Know where your opencv is installed, because some functions in caffe need to call the opencv library.
3) You should know what each line of terminal commands does, such as make all.
My configuration:
System: ubuntu18.04 LTS (other versions are also available)
OpenCV version: 2.4.13 (opencv4 I haven't tried, I'm afraid it's not compatible with caffe)
Caffe Source: https://github.com/BVLC/caffe to download here
Configuration preparation
1. reference Installation Guidance of caffe Official Network Download the dependencies.
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install --no-install-recommends libboost-all-dev
It's worth mentioning here that if your system version is ubuntu18 like me, then people integrate Caffe package in apt install and can download and install it by themselves. This is very convenient. If you want to test it after installation, the terminal input Python 3 into python programming environment, and then you can import caffe. However, at present, at my level, only caffe can be imported. Using it to do python-related programming of caffe, under C++, Caffe packages are always not imported. I think this way can only be used in Python environment. If you want to use Caffe from c++ version, or want to see the code structure of caffe clearly, it is better to install it honestly from the source code.
2. Source code compilation and installation of Opencv
Why download the source code? After all, sudo apt install libopencv-dev has been done before. Because this automatic download package is not good, first of all, even if you are lucky enough to configure it, you will find that some functions such as displaying pictures and videos are not used, because the above package is castrated version! So obedient source code compile and install Opencv. Versions 2 and 3 are both available, but 4 may not work on caffe because the Opencv options in Makefile.config are only 2 and 3.
from opencv Official Download Website Download it to your computer and refer to it Opencv Official Installation Guide . Here's a long story. Official installation instructions are the best. Don't just fool around with a blog. Most of them are in a mess.
The default opencv installation location is, / usr/local, which is fine by default. Makefile.config is simpler later, and cafe can easily find your installation location.
I'm going to have a lot of trouble. The installation location of opencv2 is, / usr/opencv2_13./
This is my installation (don't mess around on your own):
cd ~/my path to/opencv mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/opencv2_13 .. make sudo make install
The make install here installs various library files into your pre-installation location. After installation, go to the directory and see for yourself. It was empty, but now there are some things.
Makefile.config
First, cp Makefile.config.example Makefile.config generates a Makefile.config file, which can be modified according to your own needs. It is very important to write how to directly determine the successful installation of your caffe.
My requirement is that I don't need the python interface for the time being, so I can annotate everything about Python first. We need to recompile later.
Let's talk about it here. caffe official website There are many bug s in the installation instructions, which I have basically encountered, and finally generated my unique Makefile.config for reference.
## Refer to http://caffe.berkeleyvision.org/installation.html # Contributions simplifying and improving our build system are welcome! # cuDNN acceleration switch (uncomment to build with cuDNN). # USE_CUDNN := 1 #Because GPU is not applicable, it is not suitable. # CPU-only switch (uncomment to build without GPU support). CPU_ONLY := 1 #Configuring the cpu version of caffe must be turned on # uncomment to disable IO dependencies and corresponding data layers # USE_OPENCV := 0 #This means that = 0 means no need, no need for some functions in it, maybe some operations can be implemented without opencv. But opencv is convenient # USE_LEVELDB := 0 # # USE_LMDB := 0 #You need to convert the image to this LMDB format in the future, or do you want to use it? # This code is taken from https://github.com/sh1r0/caffe-android-lib # USE_HDF5 := 0 # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary) # You should not set this flag if you will be reading LMDBs with any # possibility of simultaneous read and write # ALLOW_LMDB_NOLOCK := 1 # Uncomment if you're using OpenCV 3 #OPENCV_VERSION := 3 #If you're an opencv3 version, you have to turn this on # To customize your choice of compiler, uncomment and set the following. # N.B. the default for Linux is g++ and the default for OSX is clang++ # CUSTOM_CXX := g++ # CUDA directory contains bin/ and lib/ directories that we need. CUDA_DIR := /usr/local/cuda #It's okay to leave this uncommented, because cpu_only is already in front of it. # On Ubuntu 14.04, if cuda tools are installed via # "sudo apt-get install nvidia-cuda-toolkit" then use this instead: # CUDA_DIR := /usr # CUDA architecture setting: going with all of them. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility. # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility. CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \ -gencode arch=compute_20,code=sm_21 \ -gencode arch=compute_30,code=sm_30 \ -gencode arch=compute_35,code=sm_35 \ -gencode arch=compute_50,code=sm_50 \ -gencode arch=compute_52,code=sm_52 \ -gencode arch=compute_60,code=sm_60 \ -gencode arch=compute_61,code=sm_61 \ -gencode arch=compute_61,code=compute_61 # BLAS choice: # atlas for ATLAS (default) # mkl for MKL # open for OpenBlas BLAS := atlas # Custom (MKL/ATLAS/OpenBLAS) include and lib directories. # Leave commented to accept the defaults for your choice of BLAS # (which should work)! # BLAS_INCLUDE := /path/to/your/blas # BLAS_LIB := /path/to/your/blas # Homebrew puts openblas in a directory that is not on the standard search path # BLAS_INCLUDE := $(shell brew --prefix openblas)/include # BLAS_LIB := $(shell brew --prefix openblas)/lib # This is required only if you will compile the matlab interface. # MATLAB directory should contain the mex binary in /bin. # MATLAB_DIR := /usr/local # MATLAB_DIR := /Applications/MATLAB_R2012b.app # NOTE: this is required only if you will compile the python interface. # We need to be able to find Python.h and numpy/arrayobject.h. #I've commented it out here, so I don't need Python training test for the time being. #PYTHON_INCLUDE := /usr/include/python3.6 \ # /usr/lib/python3/dist-packages/numpy/core/include # Anaconda Python distribution is quite popular. Include path: # Verify anaconda location, sometimes it's in root. #It is strongly recommended not to open. There are many conflicts between anaconda and the default environment of the system. If you open it, it will be a headache to choose environment variables. I have tried. #ANACONDA_HOME := $(HOME)/anaconda3 #PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ # $(ANACONDA_HOME)/include/python3.7m \ # $(ANACONDA_HOME)/lib/python3.7/site-packages/numpy/core/include # Uncomment to use Python 3 (default is Python 2) # PYTHON_LIBRARIES := boost_python3 python3.5m # PYTHON_INCLUDE := /usr/include/python3.5m \ # /usr/lib/python3.5/dist-packages/numpy/core/include # We need to be able to find libpythonX.X.so or .dylib. #PYTHON_LIB := /usr/lib #PYTHON_LIB := $(ANACONDA_HOME)/lib # Homebrew installs numpy in a non standard path (keg only) # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include # PYTHON_LIB += $(shell brew --prefix numpy)/lib # Uncomment to support layers written in Python (will link against Python libs) # WITH_PYTHON_LAYER := 1 # Whatever else you find you need goes here. #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 #These two places are very important. Can you successfully avoid pits and configure caffe?,95%Here we are. INCLUDE_DIRS := /usr/opencv2_13/include /usr/local/include /usr/include/hdf5/serial LIBRARY_DIRS := /usr/opencv2_13/lib /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies # INCLUDE_DIRS += $(shell brew --prefix)/include # LIBRARY_DIRS += $(shell brew --prefix)/lib # NCCL acceleration switch (uncomment to build with NCCL) # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0) # USE_NCCL := 1 # Uncomment to use `pkg-config` to specify OpenCV library paths. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.) #USE_PKG_CONFIG := 1 #LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs # N.B. both build and distribute dirs are cleared on `make clean` BUILD_DIR := build DISTRIBUTE_DIR := distribute # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 # DEBUG := 1 # The ID of the GPU that 'make runtest' will use to run unit tests. TEST_GPUID := 0 # enable pretty build (comment to see full commands) Q ?= @
It's very important to find two lines of Include and libs, as I wrote:
INCLUDE_DIRS := /usr/opencv2_13/include /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := /usr/opencv2_13/lib /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
Because my opencv2 is installed in the / usr/opencv2_13 directory, it must be placed in the front, so that the compiler can find this path first, I tried, and then failed. Because compilers are clumsy, multiple opencv versions are prone to conflict. First of all, the system installed the default / usr/local directory when sudo apt install libopencv-dev. After all, this castration version gave me a wrong report as soon as something was missing, so put my installation directory in the front to block the compiler's mouth. In addition, the directory of hdf5 should also be included. This does not conflict, so it's okay to put it in the back.
Specific practice to install it
Common errors:
CXX/LD -o .build_release/tools/extract_features.bin CXX/LD -o .build_release/tools/convert_imageset.bin CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin CXX/LD -o .build_release/tools/compute_image_mean.bin .build_release/lib/libcaffe.so: undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' .build_release/lib/libcaffe.so: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)' .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' .build_release/lib/libcaffe.so: undefined reference to `vtable for cv::_InputArray' collect2: error: ld returned 1 exit status Makefile:635: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1 make: *** Waiting for unfinished jobs.... .build_release/lib/libcaffe.so: undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' .build_release/lib/libcaffe.so: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)' .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' .build_release/lib/libcaffe.so: undefined reference to `vtable for cv::_InputArray' collect2: error: ld returned 1 exit status .build_release/lib/libcaffe.so: undefined reference to `cv::_OutputArray::_OutputArray(cv::MatMakefile:635: recipe for target '.build_release/tools/extract_features.bin' failed &make: *** [.build_release/tools/extract_features.bin] Error 1 )' .build_release/lib/libcaffe.so: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)' .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' .build_release/lib/libcaffe.so: undefined reference to `vtable for cv::_InputArray' collect2: error: ld returned 1 exit status Makefile:635: recipe for target '.build_release/tools/compute_image_mean.bin' failed make: *** [.build_release/tools/compute_image_mean.bin] Error 1 .build_release/lib/libcaffe.so: undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' .build_release/lib/libcaffe.so: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)' .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' .build_release/lib/libcaffe.so: undefined reference to `vtable for cv::_InputArray' collect2: error: ld returned 1 exit status Makefile:635: recipe for target '.build_release/tools/convert_imageset.bin' failed make: *** [.build_release/tools/convert_imageset.bin] Error 1
This prompts the opencv library not to be found. Write Makefile.config as I said above and there will be no problem.
Successful make all:
wwh@wwh-Lenovo-YOGA-710-14IKB:~/Documents/caffe$ make all -j4 PROTOC src/caffe/proto/caffe.proto CXX .build_release/src/caffe/proto/caffe.pb.cc CXX src/caffe/solvers/nesterov_solver.cpp CXX src/caffe/solvers/rmsprop_solver.cpp CXX src/caffe/solvers/adagrad_solver.cpp CXX src/caffe/solvers/adam_solver.cpp CXX src/caffe/solvers/adadelta_solver.cpp CXX src/caffe/solvers/sgd_solver.cpp CXX src/caffe/blob.cpp CXX src/caffe/common.cpp CXX src/caffe/util/db_lmdb.cpp CXX src/caffe/util/upgrade_proto.cpp CXX src/caffe/util/benchmark.cpp CXX src/caffe/util/im2col.cpp CXX src/caffe/util/db.cpp CXX src/caffe/util/db_leveldb.cpp CXX src/caffe/util/hdf5.cpp CXX src/caffe/util/blocking_queue.cpp CXX src/caffe/util/cudnn.cpp CXX src/caffe/util/math_functions.cpp CXX src/caffe/util/signal_handler.cpp CXX src/caffe/util/insert_splits.cpp CXX src/caffe/util/io.cpp CXX src/caffe/layers/tanh_layer.cpp CXX src/caffe/layers/split_layer.cpp CXX src/caffe/layers/spp_layer.cpp CXX src/caffe/layers/window_data_layer.cpp CXX src/caffe/layers/dropout_layer.cpp CXX src/caffe/layers/prelu_layer.cpp CXX src/caffe/layers/tile_layer.cpp CXX src/caffe/layers/loss_layer.cpp CXX src/caffe/layers/crop_layer.cpp CXX src/caffe/layers/batch_reindex_layer.cpp CXX src/caffe/layers/lstm_layer.cpp CXX src/caffe/layers/hdf5_data_layer.cpp CXX src/caffe/layers/cudnn_lcn_layer.cpp CXX src/caffe/layers/scale_layer.cpp CXX src/caffe/layers/cudnn_lrn_layer.cpp CXX src/caffe/layers/swish_layer.cpp CXX src/caffe/layers/softmax_loss_layer.cpp CXX src/caffe/layers/cudnn_deconv_layer.cpp CXX src/caffe/layers/hdf5_output_layer.cpp CXX src/caffe/layers/absval_layer.cpp CXX src/caffe/layers/flatten_layer.cpp CXX src/caffe/layers/accuracy_layer.cpp CXX src/caffe/layers/lrn_layer.cpp CXX src/caffe/layers/exp_layer.cpp CXX src/caffe/layers/filter_layer.cpp CXX src/caffe/layers/euclidean_loss_layer.cpp CXX src/caffe/layers/deconv_layer.cpp CXX src/caffe/layers/base_data_layer.cpp CXX src/caffe/layers/batch_norm_layer.cpp CXX src/caffe/layers/memory_data_layer.cpp CXX src/caffe/layers/base_conv_layer.cpp CXX src/caffe/layers/embed_layer.cpp CXX src/caffe/layers/cudnn_sigmoid_layer.cpp CXX src/caffe/layers/pooling_layer.cpp CXX src/caffe/layers/cudnn_tanh_layer.cpp CXX src/caffe/layers/parameter_layer.cpp CXX src/caffe/layers/data_layer.cpp CXX src/caffe/layers/mvn_layer.cpp CXX src/caffe/layers/input_layer.cpp CXX src/caffe/layers/image_data_layer.cpp CXX src/caffe/layers/eltwise_layer.cpp CXX src/caffe/layers/hinge_loss_layer.cpp CXX src/caffe/layers/bias_layer.cpp CXX src/caffe/layers/power_layer.cpp CXX src/caffe/layers/clip_layer.cpp CXX src/caffe/layers/softmax_layer.cpp CXX src/caffe/layers/relu_layer.cpp CXX src/caffe/layers/im2col_layer.cpp CXX src/caffe/layers/conv_layer.cpp CXX src/caffe/layers/inner_product_layer.cpp CXX src/caffe/layers/cudnn_conv_layer.cpp CXX src/caffe/layers/argmax_layer.cpp CXX src/caffe/layers/reshape_layer.cpp CXX src/caffe/layers/log_layer.cpp CXX src/caffe/layers/contrastive_loss_layer.cpp CXX src/caffe/layers/cudnn_pooling_layer.cpp CXX src/caffe/layers/bnll_layer.cpp CXX src/caffe/layers/infogain_loss_layer.cpp CXX src/caffe/layers/neuron_layer.cpp CXX src/caffe/layers/cudnn_softmax_layer.cpp CXX src/caffe/layers/multinomial_logistic_loss_layer.cpp CXX src/caffe/layers/threshold_layer.cpp CXX src/caffe/layers/silence_layer.cpp CXX src/caffe/layers/sigmoid_layer.cpp CXX src/caffe/layers/concat_layer.cpp CXX src/caffe/layers/rnn_layer.cpp CXX src/caffe/layers/slice_layer.cpp CXX src/caffe/layers/dummy_data_layer.cpp CXX src/caffe/layers/recurrent_layer.cpp CXX src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp CXX src/caffe/layers/reduction_layer.cpp CXX src/caffe/layers/elu_layer.cpp CXX src/caffe/layers/cudnn_relu_layer.cpp CXX src/caffe/layers/lstm_unit_layer.cpp CXX src/caffe/syncedmem.cpp CXX src/caffe/layer_factory.cpp CXX src/caffe/layer.cpp CXX src/caffe/solver.cpp CXX src/caffe/internal_thread.cpp CXX src/caffe/net.cpp CXX src/caffe/parallel.cpp CXX src/caffe/data_transformer.cpp CXX tools/extract_features.cpp CXX tools/convert_imageset.cpp CXX tools/upgrade_net_proto_binary.cpp CXX tools/compute_image_mean.cpp CXX tools/upgrade_solver_proto_text.cpp CXX tools/caffe.cpp CXX tools/upgrade_net_proto_text.cpp CXX examples/cpp_classification/classification.cpp CXX examples/cifar10/convert_cifar_data.cpp CXX examples/siamese/convert_mnist_siamese_data.cpp CXX examples/mnist/convert_mnist_data.cpp AR -o .build_release/lib/libcaffe.a LD -o .build_release/lib/libcaffe.so.1.0.0 CXX/LD -o .build_release/tools/extract_features.bin CXX/LD -o .build_release/tools/convert_imageset.bin CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin CXX/LD -o .build_release/tools/compute_image_mean.bin CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin CXX/LD -o .build_release/tools/caffe.bin CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin CXX/LD -o .build_release/examples/cpp_classification/classification.bin CXX/LD -o .build_release/examples/cifar10/convert_cifar_data.bin CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin
Successful make test
wwh@wwh-Lenovo-YOGA-710-14IKB:~/Documents/caffe$ make test CXX src/caffe/test/test_tile_layer.cpp CXX src/caffe/test/test_rnn_layer.cpp CXX src/caffe/test/test_flatten_layer.cpp CXX src/caffe/test/test_db.cpp CXX src/caffe/test/test_pooling_layer.cpp CXX src/caffe/test/test_reduction_layer.cpp CXX src/caffe/test/test_net.cpp CXX src/caffe/test/test_euclidean_loss_layer.cpp CXX src/caffe/test/test_data_transformer.cpp CXX src/caffe/test/test_power_layer.cpp CXX src/caffe/test/test_threshold_layer.cpp CXX src/caffe/test/test_convolution_layer.cpp CXX src/caffe/test/test_softmax_layer.cpp CXX src/caffe/test/test_hdf5data_layer.cpp CXX src/caffe/test/test_infogain_loss_layer.cpp CXX src/caffe/test/test_common.cpp CXX src/caffe/test/test_random_number_generator.cpp CXX src/caffe/test/test_filter_layer.cpp CXX src/caffe/test/test_dummy_data_layer.cpp CXX src/caffe/test/test_softmax_with_loss_layer.cpp CXX src/caffe/test/test_filler.cpp CXX src/caffe/test/test_stochastic_pooling.cpp CXX src/caffe/test/test_solver.cpp CXX src/caffe/test/test_inner_product_layer.cpp CXX src/caffe/test/test_mvn_layer.cpp CXX src/caffe/test/test_hinge_loss_layer.cpp CXX src/caffe/test/test_reshape_layer.cpp CXX src/caffe/test/test_maxpool_dropout_layers.cpp CXX src/caffe/test/test_layer_factory.cpp CXX src/caffe/test/test_lrn_layer.cpp CXX src/caffe/test/test_gradient_based_solver.cpp CXX src/caffe/test/test_im2col_layer.cpp CXX src/caffe/test/test_data_layer.cpp CXX src/caffe/test/test_protobuf.cpp CXX src/caffe/test/test_solver_factory.cpp CXX src/caffe/test/test_split_layer.cpp CXX src/caffe/test/test_lstm_layer.cpp CXX src/caffe/test/test_multinomial_logistic_loss_layer.cpp CXX src/caffe/test/test_sigmoid_cross_entropy_loss_layer.cpp CXX src/caffe/test/test_concat_layer.cpp CXX src/caffe/test/test_spp_layer.cpp CXX src/caffe/test/test_platform.cpp CXX src/caffe/test/test_math_functions.cpp CXX src/caffe/test/test_internal_thread.cpp CXX src/caffe/test/test_deconvolution_layer.cpp CXX src/caffe/test/test_hdf5_output_layer.cpp CXX src/caffe/test/test_bias_layer.cpp CXX src/caffe/test/test_eltwise_layer.cpp CXX src/caffe/test/test_slice_layer.cpp CXX src/caffe/test/test_memory_data_layer.cpp CXX src/caffe/test/test_accuracy_layer.cpp CXX src/caffe/test/test_scale_layer.cpp CXX src/caffe/test/test_contrastive_loss_layer.cpp CXX src/caffe/test/test_batch_norm_layer.cpp CXX src/caffe/test/test_argmax_layer.cpp CXX src/caffe/test/test_benchmark.cpp CXX src/caffe/test/test_tanh_layer.cpp CXX src/caffe/test/test_embed_layer.cpp CXX src/caffe/test/test_neuron_layer.cpp CXX src/caffe/test/test_io.cpp CXX src/caffe/test/test_crop_layer.cpp CXX src/caffe/test/test_batch_reindex_layer.cpp CXX src/caffe/test/test_upgrade_proto.cpp CXX src/caffe/test/test_blob.cpp CXX src/caffe/test/test_image_data_layer.cpp CXX src/caffe/test/test_syncedmem.cpp CXX src/caffe/test/test_util_blas.cpp CXX src/gtest/gtest-all.cpp CXX/LD -o .build_release/test/test_all.testbin src/caffe/test/test_caffe_main.cpp LD .build_release/src/caffe/test/test_tile_layer.o LD .build_release/src/caffe/test/test_rnn_layer.o LD .build_release/src/caffe/test/test_flatten_layer.o LD .build_release/src/caffe/test/test_db.o LD .build_release/src/caffe/test/test_pooling_layer.o LD .build_release/src/caffe/test/test_reduction_layer.o LD .build_release/src/caffe/test/test_net.o LD .build_release/src/caffe/test/test_euclidean_loss_layer.o LD .build_release/src/caffe/test/test_data_transformer.o LD .build_release/src/caffe/test/test_power_layer.o LD .build_release/src/caffe/test/test_threshold_layer.o LD .build_release/src/caffe/test/test_convolution_layer.o LD .build_release/src/caffe/test/test_softmax_layer.o LD .build_release/src/caffe/test/test_hdf5data_layer.o LD .build_release/src/caffe/test/test_infogain_loss_layer.o LD .build_release/src/caffe/test/test_common.o LD .build_release/src/caffe/test/test_random_number_generator.o LD .build_release/src/caffe/test/test_filter_layer.o LD .build_release/src/caffe/test/test_dummy_data_layer.o LD .build_release/src/caffe/test/test_softmax_with_loss_layer.o LD .build_release/src/caffe/test/test_filler.o LD .build_release/src/caffe/test/test_stochastic_pooling.o LD .build_release/src/caffe/test/test_solver.o LD .build_release/src/caffe/test/test_inner_product_layer.o LD .build_release/src/caffe/test/test_mvn_layer.o LD .build_release/src/caffe/test/test_hinge_loss_layer.o LD .build_release/src/caffe/test/test_reshape_layer.o LD .build_release/src/caffe/test/test_maxpool_dropout_layers.o LD .build_release/src/caffe/test/test_layer_factory.o LD .build_release/src/caffe/test/test_lrn_layer.o LD .build_release/src/caffe/test/test_gradient_based_solver.o LD .build_release/src/caffe/test/test_im2col_layer.o LD .build_release/src/caffe/test/test_data_layer.o LD .build_release/src/caffe/test/test_protobuf.o LD .build_release/src/caffe/test/test_solver_factory.o LD .build_release/src/caffe/test/test_split_layer.o LD .build_release/src/caffe/test/test_lstm_layer.o LD .build_release/src/caffe/test/test_multinomial_logistic_loss_layer.o LD .build_release/src/caffe/test/test_sigmoid_cross_entropy_loss_layer.o LD .build_release/src/caffe/test/test_concat_layer.o LD .build_release/src/caffe/test/test_spp_layer.o LD .build_release/src/caffe/test/test_platform.o LD .build_release/src/caffe/test/test_math_functions.o LD .build_release/src/caffe/test/test_internal_thread.o LD .build_release/src/caffe/test/test_deconvolution_layer.o LD .build_release/src/caffe/test/test_hdf5_output_layer.o LD .build_release/src/caffe/test/test_bias_layer.o LD .build_release/src/caffe/test/test_eltwise_layer.o LD .build_release/src/caffe/test/test_slice_layer.o LD .build_release/src/caffe/test/test_memory_data_layer.o LD .build_release/src/caffe/test/test_accuracy_layer.o LD .build_release/src/caffe/test/test_scale_layer.o LD .build_release/src/caffe/test/test_contrastive_loss_layer.o LD .build_release/src/caffe/test/test_batch_norm_layer.o LD .build_release/src/caffe/test/test_argmax_layer.o LD .build_release/src/caffe/test/test_benchmark.o LD .build_release/src/caffe/test/test_tanh_layer.o LD .build_release/src/caffe/test/test_embed_layer.o LD .build_release/src/caffe/test/test_neuron_layer.o LD .build_release/src/caffe/test/test_io.o LD .build_release/src/caffe/test/test_crop_layer.o LD .build_release/src/caffe/test/test_batch_reindex_layer.o LD .build_release/src/caffe/test/test_upgrade_proto.o LD .build_release/src/caffe/test/test_blob.o LD .build_release/src/caffe/test/test_image_data_layer.o LD .build_release/src/caffe/test/test_syncedmem.o LD .build_release/src/caffe/test/test_util_blas.o
make runtest
Now if you make runtest directly, you can't. You will report such a mistake.
wwh@wwh-Lenovo-YOGA-710-14IKB:~/Documents/caffe$ make runtest .build_release/tools/caffe .build_release/tools/caffe: error while loading shared libraries: libopencv_core.so.2.4: cannot open shared object file: No such file or directory Makefile:542: recipe for target 'runtest' failed make: *** [runtest] Error 127
Because our compiled opencv is not installed in the default directory, when we call it, caffe can not find the relevant opencv library, which will naturally cause errors. So what?
The simple way is to add dynamic link libraries first.
export LD_LIBRARY_PATH=/usr/opencv2_13/lib
sudo ldconfig
So caffe can go to the dynamic link library directory to find opencv. But the disadvantage is that you have to export every time before running. After all, the lifecycle of this method is relatively short. Turn off the terminal, and the dynamic link library will disappear. If you want to join permanently, check it out by yourself.
Then make runtest, success!
wwh@wwh-Lenovo-YOGA-710-14IKB:~/Documents/caffe$ make runtest .build_release/tools/caffe caffe: command line brew usage: caffe <command> <args> commands: train train or finetune a model test score a model device_query show GPU diagnostic information time benchmark model execution time Flags from tools/caffe.cpp: -gpu (Optional; run in GPU mode on given device IDs separated by ','.Use '-gpu all' to run on all available GPUs. The effective training batch size is multiplied by the number of devices.) type: string default: "" -iterations (The number of iterations to run.) type: int32 default: 50 -level (Optional; network level.) type: int32 default: 0 -model (The model definition protocol buffer text file.) type: string default: "" -phase (Optional; network phase (TRAIN or TEST). Only used for 'time'.) type: string default: "" -sighup_effect (Optional; action to take when a SIGHUP signal is received: snapshot, stop or none.) type: string default: "snapshot" -sigint_effect (Optional; action to take when a SIGINT signal is received: snapshot, stop or none.) type: string default: "stop" -snapshot (Optional; the snapshot solver state to resume training.) type: string default: "" -solver (The solver definition protocol buffer text file.) type: string default: "" -stage (Optional; network stages (not to be confused with phase), separated by ','.) type: string default: "" -weights (Optional; the pretrained weights to initialize finetuning, separated by ','. Cannot be set simultaneously with snapshot.) type: string default: "" .build_release/test/test_all.testbin 0 --gtest_shuffle --gtest_filter="-*GPU*" Note: Google Test filter = -*GPU* Note: Randomizing tests' orders with a seed of 21118 . [==========] Running 1162 tests from 152 test cases. [----------] Global test environment set-up. [----------] 4 tests from ConstantFillerTest/0, where TypeParam = float [ RUN ] ConstantFillerTest/0.TestFill5D [ OK ] ConstantFillerTest/0.TestFill5D (0 ms) [ RUN ] ConstantFillerTest/0.TestFill [ OK ] ConstantFillerTest/0.TestFill (0 ms) [ RUN ] ConstantFillerTest/0.TestFill1D [ OK ] ConstantFillerTest/0.TestFill1D (0 ms) [ RUN ] ConstantFillerTest/0.TestFill2D [ OK ] ConstantFillerTest/0.TestFill2D (0 ms) [----------] 4 tests from ConstantFillerTest/0 (0 ms total) ******************Omission in the middle**************************************** [----------] 10 tests from PowerLayerTest/0, where TypeParam = caffe::CPUDevice<float> [ RUN ] PowerLayerTest/0.TestPowerOneGradient [ OK ] PowerLayerTest/0.TestPowerOneGradient (1 ms) [ RUN ] PowerLayerTest/0.TestPowerGradientShiftZero [ OK ] PowerLayerTest/0.TestPowerGradientShiftZero (1 ms) [ RUN ] PowerLayerTest/0.TestPowerZero [ OK ] PowerLayerTest/0.TestPowerZero (0 ms) [ RUN ] PowerLayerTest/0.TestPowerTwo [ OK ] PowerLayerTest/0.TestPowerTwo (0 ms) [ RUN ] PowerLayerTest/0.TestPower [ OK ] PowerLayerTest/0.TestPower (0 ms) [ RUN ] PowerLayerTest/0.TestPowerTwoScaleHalfGradient [ OK ] PowerLayerTest/0.TestPowerTwoScaleHalfGradient (1 ms) [ RUN ] PowerLayerTest/0.TestPowerTwoGradient [ OK ] PowerLayerTest/0.TestPowerTwoGradient (2 ms) [ RUN ] PowerLayerTest/0.TestPowerGradient [ OK ] PowerLayerTest/0.TestPowerGradient (1 ms) [ RUN ] PowerLayerTest/0.TestPowerZeroGradient [ OK ] PowerLayerTest/0.TestPowerZeroGradient (1 ms) [ RUN ] PowerLayerTest/0.TestPowerOne [ OK ] PowerLayerTest/0.TestPowerOne (0 ms) [----------] 10 tests from PowerLayerTest/0 (8 ms total) [----------] 4 tests from SoftmaxWithLossLayerTest/1, where TypeParam = caffe::CPUDevice<double> [ RUN ] SoftmaxWithLossLayerTest/1.TestGradient [ OK ] SoftmaxWithLossLayerTest/1.TestGradient (6 ms) [ RUN ] SoftmaxWithLossLayerTest/1.TestForwardIgnoreLabel [ OK ] SoftmaxWithLossLayerTest/1.TestForwardIgnoreLabel (0 ms) [ RUN ] SoftmaxWithLossLayerTest/1.TestGradientIgnoreLabel [ OK ] SoftmaxWithLossLayerTest/1.TestGradientIgnoreLabel (8 ms) [ RUN ] SoftmaxWithLossLayerTest/1.TestGradientUnnormalized [ OK ] SoftmaxWithLossLayerTest/1.TestGradientUnnormalized (6 ms) [----------] 4 tests from SoftmaxWithLossLayerTest/1 (20 ms total) [----------] Global test environment tear-down [==========] 1162 tests from 152 test cases ran. (34731 ms total) [ PASSED ] 1162 tests.
Note that if it's just export LD_LIBRARY_PAYH, then you have to export before running the caffe model. Or write this into CMakeLists.txt, which, of course, is later. You know environmental variables naturally.