MCPcopy Create free account
hub / github.com/ChenhongyiYang/QueryDet-PyTorch / decode_dets

Method decode_dets

models/querydet/detector.py:498–535  ·  view source on GitHub ↗
(self, cls_results, reg_results, anchors)

Source from the content-addressed store, hash-verified

496 return images
497
498 def decode_dets(self, cls_results, reg_results, anchors):
499 boxes_all = []
500 scores_all = []
501 class_idxs_all = []
502
503 for cls_i, reg_i, anchors_i in zip(cls_results, reg_results, anchors):
504 cls_i = cls_i.view(-1, self.num_classes)
505 reg_i = reg_i.view(-1, 4)
506
507 cls_i = cls_i.flatten().sigmoid_() # (HxWxAxK,)
508 num_topk = min(self.topk_candidates, reg_i.size(0))
509
510 predicted_prob, topk_idxs = cls_i.sort(descending=True)
511 predicted_prob = predicted_prob[:num_topk]
512 topk_idxs = topk_idxs[:num_topk]
513
514 # filter out the proposals with low confidence score
515 keep_idxs = predicted_prob > self.score_threshold
516 predicted_prob = predicted_prob[keep_idxs]
517 topk_idxs = topk_idxs[keep_idxs]
518
519 anchor_idxs = topk_idxs // self.num_classes
520 classes_idxs = topk_idxs % self.num_classes
521 predicted_class = classes_idxs
522
523 reg_i = reg_i[anchor_idxs]
524 anchors_i = anchors_i[anchor_idxs]
525
526 if type(anchors_i) != torch.Tensor:
527 anchors_i = anchors_i.tensor
528
529 predicted_boxes = self.box2box_transform.apply_deltas(reg_i, anchors_i)
530
531 boxes_all.append(predicted_boxes)
532 scores_all.append(predicted_prob)
533 class_idxs_all.append(predicted_class)
534
535 return boxes_all, scores_all, class_idxs_all
536
537

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected