Ubuntu14.04下编译pycaffe并绘制网络结构图

前言

由于课题需要,编译了Caffe的python接口。下面的博客内容就将整个过程和遇到的问题记录下来,若是各位看官遇到了相似的情况可能会给你带来帮助。

1. 环境准备

sudo apt-get update
sudo apt-get install python-pip puthon-dev python numpy
sudo apt-get install python-pip python-dev python-numpy
sudo apt-get install gfortran
sudo pip install -r $caffe_root/python/requirements.txt

说明:$caffe_root是指caffe的目录,也就是解压的目录。在进行上面安装,当到安装IPython(对Python2.7.x)的时候可能会出现限免的情况导致安装不成功。

IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2.
    When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
    Beginning with IPython 6.0, Python 3.3 and above is required.
    
    See IPython `README.rst` file for more information:
    
        https://github.com/ipython/ipython/blob/master/README.rst
    
    Python sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0) detected.
    Your pip version is out of date, please install pip >= 9.0.1. pip 1.5.4 detected.
    
    Complete output from command python setup.py egg_info:    

IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2.
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
Beginning with IPython 6.0, Python 3.3 and above is required.

这里是说我们安装的IPython的版本太高了,需要安装IPython5左右的。这里就有两种办法去解决:
办法1:源码安装

wget https://codeload.github.com/ipython/ipython/zip/5.x -o ipython-5.x.zip
unzip ipython-5.x.zip
cd ipython-5.x
# The [test] extra ensures test dependencies are installed too:
pip install .[test]
#Do not invoke setup.py directly as this can have undesirable consequences for further upgrades. We do not recommend using easy_install either.
ln -sf /usr/local/bin/ipython /usr/bin/ipython
ipython -V

方法二:不知道那个版本可以用,那就让系统来做

sudo pip install ipython==8888 #现指定一个不存在的版本以查看可用版本,发现5版本中有5.3.0(你的可能不一样)

就会出现这些可用的版本供你选择
Ubuntu14.04下编译pycaffe并绘制网络结构图_第1张图片
之后我们选择一个可用的版本就好了。ref:http://www.jianshu.com/p/8779eac7f313

sudo pip install ipython==5.0.0
sudo pip install pydot

2. 编译pycaffe

这里的编译就比较简单了

make clean
make -j4
make pycaffe

3. 绘制网络结构图

这里以绘制mnist使用的网络结构为例进行绘制网络结构。当前命令所在的目录在$caffe_root/python/下

python draw_net.py ../examples/mnist/lenet.prototxt mnist.png

可能会出现如下错误

Drawing net to mnist.png
Traceback (most recent call last):
  File "draw_net.py", line 58, in 
    main()
  File "draw_net.py", line 54, in main
    phase)
  File "/home/sucker/Desktop/install_pakages/caffe-1.0/python/caffe/draw.py", line 244, in draw_net_to_file
    fid.write(draw_net(caffe_net, rankdir, ext, phase))
  File "/home/sucker/Desktop/install_pakages/caffe-1.0/python/caffe/draw.py", line 223, in draw_net
    return get_pydot_graph(caffe_net, rankdir, phase=phase).create(format=ext)
  File "/usr/local/lib/python2.7/dist-packages/pydot.py", line 1883, in create
    prog=prog))
Exception: "dot" not found in path.

解决办法

sudo apt-get install graphviz

生成的网络结构图
网络结构

你可能感兴趣的:(Caffe,ubuntu,PyCaffe,编译)