妙算编译Caffe之pycaffe 并实战kaggle人脸关键点识别网络

本文将介绍 TK1 如何安装 pip工具 并成功import numpy 与 caffe (python2.7)

我在import caffe之后,即兴在TK1上写下了教程,由于没有中文输入法,用英语写下思路。

tk1 import caffe

step1: export PYTHONPATH=~/caffe-caffe-0.12/python:$PYTHONPATH
step2: you will find you you haven’t install numpy

how to install numpy use pip with the environment of python2.7 in tk1 32

step1: sudo apt-get install python-pip (now u can use pip tool to install everything you want)    
step2: sudo apt-get install python-numpy
step3: vi ~/.bashrc

Add this command:
export LC_ALL=C

Ok Let’s check it out:

ubuntu@tegra-ubuntu:~$ python
Python 2.7.6 (default, Mar 22 2014, 23:30:12) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 

And try again:
ubuntu@tegra-ubuntu:~/caffe-caffe-0.12$ make pycaffe

Error:

CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
/usr/bin/ld: cannot find -lboost_python
collect2: error: ld returned 1 exit status
make: *** [python/caffe/_caffe.so] Error 1

Solution: input :

ubuntu@tegra-ubuntu:~/caffe-caffe-0.12$ sudo apt-get install libboost-python-dev
[sudo] password for ubuntu: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
	...

Now make pycaffe again:

ubuntu@tegra-ubuntu:~/caffe-caffe-0.12$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
touch python/caffe/proto/__init__.py
PROTOC (python) src/caffe/proto/caffe.proto

open python and test again:

ubuntu@tegra-ubuntu:~/caffe-caffe-0.12$ python
Python 2.7.6 (default, Nov 23 2017, 16:04:23) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import caffe
>>> import numpy

Finially!!! U make it. Leonard~
Notice:
vi ~/.bashrc
add export PYTHONPATH=~/caffe-caffe-0.12/python:$PYTHONPATH
to your caffe path~

Enjoy it~

实战kaggle人脸关键点识别网络

  1. 准备文件kaggle官网上的训练集csv格式,先用python代码转换成HDF5格式
    train.hd5和val.hd5两个文件

  2. 把该文件目录放到一个名字相同后缀为txt里
    在这里插入图片描述
    在这里插入图片描述

  3. 数据准备好了那接下来就是train_val.prototxt 和 solver.prototxt两个重头戏了。

  4. 先写train_val.prototxt,因为solver.prototxt会把它的文件目录添加进去。

train_val.prototxt:

在这里插入图片描述
这里主要是这两个地方,一个是训练的train.txt,另一个是测试的 val.txt路径一定得正确。

solver.prototxt:

在这里插入图片描述
这里主要也是两个地方:
1.是网络文件
2.是存放模型和状态文件的位置

然后
./build/tools/caffe-caffe-0.12 train -solver=examples/fk/solver.prototxt
就开始训练网络并能生成以下模型和状态文件
在这里插入图片描述
每当迭代iteration==5000,共迭代1w次并生成两回。

Notice:

第一点:
“/home/ubuntu/caffe-caffe-0.12/examples/fk/” 放到fk目录下
&
“/home/ubuntu/caffe-caffe-0.12/examples/fk” 放到examples目录下

第二点:
snapshot_prefix:"/home/ubuntu/caffe-caffe-0.12/fk2/"
而不是
snapshot_prefix:"/home/ubuntu/caffe-caffe-0.12/fk2"
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xsy3858/article/details/83240230
今日推荐