使用anaconda3环境下的python2.7, 机器macos mojave 10.14

1.安装Xcode

首先现在app store中安装Xcode:

不然会有” framework not found vecLib “的问题出现

2.相应包安装

1.首先要安装homebrew包管理工具,在终端运行下面命令:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.然后利用该管理工具安装caffe依赖包

brew install -vd snappy leveldb gflags glog szip lmdb
brew install hdf5 opencv
brew install openblas

3.安装boost

brew install boost@1.59 boost-python@1.59
brew link boost@1.59 --force
brew link boost-python@1.59 --force

4. 安装2.6.1版本的protobuf

一开始的是安装3.5.1版本的protobuf,但是后面出现问题,所以还是安装2.6.1版本

下面只是记录一下:

cd ~/Downloads
wget https://github.com/protocolbuffers/protobuf/archive/v3.5.1.zip
unzip v3.5..zip
cd protobuf-3.5.
./autogen.sh
./configure
make
make install

运行./autogen.sh过程出错:

+ autoreconf -f -i -Wall,no-obsolete
./autogen.sh: line : autoreconf: command not found

解决方案是安装protobuf的依赖项:

(deeplearning2) userdeMacBook-Pro:protobuf-3.5. user$ brew install autoconf automake libtool

再重新运行./autogen.sh及之后命令

成功后查看版本:

(deeplearning2) userdeMacBook-Pro:protobuf-3.5. user$ protoc --version
libprotoc 3.5.

这里在下面caffe文件夹中make all之前忘记make clean了,可能是这个原因没成功也不一定,但是2.6.0版本的的确成功了,直接用该版本即可

后面发现还是不行,就去下了2.6.1版本的:

/Library/Developer/CommandLineTools/usr/bin/make  check-TESTS
PASS: protobuf-test
PASS: protobuf-lazy-descriptor-test
PASS: protobuf-lite-test
PASS: google/protobuf/compiler/zip_output_unittest.sh
PASS: google/protobuf/io/gzip_stream_unittest.sh
============================================================================
Testsuite summary for Protocol Buffers 2.6.
============================================================================
# TOTAL:
# PASS:
# SKIP:
# XFAIL:
# FAIL:
# XPASS:
# ERROR:
============================================================================

版本查看:

(deeplearning2) userdeMacBook-Pro:~ user$  protoc --version
libprotoc 2.6.

3.下载caffe源码

(deeplearning2) userdeMacBook-Pro:~ user$ git clone https://github.com/bvlc/caffe.git
Cloning into 'caffe'...
remote: Enumerating objects: , done.

下载好后:

(deeplearning2) userdeMacBook-Pro:~ user$ cd caffe
(deeplearning2) userdeMacBook-Pro:caffe user$ cp Makefile.config.example Makefile.config

4.更改Makefile.config文件

打开CPU_ONLY选项,保存

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

即去掉前面的#号,表示caffe编译时仅支持CPU,不支持GPU

取消CPU_ONLY前面的注释

取消USE_OPENCV前面的注释

取消USE_HDF5前面的注释,并且改成1

更改CUSTOM_CXX

注释掉CUDA_DIR那一行

将BLAS改成open

设置blas的路径,取消下面两行的注释

# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := # This code is taken from https://github.com/sh1r0/caffe-android-lib
USE_HDF5 := # Uncomment if you're using OpenCV 3
OPENCV_VERSION :=
# CUDA directory contains bin/ and lib/ directories that we need.
#CUDA_DIR := /usr/local/cuda
BLAS := open # 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
# 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

下面就是设置路径,使用的是anaconda3,这个根据你自己的路径设置

注释掉:

# 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. \
# /usr/lib/python2./dist-packages/numpy/core/include

更改为:

# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := /anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/envs/deeplearning2/include \
$(ANACONDA_HOME)/envs/deeplearning2/include/python2. \
$(ANACONDA_HOME)/envs/deeplearning2/lib/python2./site-packages/numpy/core/include

下面这个也更改为:

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/envs/deeplearning2/lib

然后添加一些include和lib路径:

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/opt/boost@1.59/include /usr/local/opt/hdf5/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/opt/boost-python@1.59/lib /usr/local/opt/hdf5/lib

最终版本为:

## 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 := # CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := # uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV :=
# USE_LEVELDB :=
# USE_LMDB :=
# This code is taken from https://github.com/sh1r0/caffe-android-lib
USE_HDF5 := # 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 := # Uncomment if you're using OpenCV 3
# OPENCV_VERSION := # 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++
CUSTOM_CXX := clang++ -std=c++ # 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 := open
# 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.
# PYTHON_INCLUDE := /usr/include/python2. \
# /usr/lib/python2./dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := /anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/envs/deeplearning2/include \
$(ANACONDA_HOME)/envs/deeplearning2/include/python2. \
$(ANACONDA_HOME)/envs/deeplearning2/lib/python2./site-packages/numpy/core/include # Uncomment to use Python (default is Python )
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3./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)/envs/deeplearning2/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 := # Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/opt/boost@1.59/include /usr/local/opt/hdf5/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/opt/boost-python@1.59/lib /usr/local/opt/hdf5/lib # 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 := # 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 := # 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 := # The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := # enable pretty build (comment to see full commands)
Q ?= @

如果你在运行make test命令出下面类似的错误:

In file included from /usr/local/include/leveldb/iterator.h::
/usr/local/include/leveldb/status.h::: error: expected ';' at end of declaration list
Status() noexcept : state_(nullptr) {}
^
;
/usr/local/include/leveldb/status.h::: warning: rvalue references are a C++ extension [-Wc++-extensions]
Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
^
/usr/local/include/leveldb/status.h::: error: expected ';' at end of declaration list
Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
^
;
/usr/local/include/leveldb/status.h::: error: 'Status' is missing exception specification 'throw()'
inline Status::Status(const Status& rhs) {
^
throw()
/usr/local/include/leveldb/status.h::: note: previous declaration is here
class LEVELDB_EXPORT Status {
^
/usr/local/include/leveldb/status.h::: warning: rvalue references are a C++ extension [-Wc++-extensions]
inline Status& Status::operator=(Status&& rhs) noexcept {
^
/usr/local/include/leveldb/status.h::: error: expected function body after function declarator
inline Status& Status::operator=(Status&& rhs) noexcept {
^
In file included from src/caffe/util/db.cpp::

之前出这样的内容以为是leveldb版本的问题,但是后面发现设置该为:

# 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++
CUSTOM_CXX := clang++ -std=c++

需要添加-std=c++11才能正常编译,就没有上面的问题了,跟着上面的配置走应该就不会有问题

想要读取python写的layer,就要取消下面行的注释:

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER :=

5.make编译:

make all
make test
make runtest
make pycaffe

⚠️注意:过程中可能会出现很多warning,只要不出现error,那都可以忽略

下面的问题基本上都使用更改配置的方法解决了,所以如果你跟着我上面的配置走,下面的一些问题你应该不会遇见

下面只是记录一下

⚠️运行make命令时,出了任何错,更改过后都要记得make clean一次,然后再从头make all进行编译

make all问题:

bool    OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue,
^
src/caffe/net.cpp::: error: use of undeclared identifier 'H5Fis_hdf5'
if (H5Fis_hdf5(trained_filename.c_str())) {
^
warnings and error generated.
make: *** [.build_release/src/caffe/net.o] Error

解决,在配置中添加boost路径:

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/opt/boost@1.59/include /usr/local/opt/hdf5/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/opt/boost-python@1.59/lib /usr/local/opt/hdf5/lib

make runtest问题:

(deeplearning2) userdeMacBook-Pro:caffe user$ make runtest
.build_release/tools/caffe
dyld: Library not loaded: /usr/local/opt/gcc/lib/gcc//libgfortran..dylib
Referenced from: /usr/local/opt/openblas/lib/libopenblasp-r0.3.5.dylib
Reason: image not found
make: *** [runtest] Abort trap:

原因:

因为我本地安装的gcc是9版本,只有/usr/local/opt/gcc/lib/gcc/9,没有8的路径

解决办法就是安装了个8的版本:

(deeplearning2) userdeMacBook-Pro:caffe user$ brew install gcc@
==> Downloading https://homebrew.bintray.com/bottles/gcc@8-8.3.0.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/b1/b1e150c72b4c3b7f3493371d71cdb668f691bfee2e998e5b0bf570eed28254d6?__gda__=exp=1565346562~hmac=81794cd252808740593fa500900f13dbd
######################################################################## 100.0%
==> Pouring gcc@-8.3..mojave.bottle.tar.gz

深度学习:21天实战caffe学习资源-4-环境安装的更多相关文章

  1. 21天实战caffe笔记_第二天

    1 传统机器学习 传统机器学习:通过人工设计特征提取器,将原始数据转化为合适的中间表示形式或者特征向量,利用学习系统(通常为分类器)可以对输入模式进行检测或者分类.流程如下: 传统机器学习的局限在于需 ...

  2. 21天实战caffe笔记_第三天

    1 深度学习工具汇总 (1)  caffe : 由BVLC开发的基于C++/CUDA/Python实现的卷积神经网络,提供了面向命令行.Matlab和Python的绑定接口.特性如下: A 实现了前馈 ...

  3. 21天实战caffe笔记_第一天

    1 深度学习术语 深度学习常用名词:有监督学习.无监督学习.训练数据集.测试数据集.过拟合.泛化.惩罚值(损失loss); 机器自动学习所需三份数据:训练集(机器学习的样例),验证集(机器学习阶段,用 ...

  4. Python学习--21天Python基础学习之旅(Day08-Day21)

    Day08: Chapter 11 异常 1.1如果try代码块中代码运行没有问题,则运行时跳过except代码块.(有异常时执行except中的代码,没有异常则跳过except中的代码) try-e ...

  5. Python学习--21天Python基础学习之旅(Day01、Day02)

    21天的python基础学习,使用<Python从入门到实践>,并且需要手敲书中的code,以下为整个学习过程的记录. Day01: 安装python时要选择复选框 Add Python ...

  6. Python学习--21天Python基础学习之旅(Day05、Day06、Day07)

    Day05: Chapter 8 函数 1.1函数定义与调用 1.1.1向函数传递参数 1.2传递实参 1.2.1位置实参:基于实参顺序 1.2.2关键字实参:调用时指出各个实参对应的形参 1.2.3 ...

  7. Python学习--21天Python基础学习之旅(Day03、Day04)

    关于缩进问题,缩进几个空格都不影响程序解释(不会报错什么的),但一般缩进四个空格是为了可读性和规范. Day03: Chapter 5 1.if语句 1.1条件测试:值为True或False的表达式成 ...

  8. PYTHON TDD学习(一)-->Python 3.4版本环境安装Django及其启动

    1.安装Python3.4版本,原因:3.4及其以后版本默认自带pip工具,非常好用 2.django 安装命令(c:\Python34\Scripts):pip install django 3.s ...

  9. 【神经网络与深度学习】深度学习实战——caffe windows 下训练自己的网络模型

    1.相关准备 1.1 手写数字数据集 这篇博客上有.jpg格式的图片下载,附带标签信息,有需要的自行下载,博客附带百度云盘下载地址(手写数字.jpg 格式):http://blog.csdn.net/ ...

随机推荐

  1. 《基于 Java EE 的高校重修管理系统设计与实现》论文笔记(九)

    标题:基于 Java EE 的高校重修管理系统设计与实现 一.基本信息 时间:2015 来源:河海大学文天学院 关键词::Java EE 架构: B/S 模式: 重修管理系统 二.研究内容 1.需求分 ...

  2. SQL SERVER使用 CROSS APPLY 与 OUTER APPLY 连接查询

    概述 CROSS APPLY 与 OUTER APPLY 可以做到:      左表一条关联右表多条记录时,我需要控制右表的某一条或多条记录跟左表匹配的情况. 有两张表:Student(学生表)和 S ...

  3. python - Django - restframework 简单使用 和 组件

    FBV 和 CBV CBV 通过函数调用方法FBV 通过类调用方法    其本质上都是 CBV 但是 FBV 内部封装了关于 method 的方法,由于基本上都是前端的请求,所有像GET,POST等方 ...

  4. LightOJ - 1323 - Billiard Balls(模拟)

    链接: https://vjudge.net/problem/LightOJ-1323 题意: You are given a rectangular billiard board, L and W ...

  5. .net web api 返回的是xml

    var result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(dto2) ...

  6. 阿里开源线上应用调试利器 Arthas的背后

    Arthas是一个功能非常强大的诊断工具,功能点很多,例如:jvm信息.线程信息.搜索类中的方法.跟踪代码执行.观测方法的入参和返回参数等等. 作为有追求的程序员,你不仅要知道它能做什么,更要思考它是 ...

  7. 替罪羊树 ------ luogu P3369 【模板】普通平衡树(Treap/SBT)

    二次联通门 : luogu P3369 [模板]普通平衡树(Treap/SBT) 闲的没事,把各种平衡树都写写 比较比较... 下面是替罪羊树 #include <cstdio> #inc ...

  8. SweetAlert 2 全网最详细的使用方法

    官网链接 SweetAlert2 官网链接 准备阶段 CDN js 如果该 链接 时间久远了 , 可以在官网去找找最新的 可以把 js 复制出来 自己新建一个文件 然后 引用到 html 中 1. 带 ...

  9. Python正则表达式【转载】

    原作者:LouieZhang 原文出处:https://www.cnblogs.com/LouieZhang/p/7399836.html 0x00 简介 正则表达式就是描述字符串排列的一套规则.利用 ...

  10. el-select定义初始值并且可以修改

    [](https://img2018.cnblogs.com/blog/1338470/201811/1338470-20181112152013318-1731627947.png <el-f ...