在 caffe 中基于 VGG16 制作跳层连接网络时出错



我目前正在阅读关于"CMS-RCNN:用于无约束人脸检测的基于区域的上下文多尺度CNN"的论文,它正在使用跳过连接将conv3-3,conv4-3和conv5-3融合在一起,步骤如下所示

提取面部区域的特征图(在多个比例下 conv3-3、conv4-3、conv5-3)并对其应用 RoI 池化(即转换为固定的高度和宽度)。 L2 规范化每个特征图。 将人脸的(RoI池化和归一化)特征图(在多个尺度上)相互连接(创建一个张量)。 对面张量应用 1x1 卷积。 将两个完全连接的层应用于面张量,创建一个向量。

我使用了咖啡并基于更快的RCNN VGG16制作了一个prototxt,以下部分被添加到原始prototxt

# roi pooling the conv3-3 layer and L2 normalize it 
layer {
name: "roi_pool3"
type: "ROIPooling"
bottom: "conv3_3"
bottom: "rois"
top: "pool3_roi"
roi_pooling_param {
pooled_w: 7
pooled_h: 7
spatial_scale: 0.25 # 1/4
}
}
layer {
name:"roi_pool3_l2norm"
type:"L2Norm"
bottom: "pool3_roi"
top:"pool3_roi"
}
-------------
# roi pooling the conv4-3 layer and L2 normalize it 

layer {
name: "roi_pool4"
type: "ROIPooling"
bottom: "conv4_3"
bottom: "rois"
top: "pool4_roi"
roi_pooling_param {
pooled_w: 7
pooled_h: 7
spatial_scale: 0.125 # 1/8
}
}
layer {
name:"roi_pool4_l2norm"
type:"L2Norm"
bottom: "pool4_roi"
top:"pool4_roi"
}
--------------------------
# roi pooling the conv5-3 layer and L2 normalize it 
layer {
name: "roi_pool5"
type: "ROIPooling"
bottom: "conv5_3"
bottom: "rois"
top: "pool5"
roi_pooling_param {
pooled_w: 7
pooled_h: 7
spatial_scale: 0.0625 # 1/16
}
}

layer {
name:"roi_pool5_l2norm"
type:"L2Norm"
bottom: "pool5"
top:"pool5"
}

# concat roi_pool3, roi_pool4, roi_pool5 and apply 1*1 conv

layer {
name:"roi_concat"
type: "Concat"
concat_param {
axis: 1
}
bottom: "pool5"
bottom: "pool4_roi"
bottom: "pool3_roi"      
top:"roi_concat"
}
layer {
name:"roi_concat_1*1_conv"
type:"Convolution"
top:"roi_concat_1*1_conv"
bottom:"roi_concat"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 128
pad: 1
kernel_size: 1
weight_filler{
type:"xavier"
}
bias_filler{
type:"constant"        
}
}
}
layer {
name: "fc6"
type: "InnerProduct"
bottom: "roi_concat_1*1_conv"
top: "fc6"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 4096
}
}

在培训期间,我遇到了这样的问题

F0616 16:43:02.899025  3712 net.cpp:757] Cannot copy param 0 weights from layer 'fc6'; shape mismatch.  Source param shape is 1 1 4096 25088 (102760448); target param shape is 4096 10368 (42467328).
To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.

我可以找出问题所在,但如果您需要发现一些问题或解释,我需要您的帮助。

真的很感激!!

您收到的错误消息非常清楚。您正在尝试微调图层的权重,但对于"fc6"图层,您遇到了一个问题:
您从中复制权重的原始网络具有输入维度为 10368 的图层"fc6"。另一方面,"fc6"图层的输入维度为 25088。如果输入维度不同,则不能使用相同的W矩阵(也称为此图层的param 0)。

现在您知道了问题,请再次查看错误消息:

Cannot copy param 0 weights from layer 'fc6'; shape mismatch.  
Source param shape is 1 1 4096 25088 (102760448); 
target param shape is 4096 10368 (42467328).

Caffe 无法复制"fc6"W矩阵 (param 0),其形状与您尝试微调的 .caffemodel 中存储的W的形状不匹配。

你能做什么?
只需阅读错误消息的下一行:

To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.

只需重命名图层,caffe 将从头开始学习权重(仅适用于此图层)。

最新更新