zuokai / roialign

caffe
17 stars 4 forks source link

how to modify the roi_pooling_layer to have members of pad_ratio, bi_type and is_multi_interpolate #1

Closed yunren closed 6 years ago

yunren commented 7 years ago

Hi, thanks for your sharing codes. However,when i compile my caffe with roi_align_layer, there are some errors in roi_align_layer.cpp. Namely, pad_ratio, bi_type, is_multi_interpolate is not the members of caffe:ROIPoolingParameter. How to modify?

zuokai commented 7 years ago

add these members in caffe.proto. (我不清楚你懂不懂中文,如果懂的话,我说详细点, 1,你找一下src文件夹下面的caffe.proto文件 2,你搜一下ROIPoolingParameter 3,在里面加这些字段(bi_type是0代表双线性,1代表双三次,is_multi_interpolate是true代表4次插值,false代表单次插值))

yunren commented 7 years ago

感谢您的耐心解答,谢谢。 请问下 那个pad_ratio代表的啥?一般怎么设置啊?

zuokai commented 6 years ago

不好意思,很久没来看了,pad_ratio表示的将roi上下左右各扩大百分之多少,目的是增加roi区域。因为有的研究表明(具体哪篇文章忘了),增大roi区域,空间上的上下文信息,可以帮助判断物体类别。(比如,如果有一条鱼,增大roi区域,roi中包含了鱼缸,可帮助判断这是一条鱼)。一般会用2个roipooling层,1个pad_ratio设置为0,1个设置为大于0的值,这两个roipooling层的输出concat。

yunren commented 6 years ago

原来是这个意思,明白了,感谢您的回复

chl916185 commented 6 years ago

您好,能分享下src文件夹下面的caffe.proto文件以及,roi_pooling_layer使用的实例吗, @zuokai @yunren

zuokai commented 6 years ago

roipooling在caffe.proto中的写法,在happynear的caffe-windows里面有,在prototxt里面 layer { bottom: "conv4_3" bottom: "rois" top: "roi_feaures" name: "roipooling" type: "ROIPooling" roi_pooling_param { spatial_scale: 0.0625 pooled_h: 7 pooled_w: 7 } } 其中bottom: "rois"在训练时是rpnproposaltarget层的输出,预测时是proposal层的输出。训练时多了正负样本筛选的工作。spatial_scale: 0.0625表示conv4_3是总stride=16的卷积层。rois是原图中的位置,因此需要spatial_scale把roi映射到feature map的对应位置。 你可以参考https://github.com/zhaoweicai/mscnn/blob/master/examples/kitti_car/mscnn-7s-384/mscnn_deploy.prototxt 这个是C++版本可以直接跑的检测模型。你可以看看

18191171661 commented 6 years ago

@zuokai ,首先感谢你分享了ROIAlign层的实现代码。我的一个项目需要用到ROIAlign层,但是我编译的window_caffe版本没有这个层,我知道xxx.cpp、xxx.cu和xxx.h的放置位置,但是我不知道如何在 caffe.proto中添加内容,麻烦您详细的说明一下。除此之外,你能给出一个ROIAlign层的使用样例嘛?谢谢您。

zuokai commented 6 years ago

@18191171661 可以参考下面: 在caffe.proto中找到下面这个ROIPoolingParameter, 修改如下: message ROIPoolingParameter { // Pad, kernel size, and stride are all given as a single value for equal // dimensions in height and width or as Y, X pairs. optional uint32 pooled_h = 1 [default = 0]; // The pooled output height optional uint32 pooled_w = 2 [default = 0]; // The pooled output width // Multiplicative spatial scale factor to translate ROI coords from their // input scale to the scale used when pooling optional float spatial_scale = 3 [default = 1]; optional float pad_ratio = 4 [default = 0]; optional uint32 bi_type = 5 [default = 0]; optional bool is_multi_interpolate = 6 [default = True]; } ROIAlign使用如下: layer { bottom: "conv4_3" bottom: "rois" top: "roi_feaures" name: "roialign" type: "ROIAlign" roi_pooling_param { spatial_scale: 0.0625 pooled_h: 7 pooled_w: 7 bi_type: 0 #如果是默认值可以不设置 is_multi_interpolate: True #如果是默认值可以不设置 } } 你试一下,因为我转tf已经大半年了,不确定是不是写完整了,如果有问题,你可以再问我。

18191171661 commented 6 years ago

@zuokai @yunren ,您好,感谢您的回复。我在使用ROIAlign层时,遇到了其它的问题,希望能够得到您的帮助。 我按照您说的方法在编译ROIAlign层时出现如下的问题:pad_ratio, bi_type, is_multi_interpolate is not the members of 。我可以确认在caffe.proto中的ROIPoolingParameter部分添加了对应的参数,但是编译时仍然会报错。 message ROIPoolingParameter { // Pad, kernel size, and stride are all given as a single value for equal // dimensions in height and width or as Y, X pairs. optional uint32 pooled_h = 1 [default = 0]; // The pooled output height optional uint32 pooled_w = 2 [default = 0]; // The pooled output width // Multiplicative spatial scale factor to translate ROI coords from their // input scale to the scale used when pooling optional float spatial_scale = 3 [default = 1]; optional float pad_ratio = 4 [default = 0]; optional uint32 bi_type = 5 [default = 0]; optional bool is_multi_interpolate = 6 [default = True]; } 另外,我使用的是happynear的caffe-windows版本,您的这种方法相当于替换掉了里面的ROIPooling层,我想要保留这两个,因此,我将roi_align_layer.cpp做了相应的修改, template void ROIAlignLayer::LayerSetUp(const vector<Blob>& bottom, const vector<Blob>& top) { ROIAlignParameter roi_align_param = this->layerparam.roi_align_param(); CHECK_GT(roi_align_param.pooled_h(), 0) << "pooled_h must be > 0"; CHECK_GT(roi_align_param.pooled_w(), 0) << "pooled_w must be > 0"; pooledheight = roi_align_param.pooled_h(); pooledwidth = roi_align_param.pooled_w(); spatialscale = roi_align_param.spatial_scale(); padratio = roi_align_param.pad_ratio(); bi_type = roi_align_param.bi_type(); is_multi_interpolate = roi_align_param.is_multi_interpolate(); LOG(INFO) << "Spatial scale: " << spatialscale;

}

在 caffe.proto文件中增加了如下代码: message ROIAlignParameter { // Pad, kernel size, and stride are all given as a single value for equal // dimensions in height and width or as Y, X pairs. optional uint32 pooled_h = 1 [default = 0]; // The pooled output height optional uint32 pooled_w = 2 [default = 0]; // The pooled output width // Multiplicative spatial scale factor to translate ROI coords from their // input scale to the scale used when pooling optional float spatial_scale = 3 [default = 1]; optional float pad_ratio = 4 [default = 0]; optional uint32 bi_type = 5 [default = 0]; optional bool is_multi_interpolate = 6 [default = True]; } 并对该模块进行了注册, optional ROIAlignParameter roi_align_param = 242; 但是在用vs2015编译的时候仍然会出现以下的错误: 错误 C2039“pad_ratio”: 不是“caffe::ROIAlignParameter”的成员 libcaffe E:\caffe-windows-use\caffe-windows-ms\src\caffe\layers\roi_align_layer.cpp 74
我自己尝试了很久,仍然没有解决这个问题,希望能够得到您的帮助,谢谢您,如果您方便的话,加下我的QQ:1575262785,我想要咨询您一些问题。

zuokai commented 6 years ago

你生成新的proto.pb.cc和proto.pb.hh了吗?