caffe中基于VGG16制作跳层连接网络报错
error in making skip-layer connection network based on VGG16 in caffe
目前正在看'CMS-RCNN: Contextual Multi-Scale Region-based CNN for Unconstrained Face Detection'上的论文,是用skip-connection将conv3-3,conv4-3,conv5-3融合在一起,步骤如下
提取面部区域的特征图(多尺度 conv3-3、conv4-3、conv5-3)并对其应用 RoI-Pooling(即转换为固定的高度和宽度)。
L2-归一化每个特征图。
将面部(多尺度)的(RoI 池化和归一化)特征图相互连接(创建一个张量)。
对面部张量应用 1x1 卷积。
将两个完全连接的层应用于面部张量,创建一个向量。
我用caffe做了一个基于faster-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"
层您遇到了问题:
您从中复制权重的原始网络具有 "fc6"
层,输入维度为 10368。另一方面,您的 "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 将从头开始学习权重(仅针对该层)。
目前正在看'CMS-RCNN: Contextual Multi-Scale Region-based CNN for Unconstrained Face Detection'上的论文,是用skip-connection将conv3-3,conv4-3,conv5-3融合在一起,步骤如下
提取面部区域的特征图(多尺度 conv3-3、conv4-3、conv5-3)并对其应用 RoI-Pooling(即转换为固定的高度和宽度)。 L2-归一化每个特征图。 将面部(多尺度)的(RoI 池化和归一化)特征图相互连接(创建一个张量)。 对面部张量应用 1x1 卷积。 将两个完全连接的层应用于面部张量,创建一个向量。
我用caffe做了一个基于faster-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"
层您遇到了问题:
您从中复制权重的原始网络具有 "fc6"
层,输入维度为 10368。另一方面,您的 "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 将从头开始学习权重(仅针对该层)。