| 239 | struct RPNOps : public NodeOps |
| 240 | { |
| 241 | bool Run(Node* node) |
| 242 | { |
| 243 | const Tensor* score_tensor = node->GetInputTensor(0); |
| 244 | const Tensor* featmap_tensor = node->GetInputTensor(1); |
| 245 | const Tensor* info_tensor = node->GetInputTensor(2); |
| 246 | Tensor* output_tensor = node->GetOutputTensor(0); |
| 247 | TShape& out_shape = output_tensor->GetShape(); |
| 248 | |
| 249 | float* output = ( float* )get_tensor_mem(output_tensor); |
| 250 | const float* im_info = ( float* )get_tensor_mem(info_tensor); |
| 251 | const float* m_score_ = ( float* )get_tensor_mem(score_tensor); |
| 252 | const float* m_box_ = ( float* )get_tensor_mem(featmap_tensor); |
| 253 | |
| 254 | const TShape& featmap_shape = featmap_tensor->GetShape(); |
| 255 | const TShape& score_shape = score_tensor->GetShape(); |
| 256 | const int feat_height = featmap_shape.GetH(); |
| 257 | const int feat_width = featmap_shape.GetW(); |
| 258 | const int feat_channel = featmap_shape.GetC(); |
| 259 | const int score_channel = score_shape.GetC(); |
| 260 | const int feat_size = feat_height * feat_width; |
| 261 | int src_height_ = im_info[0]; |
| 262 | int src_width_ = im_info[1]; |
| 263 | int src_scale_ = im_info[2]; |
| 264 | |
| 265 | RPN* RPN_op = dynamic_cast<RPN*>(node->GetOp()); |
| 266 | RPNParam* param_ = RPN_op->GetParam(); |
| 267 | int feat_stride = param_->feat_stride; |
| 268 | int num_anchors = ( int )param_->anchors_.size(); |
| 269 | |
| 270 | // local_anchors (1, anchors_nums_ * 4, map_height_, map_width_); |
| 271 | float* local_anchors = new float[num_anchors * 4 * feat_size]; |
| 272 | proposal_local_anchor(feat_height, feat_width, feat_stride, param_->anchors_, local_anchors); |
| 273 | |
| 274 | float* m_box = new float[feat_channel * feat_size]; |
| 275 | for(int i = 0; i < feat_channel * feat_size; i++) |
| 276 | m_box[i] = m_box_[i]; |
| 277 | bbox_tranform_inv(m_box, local_anchors, feat_height, feat_width, feat_channel, num_anchors); |
| 278 | |
| 279 | delete[] local_anchors; |
| 280 | std::vector<SBox> boxes; |
| 281 | float* m_score = new float[score_channel * feat_size]; |
| 282 | for(int i = 0; i < score_channel * feat_size; i++) |
| 283 | m_score[i] = m_score_[i]; |
| 284 | filter_boxs(boxes, m_box, m_score, param_->min_size, src_scale_, src_width_, src_height_, feat_width, |
| 285 | feat_height, num_anchors, feat_channel); |
| 286 | delete[] m_box; |
| 287 | delete[] m_score; |
| 288 | |
| 289 | std::sort(boxes.rbegin(), boxes.rend()); |
| 290 | |
| 291 | if(param_->per_nms_topn > 0) |
| 292 | { |
| 293 | int tmp = MIN(param_->per_nms_topn, ( int )boxes.size()); |
| 294 | boxes.erase(boxes.begin() + tmp, boxes.end()); |
| 295 | } |
| 296 | nms_rpn(boxes, param_->nms_thresh); |
| 297 | |
| 298 | if(param_->post_nms_topn > 0) |
nothing calls this directly
no test coverage detected