@@ -47,14 +47,21 @@ void ProposalLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
4747 top_shape.push_back (1 );
4848 top_shape.push_back (5 );
4949 top[0 ]->Reshape (top_shape);
50+ if (top.size () > 1 )
51+ {
52+ vector<int > top_shape1 (2 , 1 );
53+ top_shape1.push_back (1 );
54+ top_shape1.push_back (1 );
55+ top[1 ]->Reshape (top_shape1);
56+ }
5057}
5158
5259template <typename Dtype>
5360void ProposalLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
5461 const vector<Blob<Dtype>*>& top) {
55- const Dtype* score = bottom[0 ]->cpu_data ();
56- const Dtype* bbox_deltas = bottom[1 ]->cpu_data ();
57- const Dtype* im_info = bottom[2 ]->cpu_data ();
62+ const Dtype* score = bottom[0 ]->cpu_data (); // data order [n,c,h,w]
63+ const Dtype* bbox_deltas = bottom[1 ]->cpu_data (); // data order [n,c,h,w]
64+ const Dtype* im_info = bottom[2 ]->cpu_data (); // data order [h,w,c]
5865 int height = bottom[0 ]->height ();
5966 int width = bottom[0 ]->width ();
6067 // float thresh = 0.3; //
@@ -63,7 +70,7 @@ void ProposalLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
6370 vector<vector<float > > bbox;
6471 int anchor_num = anchor_scale_.size ()*anchor_ratio_.size ();
6572
66- // TODO: data order is different from python version, may need adjustment
73+ // TODO: stored data order is different from python version, may need adjustment
6774 for (int k = 0 ; k < anchor_num; k++)
6875 {
6976 float w = anchor_boxes_[4 * k + 2 ] - anchor_boxes_[4 * k] + 1 ;
@@ -132,6 +139,20 @@ void ProposalLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
132139 top_data[5 * i + 3 ] = pred_boxes[index][2 ];
133140 top_data[5 * i + 4 ] = pred_boxes[index][3 ];
134141 }
142+
143+ if (top.size () > 1 )
144+ {
145+ vector<int > score_shape;
146+ score_shape.push_back (num);
147+ score_shape.push_back (1 );
148+ top[1 ]->Reshape (score_shape);
149+ Dtype* top_data1 = top[1 ]->mutable_cpu_data ();
150+ for (int i = 0 ; i < num; i++)
151+ {
152+ int index = indices[i];
153+ top_data1[i] = confidence[index];
154+ }
155+ }
135156}
136157
137158
@@ -302,6 +323,7 @@ void ProposalLayer<Dtype>::applynmsfast(vector<vector<float> > &pred_boxes, vect
302323 indices.resize (top_k);
303324}
304325
326+ /*
305327template <typename Dtype>
306328void ProposalLayer<Dtype>::apply_nms(vector<vector<float> > &pred_boxes, vector<float> &confidence)
307329{
@@ -342,7 +364,7 @@ void ProposalLayer<Dtype>::apply_nms(vector<vector<float> > &pred_boxes, vector<
342364 }
343365 }
344366}
345-
367+ */
346368
347369INSTANTIATE_CLASS (ProposalLayer);
348370REGISTER_LAYER_CLASS (Proposal);
0 commit comments