Asus主機 i7 Ubuntu16.04 + GTX 1080 8G + cuda10.0 + cudnn7.4.1 install caffe

目錄

Install caffe Reference

Step1. pre-installation

$ 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
BLAS:
$ sudo apt-get install libopenblas-dev 
Python:
$ sudo apt-get install the python-dev package 

$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
$ sudo apt-get install libatlas-base-dev


Step2.

$ git clone git://github.com/BVLC/caffe.git
$ cd caffe/
$ cp Makefile.config.example Makefile.config

更改 Makefile.config
$ vim Makefile.config

uncommand 
USE_PKG_CONFIG := 1  
USE_OPENCV := 0 (12/6 還沒安裝opencv所以先關掉
OPENCV_VERSION := 2.4

**opencv error**
_InputArray const&, intcv::_InputArray const&,) 'int
)'
collect2: error: ld returned 1 exit status
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
make: *** Waiting for unfinished jobs....

Delete 
CUDA_ARCH :=-gencode_arch=compute_20,code_sm_20 \
            -gencode_arch=compute_20,code_sm_21 \ 
hdf5 path:
----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

更改 Makefile
----LIBRARIES += hdf5_hl hdf5
++++LIBRARIES += hdf5_serial_hl hdf5_serial
---- $(OPENCV_VERSION),3
++++ $(OPENCV_VERSION),2.4

因為opencv error 找不到 libippic.a 
$ pkg-config --libs --cflags opencv (可以查到安裝路徑
$ ls share/OpenCV/3rdparty/lib/
$ cp share/OpenCV/3rdparty/lib/libippic.a /usr/local/lib/

Step3.

$ make clean
$ make (make all (make all -j8
$ make test
$ make runtest
成功就結束安裝了~~~

Caffe mnist test

training Reference

在git clone caffe 的時候,範例都有一起載下來~
只要再下載要訓練的資料就可以了!
先 download data:
$ ./data/mnist/get_mnist.sh
$ ./examples/mnist/create_mnist.sh
在run的前面加time 可以看到執行時間~ 
$ time ./examples/mnist/train_lenet.sh

I1205 18:45:26.570658  6016 sgd_solver.cpp:284] Snapshotting solver   state to binary proto file examples/mnist/lenet_iter_10000.solverstate
I1205 18:45:26.575165  6016 solver.cpp:327] Iteration 10000, loss = 0.00407554
I1205 18:45:26.575186  6016 solver.cpp:347] Iteration 10000, Testing net (#0)
I1205 18:45:26.845449  6023 data_layer.cpp:73] Restarting data prefetching from start.
I1205 18:45:26.856081  6016 solver.cpp:414]     Test net output #0: accuracy = 0.9901
I1205 18:45:26.856103  6016 solver.cpp:414]     Test net output #1: loss = 0.0281726 (* 1 = 0.0281726 loss)
I1205 18:45:26.856108  6016 solver.cpp:332] Optimization Done.
I1205 18:45:26.856112  6016 caffe.cpp:250] Optimization Done.
real 0m58.352s
user 0m54.758s
sys 0m13.820s  
 

Caffe cats and dogs test

training Reference

Python

$ sudo vim ~/.bashrc (add) export PYTHONPATH=/home/zoey/caffe/python:$PATHONPATH $ source ~/.bashrc $ pip install lmdb --user (for import lmdb error

cats and dogs

$ git clone https://github.com/adilmoujahid/deeplearning-cats-dogs-tutorial.git
$ cd deeplearning-cats-dogs-tutorial
$ mkdir input $ python create_imdb.py
 *** error **** 因為path的問題,要去更改一下,還有呼叫的相對應檔案都要一併更改。 
如果還是有問題,就把有關路徑的都改成絕對路徑。 
--generate data
$ /home/zoey/caffe/build/tools/compute_image_mean -backend=lmdb /home/zoey/deeplearning-cats-dogs-tutorial/input/train_lmdb /home/zoey/deeplearning-cats-dogs-tutorial/input/mean.binaryproto

 --trainin data
$ /home/zoey/caffe/build/tools/caffe train --solver /home/zoey/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/solver_1.prototxt 2>&1 | tee /home/zoey/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/model_1_train.log

$ python /home/zoey/deeplearning-cats-dogs-tutorial/code/plot_learning_curve.py /home/zoey/deeplearning-cats-dogs-tutorial/caffe_models/caffe_models/caffe_model_1/model_1_train.log /home/zoey/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/caffe_model_1_learning_curve.png

測試,使用train好的model來分辨貓狗

$ python /home/zoey/deeplearning-cats-dogs-tutorial/code/make_predictions_1.py
(記得路徑要改
  ** 單指定一張,更改讀圖就可以指定測試圖** 
----test_img_paths = [img_path for img_path in glob.glob("/home/zoey/deeplearning-cats-dogs-tutorial/input/test1/*jpg")] 
++++test_img_paths = [img_path for img_path in glob.glob("/home/zoey/deeplearning-cats-dogs-tutorial/input/test1/29.jpg")]
 

留言