Ubuntu 14.04上安装caffe


== 前言 ==
本教程指导大家如何在Ubuntu 14.04上安装caffe。

== 前期准备 ==
为了安装caffe, 你需要准备如下东西, 1台安装了ubuntu 14.04的电脑, 1块nvidia显卡(当然, 你可以只用cpu跑caffe, 但时间会让你抓狂), cuda安装包。 以上为必备选项。 还有一些可选选项, 大家可以不安装, 但安装他们会提高caffe的性能, 包括intel mkl库(数学运算库, 需注册intel), cudnn(需注册nvidia开发者并通过审核)。

== 安装gcc, g++, gfortran ==
有了这些必须软件之后, 我们就可以一步一步安装caffe了。 不过在那之前, 请先安装c++编译器, ubuntu下一般采用gcc。<br />
<syntaxhighlight lang="bash">
sudo apt-get install build-essential # 安装gcc编译器
</syntaxhighlight>

== 安装cuda ==
请参靠网上的文章

== 安装intel mkl(可选) ==
caffe需要用到blas库, 有三个选择都可以满足caffe, 分别是intel mkl, atlas以及openblas。<br />
三者之中, 推荐安装intel mkl, 因为我认为blas的速度中应该是intel mkl最快。<br />
<br />
下载intel mkl去[https://software.intel.com/en-us/qualify-for-free-software/ 这里], 大家选择学生, 然后用邮箱申请一下即可。 intel会给你发一封带有邮箱和验证码的邮件。<br />
<br />
下载好之后, 解压, 然后安装
<syntaxhighlight lang="bash">
sudo sh install_GUI.sh # sudo 会采用root安装, 安装在/opt/intel中
</syntaxhighlight>
增加intel的lib路径
<syntaxhighlight lang="bash">
sudo gedit /etc/ld.so.conf.d/intel_mkl.conf
</syntaxhighlight>
在文件中添加内容
<syntaxhighlight lang="bash">
/opt/intel/lib
/opt/intel/mkl/lib/intel64
</syntaxhighlight>
最后使命令生效
<syntaxhighlight lang="bash">
sudo ldconfig
</syntaxhighlight>

== 安装atlas ==
这一步是为了没有安装intel mkl的同学准备的, 如果安装intel mkl, 请跳过。<br />
如果你觉得intel mkl太麻烦了, 你也可以采用简单的做法, 安装atlas。<br />
你只需要敲入一行命令即可。
<syntaxhighlight lang="bash">
sudo apt-get install libatlas-base-dev
</syntaxhighlight>

== 安装opencv ==
请参靠网上的文章

== 安装其他依赖项 ==
caffe需要一些数据库的操作, 因此需要安装leveldb, lmdb, hdf5等库, 此外, caffe采用了google的一些库, 比如protobuf以及glog, 这些也需要安装。
<syntaxhighlight lang="bash">
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
</syntaxhighlight>

== 安装python ==
caffe的可视化接口是用python写的, 另外做测试的时候也需要用到python代码。 因此推荐安装。<br />
安装之前, 请参靠网上的文章, 用virtualenv新建一个python环境, 否则可能会搞乱!<br />
<br />
首先, 采用你新建的python环境。 假设你的python环境名就是cp
<syntaxhighlight lang="bash">
source path_to_cp/bin/active
</syntaxhighlight>
其次, 进入caffe安装目录中的python文件夹, 你会看到一个requirements.txt, 首先, 修改protobuf那一行为<code>protobuf==2.5.0</code>, 然后采用如下命令:
<syntaxhighlight lang="bash">
for req in $(cat requirements.txt); do pip install $req; done
</syntaxhighlight>
可能一次运行有些选项安装时会报错, 不过可以多运行几次命令, 直到所有选项都被安装。<br />
<br />
另注, anaconda包不推荐安装, 因为安装之后进不去桌面。anaconda包只是一个自带了requirements.txt中所有选项的python集合库, 将上面的库安装好之后, 不装anaconda没有任何影响。

== 安装matlab ==
大家下载ubuntu版本的matlab安装即可。

== 更改caffe config==
终于到这一步了。 首先, 复制一份config以防写错。
<syntaxhighlight lang="bash">
cp Makefile.config.example Makefile.config
</syntaxhighlight>
其次, 大家可以参考我的配置。
<syntaxhighlight lang="bash">
## 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

# 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 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_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := mkl
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
BLAS_INCLUDE := /opt/intel/mkl/include
BLAS_LIB := /opt/intel/mkl/lib/intel64

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

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib/x86_64-linux-gnu
# PYTHON_LIB := $(ANACONDA_HOME)/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
# LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

# 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

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 ?= @
</syntaxhighlight>
最后, 大家使用
<syntaxhighlight lang="bash">
make all -j20 # 20线程编译
make alltest -j20 # 编译测试
make runtest # 运行测试
make pycaffe # 编译caffe python接口
make matcaffe # 编译 matlab接口
</syntaxhighlight>

== 结束 ==

我写的大部分参考自

http://www.cnblogs.com/platero/p/3993877.html

https://wiki.qut.edu.au/display/cyphy/Caffe+Installation+on+Ubuntu+12.04

谢谢大家

内容概要:本文深入研究了基于深度强化学习(DRL)的微网储能系统控制策略。首先介绍了微网系统的组成及其特性,重点探讨了光伏发电、储能系统和负荷系统的关键组件数学模型。接着详细描述了Simulink仿真设计实现,包括微网环境模拟类(MicrogridEnv)、双重深度Q网络(Double DQN)算法的实现以及训练过程。为了验证该方法的有效性,文章还进行了对比实验,分别测试了规则策略、传统优化方法和DDQN策略的表现。实验结果显示,DDQN策略在成本节约、SOC合规率等方面明显优于其他两种方法。最后,本文提出了创新点与贡献总结,包括仿真-学习一体化框架、改进的DRL算法以及多维度验证,并展望了后续研究方向如多时间尺度优化、多能源协同、不确定性处理等。 适用人群:从事电力系统、微网技术研究的专业人士,以及对深度强化学习应用于能源领域感兴趣的科研人员和工程师。 使用场景及目标:①掌握微网储能系统的基本构成与工作原理;②理解如何利用深度强化学习优化微网储能控制策略;③学习具体的算法实现细节,包括环境搭建、DDQN算法实现和训练流程;④对比不同控制策略的效果,评估DDQN策略的优势。 其他说明:本文不仅提供了理论分析和技术实现,还展示了详细的实验验证过程,通过具体的实验数据证明了所提方法的有效性。此外,文中提及的多种改进措施和技术细节对于实际工程项目具有重要的参考价值。阅读本文有助于读者全面了解微网储能控制领域的最新进展,为相关研究和技术开发提供有益的指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值