@@ -28,7 +28,7 @@ namespace phi {
2828
2929template <typename T>
3030std::pair<phi::DenseTensor, phi::DenseTensor> ProposalForOneImage (
31- const phi::CPUContext &ctx ,
31+ const phi::CPUContext &dev_ctx ,
3232 const phi::DenseTensor &im_info_slice,
3333 const phi::DenseTensor &anchors,
3434 const phi::DenseTensor &variances,
@@ -44,7 +44,7 @@ std::pair<phi::DenseTensor, phi::DenseTensor> ProposalForOneImage(
4444 // Sort index
4545 phi::DenseTensor index_t ;
4646 index_t .Resize ({scores_slice.numel ()});
47- int *index = ctx .Alloc <int >(&index_t );
47+ int *index = dev_ctx .Alloc <int >(&index_t );
4848 for (int i = 0 ; i < scores_slice.numel (); ++i) {
4949 index[i] = i;
5050 }
@@ -65,64 +65,65 @@ std::pair<phi::DenseTensor, phi::DenseTensor> ProposalForOneImage(
6565 bbox_sel.Resize ({index_t .numel (), 4 });
6666 anchor_sel.Resize ({index_t .numel (), 4 });
6767 var_sel.Resize ({index_t .numel (), 4 });
68- ctx .Alloc <T>(&scores_sel);
69- ctx .Alloc <T>(&bbox_sel);
70- ctx .Alloc <T>(&anchor_sel);
71- ctx .Alloc <T>(&var_sel);
68+ dev_ctx .Alloc <T>(&scores_sel);
69+ dev_ctx .Alloc <T>(&bbox_sel);
70+ dev_ctx .Alloc <T>(&anchor_sel);
71+ dev_ctx .Alloc <T>(&var_sel);
7272
73- phi::funcs::CPUGather<T>(ctx , scores_slice, index_t , &scores_sel);
74- phi::funcs::CPUGather<T>(ctx , bbox_deltas_slice, index_t , &bbox_sel);
75- phi::funcs::CPUGather<T>(ctx , anchors, index_t , &anchor_sel);
76- phi::funcs::CPUGather<T>(ctx , variances, index_t , &var_sel);
73+ phi::funcs::CPUGather<T>(dev_ctx , scores_slice, index_t , &scores_sel);
74+ phi::funcs::CPUGather<T>(dev_ctx , bbox_deltas_slice, index_t , &bbox_sel);
75+ phi::funcs::CPUGather<T>(dev_ctx , anchors, index_t , &anchor_sel);
76+ phi::funcs::CPUGather<T>(dev_ctx , variances, index_t , &var_sel);
7777
7878 phi::DenseTensor proposals;
7979 proposals.Resize ({index_t .numel (), 4 });
80- ctx.Alloc <T>(&proposals);
81- phi::funcs::BoxCoder<T>(ctx, &anchor_sel, &bbox_sel, &var_sel, &proposals);
80+ dev_ctx.Alloc <T>(&proposals);
81+ phi::funcs::BoxCoder<T>(
82+ dev_ctx, &anchor_sel, &bbox_sel, &var_sel, &proposals);
8283
8384 phi::funcs::ClipTiledBoxes<T>(
84- ctx , im_info_slice, proposals, &proposals, false );
85+ dev_ctx , im_info_slice, proposals, &proposals, false );
8586
8687 phi::DenseTensor keep;
8788 phi::funcs::FilterBoxes<T>(
88- ctx , &proposals, min_size, im_info_slice, true , &keep);
89+ dev_ctx , &proposals, min_size, im_info_slice, true , &keep);
8990 // Handle the case when there is no keep index left
9091 if (keep.numel () == 0 ) {
9192 phi::funcs::SetConstant<phi::CPUContext, T> set_zero;
9293 bbox_sel.Resize ({1 , 4 });
93- ctx .Alloc <T>(&bbox_sel);
94- set_zero (ctx , &bbox_sel, static_cast <T>(0 ));
94+ dev_ctx .Alloc <T>(&bbox_sel);
95+ set_zero (dev_ctx , &bbox_sel, static_cast <T>(0 ));
9596 phi::DenseTensor scores_filter;
9697 scores_filter.Resize ({1 , 1 });
97- ctx .Alloc <T>(&scores_filter);
98- set_zero (ctx , &scores_filter, static_cast <T>(0 ));
98+ dev_ctx .Alloc <T>(&scores_filter);
99+ set_zero (dev_ctx , &scores_filter, static_cast <T>(0 ));
99100 return std::make_pair (bbox_sel, scores_filter);
100101 }
101102
102103 phi::DenseTensor scores_filter;
103104 bbox_sel.Resize ({keep.numel (), 4 });
104105 scores_filter.Resize ({keep.numel (), 1 });
105- ctx .Alloc <T>(&bbox_sel);
106- ctx .Alloc <T>(&scores_filter);
107- phi::funcs::CPUGather<T>(ctx , proposals, keep, &bbox_sel);
108- phi::funcs::CPUGather<T>(ctx , scores_sel, keep, &scores_filter);
106+ dev_ctx .Alloc <T>(&bbox_sel);
107+ dev_ctx .Alloc <T>(&scores_filter);
108+ phi::funcs::CPUGather<T>(dev_ctx , proposals, keep, &bbox_sel);
109+ phi::funcs::CPUGather<T>(dev_ctx , scores_sel, keep, &scores_filter);
109110 if (nms_thresh <= 0 ) {
110111 return std::make_pair (bbox_sel, scores_filter);
111112 }
112113
113114 phi::DenseTensor keep_nms =
114- phi::funcs::NMS<T>(ctx , &bbox_sel, &scores_filter, nms_thresh, eta);
115+ phi::funcs::NMS<T>(dev_ctx , &bbox_sel, &scores_filter, nms_thresh, eta);
115116
116117 if (post_nms_top_n > 0 && post_nms_top_n < keep_nms.numel ()) {
117118 keep_nms.Resize ({post_nms_top_n});
118119 }
119120
120121 proposals.Resize ({keep_nms.numel (), 4 });
121122 scores_sel.Resize ({keep_nms.numel (), 1 });
122- ctx .Alloc <T>(&proposals);
123- ctx .Alloc <T>(&scores_sel);
124- phi::funcs::CPUGather<T>(ctx , bbox_sel, keep_nms, &proposals);
125- phi::funcs::CPUGather<T>(ctx , scores_filter, keep_nms, &scores_sel);
123+ dev_ctx .Alloc <T>(&proposals);
124+ dev_ctx .Alloc <T>(&scores_sel);
125+ phi::funcs::CPUGather<T>(dev_ctx , bbox_sel, keep_nms, &proposals);
126+ phi::funcs::CPUGather<T>(dev_ctx , scores_filter, keep_nms, &scores_sel);
126127
127128 return std::make_pair (proposals, scores_sel);
128129}
0 commit comments