ubuntu16.04+caffe+仅CPU安装

虽然我的机子很好 但是双显卡太费劲了 反正我暂时不想训练东西 先CPU就好 等师兄写完论文向他请教吧。
3: https://blog.csdn.net/zyb19931130/article/details/53842791
安装过程:
 
   

依赖项:按照官网的要求安装 具体的软件名 可以在https://packages.ubuntu.com/搜索

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev  libhdf5-serial-dev protobuf-compiler

libopencv-dev和libboost-all-dev我以前似乎都安装过 。
比如 我在终端输入:dpkg -l |grep boost
 
  

底下出现一堆

ii libboost-all-dev 1.58.0.1ubuntu1
ii libboost-atomic-dev:amd64 1.58.0.1ubuntu1 a types, operations, and memory ordering constraints
ii libboost-atomic1.58.0:amd64 1.58.0+dfsg-5ubuntu3.1 amd64 atomic data types, operations, and memory ordering constraints
ii libboost-chrono-dev:amd64 1.58.0.1ubuntu1 amd64 C++ representation of time duration, time point, and clocks (default version)
ii libboost-chrono1.58-dev:amd64 1.58.0+dfsg-5ubuntu3.1 amd64 C++
representation of time duration, time point, and clocks

 
 

就说明我安装了啊。

BLAS: install ATLAS by 

[python]  view plain  copy
  1. sudo apt-get install libatlas-base-dev  

这个BLAS是最慢的 但是管他呢 最简单。

我已经安装了opencv3了 所以直接用就好了

从caffe项目主页把caffe项目clone下来:

  1. git clone --recursive https://github.com/BVLC/caffe.git  

然后:

  1. cd caffe 
  2. cp Makefile.config.example Makefile.config 

由于是仅CPU安装,修改Makefile相关配置:

 
 
 
 

## 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

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 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

# 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
# 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 := /usr/include
BLAS_LIB := /usr/lib

# 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.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.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


# 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

# 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 ?= @


文件修改完成后,开始编译

make pycaffe  
若编译没有错误,则编译成功。完成后:
  1. $cd caffe/python  
  2. $python  
  3. >>>import caffe  
但我的编译有错误:
错误一:
 
 
 
 

make -j8 && make pycaffe

 
 
 
 

In file included from src/caffe/util/db_lmdb.cpp:2:0:
./include/caffe/util/db_lmdb.hpp:8:18: fatal error: lmdb.h: 没有那个文件或目录
compilation terminated.
Makefile:581: recipe for target '.build_release/src/caffe/util/db_lmdb.o' failed
make: *** [.build_release/src/caffe/util/db_lmdb.o] Error 1
make: *** 正在等待未完成的任务....

 
 

明明lmdb是可选的,但是非要报错我也没法子:

 
 
 
 

sudo apt-get install liblmdb-dev

名字我从https://packages.ubuntu.com/找到的。

安装好了再

 
 

make -j8 && make pycaffe

 
 

好了


错误二:

 
 
 
 

make all
make: Nothing to be done for 'all'.

没有这样的操作 我在caffe官网也没看到这样的操作 反而是cmake需要 不管了。


错误三:

 
 
 
 

>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "caffe/io.py", line 2, in <module>
import skimage.io
ImportError: No module named skimage.io

解决方案一:

 
 
 
 

pip install python-skimage

Collecting python-skimage
Could not find a version that satisfies the requirement python-skimage (from versions: )
No matching distribution found for python-skimage
You are using pip version 8.1.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

显示说我的pip要升级 我才不管呢 反正pip和apt-get也没啥区别。

解决方案二:

 
 
 
 

sudo apt-get install python-skimage

ok了  skimage是在https://packages.ubuntu.com/找的


错误四:

 
 
 
 

>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "caffe/io.py", line 8, in <module>
from caffe.proto import caffe_pb2
File "caffe/proto/caffe_pb2.py", line 6, in <module>
from google.protobuf.internal import enum_type_wrapper
ImportError: No module named google.protobuf.internal

遇到这个问题我很困惑 我明明安装了啊

 
 
 
 

dpkg -l|grep protobuf

显示:

 
 
 
 

ii libmirprotobuf3:amd64 0.26.3+16.04.20170605-0ubuntu1.1

很多诸如此类

明明是有的 我又在https://packages.ubuntu.com/上面找哪个软件有google.protobuf.internal这个文件 发现没有!

我谷歌了一下:

https://stackoverflow.com/questions/37666241/importing-caffe-results-in-importerror-no

-module-named-google-protobuf-interna

这个问问题的人就是没安装protobuf但我明明安装了libprotobuf-dev啊 唉 不管那么多了

 
 
 
 

pip install protobuf

好了 我猜测是ubuntu官网没有 但是python官网是有的

但我看链接中有人用sudo apt-get了 好像也行 有的人必须是sudo才行 好像 大家看看吧 。


最后结果:

 
 
 
 

>>> import caffe
>>>


接下来编译Faster-rcnn就相对容易:

全部按照这个后面来:https://blog.csdn.net/zyb19931130/article/details/53842791

只不过我遇到了一个错误,在这个中解决了。https://blog.csdn.net/u013832707/article/details/53501478

 
 
 
 

Traceback (most recent call last): 
File “/home/gph/Desktop/py-faster-rcnn-master/tools/../lib/rpn/proposal_layer.py”, line 10, in 
import yaml 
ImportError: No module named yaml 
Traceback (most recent call last): 
File “./tools/demo.py”, line 135, in 
net = caffe.Net(prototxt, caffemodel, caffe.TEST) 
SystemError: NULL result without error in PyObject_Call

sudo apt-get install python-yaml
 
 

安装结果:

 
 

Loaded network /home/zbq/py-faster-rcnn/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000456.jpg
Detection took 15.721s for 300 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000542.jpg
Detection took 14.330s for 161 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001150.jpg
Detection took 14.775s for 194 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001763.jpg
Detection took 14.695s for 196 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/004545.jpg
Detection took 15.533s for 300 object proposals
速度真是太慢了太慢了我的妈呀。

猜你喜欢

转载自blog.csdn.net/zhengbq_seu/article/details/80516663