一、caffe 这个框架就不介绍了,学习deeplearning的人可以不知道tensorflow ,pytorch,但是不能不知道caffe!
二、caffe 框架内置了很多的layer,利用 prototxt进行调用及网络结构设计!
每一层,都需要通过设定如下的参数进行调整!看起来会比现在的很多利用python的框架麻烦,现在的很多框架想要实现一层卷积,基本上就是一行代码:
self.conv=Conv2d(3,64,3,1,false)
x=self.conv(input)
layer {
name: "your layer name"
type: "Convolution"
bottom: "input data"
top: "output data"
param {
lr_mult: 4.0
decay_mult: 1
}
param {
lr_mult: 8.0
decay_mult: 0
}
convolution_param {
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
}
num_output: 21
pad: 0
kernel_size: 1
}
}
虽然caffe的网络结构定义上很麻烦,但是不得不承认,这样写:1、很清晰的定义了各种参数 2、配合上可视化工具,网络结构能够一目了然 http://ethereon.github.io/netscope/#/editor ,这个工具的存在,让我一度成为caffe的舔狗!
三、对于很多人,不喜欢caffe主要是以下两点
1、安装麻烦~~~这个其实如果熟悉了原因,其实直接进去make,非常方便。修改好makefile,makefile.config。。。主要大多数都是卡在了opencv上,其实好好弄个独立的opencv,把makefile.config好好改好,直接进入caffe目录,直接通过。cudnn不配合?把这个caffe的于cudnn相关的各种文件全部,全部换成可以用的版本的就可以了!
2、没办法想pytorch一样直接调试,甚至去查看每一层的输入输出,查看他们的数据size,进行可视化!其实很方便!!!!
简历如下文件xxx.py
import sys
sys.path.append("/home/oujie/Desktop/caffe_train/python")
import caffe
import numpy as np
import logging
import matplotlib.pyplot as plt
class DebugLayer(caffe.Layer):
"""
Outputs object detection proposals by applying estimated bounding-box
transformations to a set of regular boxes (called "anchors").
"""
def setup(self, bottom, top):
self.file=open("/home/oujie/Desktop/caffe_train/python_layer/log.txt",'a+')
def forward(self, bottom, top):
data1=bottom[0].data
data2=bottom[1].data
data3=bottom[2].data
data4=bottom[3].data
data5=bottom[4].data
data6=bottom[5].data
data7=bottom[6].data
data8=bottom[7].data
data9=bottom[8].data
data10=bottom[9].data
data11=bottom[10].data
data12=bottom[11].data
data13=bottom[12].data
data14=bottom[13].data
data15=bottom[14].data
data16=bottom[15].data
data17=bottom[16].data
L2=[data10.sum(),data11.sum(),data12.sum(),data13.sum(),data14.sum(),data15.sum(),data16.sum(),data17.sum()]
self.file.write(str(L2)+"\n")
print(data5.shape)
print(data6.shape)
print(data9[7,0,:,:].min(),data9[7,0,:,:].max())
plt.imshow(data7[7,:,:,:].sum(axis=0))
plt.show()
plt.imshow(data4[7,:,:,:].sum(axis=0))
plt.show()
plt.imshow(data5[7,:,:,:].sum(axis=0))
plt.show()
plt.imshow(data6[7,:,:,:].sum(axis=0))
plt.show()
plt.imshow(data8[7,0,:,:])
plt.show()
plt.imshow(data9[7,0,:,:])
plt.show()
assert 1==2,L2
#print(data.sum())
def backward(self, top, propagate_down, bottom):
"""This layer does not propagate gradients."""
pass
def reshape(self, bottom, top):
"""Reshaping happens during the call to forward."""
pass
然后进行调用:
layer{
name: "debug"
type: "Python"
bottom: "vec_weight"
bottom: "weight_stage0_L2"
bottom: "weight_stage1_L1"
bottom: "Mconv6_stage2_L2"
bottom: "label_heat"
bottom: "label_vec"
bottom: "image"
bottom: "heat_weight"
bottom: "vec_weight"
bottom: "Mconv6_stage0_L2"
bottom: "Mconv6_stage1_L2"
bottom: "Mconv6_stage2_L2"
bottom: "Mconv6_stage3_L2"
bottom: "Mconv7_stage0_L2"
bottom: "Mconv7_stage1_L2"
bottom: "Mconv7_stage2_L2"
bottom: "Mconv7_stage3_L2"
python_param {
module: 'debug_layer' #这个就是你那个 xxx.py的不带py的文件名
layer: 'DebugLayer' #这个就是那个class name
}
}
然后直接 build/caffe train --solver .....