【发布时间】:2017-02-03 10:46:02
【问题描述】:
我使用的是 caffe,它没有本地连接层。那么关于如何使用 im2col 层、reshape 层和内积层来实现本地连接层的任何示例?谢谢
【问题讨论】:
标签: deep-learning caffe
我使用的是 caffe,它没有本地连接层。那么关于如何使用 im2col 层、reshape 层和内积层来实现本地连接层的任何示例?谢谢
【问题讨论】:
标签: deep-learning caffe
我也尝试过使用Crop、Im2col、Reshape和InnerProduct层来实现本地连接层但失败。
因为当我想使用InnerProduct层实现卷积操作时,我发现在InnerProductLayer<Dtype>::Forward_cpu()函数中:
caffe_cpu_gemm<Dtype>(CblasNoTrans, transpose_ ? CblasNoTrans : CblasTrans,
M_, N_, K_, (Dtype)1.,
bottom_data, weight, (Dtype)0., top_data);
在BaseConvolutionLayer<Dtype>::forward_cpu_gemm()函数中:
caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, conv_out_channels_ /
group_, conv_out_spatial_dim_, kernel_dim_,
(Dtype)1., weights + weight_offset_ * g, col_buff + col_offset_ * g,
(Dtype)0., output + output_offset_ * g);
应该用作卷积核的weight(s) 被传递给caffe_cpu_gemm() 的不同参数。
所以我无法使用InnerProductLayer<Dtype>::Forward_cpu() 函数实现卷积运算,因此无法使用Crop、Im2col、Reshape 和InnerProduct 实现局部连接层(这里指的是局部卷积)层。
但是,我实现了一个局部卷积层here,其想法是将输入特征图划分为N*N 网格(即使有重叠),并使用不同的内核对每个网格执行卷积。例如,输入的特征图有一个形状(2, 3, 8, 8),你想将空间特征图8*8划分为16个2*2局部区域,然后用不同的内核库对每个局部区域进行卷积,你可以写一个像这样的prototxt:
layer {
name: "local_conv"
type: "LocalConvolution"
bottom: "bottom" # shape (2,3,8,8)
top: "top"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
local_conv_param {
local_region_number_h: 4
local_region_number_w: 4
local_region_ratio_h: 0.3 # determin the height/width of local regions
local_region_ratio_w: 0.3 # local_region_size = floor(local_region_ratio * input_size)
local_region_step_h: 2 # step between local regions on the top left part
# and other regions will lie in the axial symmetry positions
# automatically
local_region_step_w: 2
num_output: 5
kernel_h: 3
kernel_w: 1
stride: 1
pad: 0
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
您可以轻松地将这一层添加到您的caffe,相关文件如下:
include/caffe/layers/local_conv_layer.hpp
src/caffe/layers/local_conv_layer.cpp(cu)
您还应该将message LocalConvolutionParameter、optional LocalConvolutionParameter local_conv_param 从src/caffe/proto/caffe.proto 添加到您的caffe.proto。
.
【讨论】:
num x channel x height x width。所以如果我理解正确的话,你的本地连接层的输入应该是num x 32 x 7 x 7,这个层是支持的。