Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 1208|回复: 0

安装caffe(CPU版本)的一些参考和问题的解决

[复制链接]
  • TA的每日心情
    奋斗
    3 小时前
  • 签到天数: 742 天

    [LV.9]以坛为家II

    2037

    主题

    2095

    帖子

    70万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    703644
    发表于 2021-9-8 11:49:16 | 显示全部楼层 |阅读模式

    1.安装前的预备工作

      依次按照一下命令安装:

        

     1 sudo apt-get install libprotobuf-dev 
     2 sudo apt-get install libleveldb-dev 
     3 sudo apt-get install libsnappy-dev 
     4 sudo apt-get install libopencv-dev 
     5 sudo apt-get install libhdf5-serial-dev 
     6 sudo apt-get install protobuf-compiler
     7 sudo apt-get install --no-install-recommends libboost-all-dev
     8 sudo apt-get install libatlas-base-dev
     9 sudo apt-get install python-dev
    10 sudo apt-get install libgflags-dev
    11 sudo apt-get install libgoogle-glog-dev 
    12 sudo apt-get install liblmdb-dev

    2.下载caffe源码

      在github上下载

      

    git clone https://github.com/BVLC/caffe.git

     

      接着装caffe要求装的一些依赖库(如requirements.txt【$caffe_root/python】中的内容所示):

    Cython>=0.19.2
    numpy>=1.7.1
    scipy>=0.13.2
    scikit-image>=0.9.3
    matplotlib>=1.3.1
    ipython>=3.0.0
    h5py>=2.2.0
    leveldb>=0.191
    networkx>=1.8.1
    nose>=1.3.0
    pandas>=0.12.0
    python-dateutil>=1.4,<2
    protobuf>=2.5.0
    python-gflags>=2.0
    pyyaml>=3.10
    Pillow>=2.3.0
    six>=1.1.0

      可以自己一个一个装,也可以通过以下命令:

    1 pip install -r requirements.txt

    3.编译caffe

      3.1 使用Cmake编译

        进入caffe根目录,创建一个build文件夹并进入

     

    1 mkdir build && cd build

     

          进行cmake

    cmake -DCPU_ONLY=1 .. 

          接着make

    make -j"$(nproc)"

       3.2 使用make编译(我使用的这种)

        首先因为我们需要的是CPU版本的caffe,因此需要对Makefile进行修改,我们先创建一个副本

     

    1 cp Makefile.config.example Makefile.config

     

          接着对内容进行修改

         我们去掉CPU_ONLY前面的注释

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

     

     

     

     

     

        接着python的文件路径需要我们修改

     

    # 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
    
    修改为
    
    PYTHON_INCLUDE := /usr/include/python2.7 \
            /usr/local/lib/python2.7/dist-packages/numpy/core/include

     

          hdf5库的路径也需要添加

     

    # Whatever else you find you need goes here.
    INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
    LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
    
    修改为
    
    # 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

     

          同时Makefile中的关于hdf5的内容也需要修改

     

    LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
    
    修改为
    
    LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

     

          不然可能会出现以下错误

     

    /usr/bin/ld: cannot find -lhdf5_hl
    /usr/bin/ld: cannot find -lhdf5
    collect2: error: ld returned 1 exit status

     

          接着开始编译过程

     

    make pycaffe
    make all
    make test
    make runtest

     

          可在其后加上-j"$(nproc)"以加快速度

         可能在进行make runtest时出现一些错误,但若前三个命令没有错误出现,就不妨碍使用(暂时没发现什么妨碍的地方)

     

    4.配置环境变量

      在.bashrc中配置环境变量

      

    sudo gedit ~/.bashrc

     

      在后面加上

     

    export PYTHONPATH=/your path/caffe/python:$PYTHONPATH

     

      接着

     

    source ~/.bashrc

     

    5.测试

     

    Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import caffe
    >>> dir(caffe)
    ['AdaDeltaSolver', 'AdaGradSolver', 'AdamSolver', 'Classifier', 'Detector', 'Layer', 'NCCL', 'NesterovSolver', 'Net', 'NetSpec', 'RMSPropSolver', 'SGDSolver', 'TEST', 'TRAIN', 'Timer', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_caffe', 'classifier', 'detector', 'get_solver', 'has_nccl', 'init_log', 'io', 'layer_type_list', 'layers', 'log', 'net_spec', 'params', 'proto', 'pycaffe', 'set_device', 'set_mode_cpu', 'set_mode_gpu', 'set_multiprocess', 'set_random_seed', 'set_solver_count', 'set_solver_rank', 'solver_count', 'solver_rank', 'to_proto']
    >>> 

     

      没问题,OK~

     

    官方github:https://github.com/BVLC/caffe

    官方安装文档:http://caffe.berkeleyvision.org/installation.html

    参考:https://blog.csdn.net/muzilinxi90/article/details/53673184

     

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-3-19 16:22 , Processed in 0.065473 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表