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
sudo apt-get install libatlas-base-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo git clone https://github.com/BVLC/caffe.git
cd /caffe/python
for
req in $(cat requirements.txt);
do
pip install $req; done
漫长的等待。。。。。。。。
我这里报错,没报错直接忽略
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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&)'
原因是我这里使用了opencv3x的依赖包
解决方法:
vim Makefile
在最后添加
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system boost_filesystem hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
又或者你的Makefile的编写形式是这样的
ifeq ($(USE_OPENCV),1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
ifeq ($(USE_OPENCV),3)
LIBRARIES += opencv_imgcodecs
endif
endif
---------------------------------------------------------------------------------------------------------------------------------
cp Makefile.config.example Makefile.config
vim Makefile.config
找到下面这两行,再将加黑路径添加上去
退出vim
make pycaffe
---------------------------------------------------------------------------------------------------------------------------------
这里出错了,提示找不到numpy
执行sudo apt-get install python-numpy
make test
make runtest
添加环境变量
echo 'export PYTHONPATH =$PYTHONPATH:/home/'username'/caffe/python'>>~/.bashrc
source ~/.bashrc
到这里就安装完成了,下面进行测试
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh
./build/tools/caffe.bin test -model=examples/mnist/lenet_train_test.prototxt -weights=examples/mnist/lenet_iter_10000.caffemodel -gpu=0 或者不使用GPU ./build/tools/caffe.bin test -model=examples/mnist/lenet_train_test.prototxt -weights=examples/mnist/lenet_iter_10000.caffemodel
所有数据都训练好之后,接下来就是如何将模型应用到实际数据了。test:表示对训练好的模型进行Testing,而不是training。其他参数包括train, time, device_query。
-model=XXX:指定模型prototxt文件,这是一个文本文件,详细描述了网络结构和数据集信息。