diff --git a/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml b/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml index db9a8c683adc74ed043472d3d0e8fbb4c3b537f5..251a3dd58b42311ab4e9c90466b7822ade5f6d01 100644 --- a/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml +++ b/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml @@ -17,6 +17,7 @@ PicoDet: backbone: LCNet neck: CSPPAN head: PicoHead + nms_cpu: True LCNet: scale: 1.0 diff --git a/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml b/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml index b6d771f618b5f4b9b4569f55930863cf6644c2b2..a30807fb9cfc9b64ce4e3a078546116340a81468 100644 --- a/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml +++ b/configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml @@ -10,6 +10,7 @@ PicoDet: backbone: LCNet neck: CSPPAN head: PicoHead + nms_cpu: True LCNet: scale: 2.5 diff --git a/ppdet/modeling/architectures/picodet.py b/ppdet/modeling/architectures/picodet.py index 0b87a4baa429dae1c03286f09243ca3211b199df..b6f44472a4f8adb4fd708cc3e8d443699daa12ae 100644 --- a/ppdet/modeling/architectures/picodet.py +++ b/ppdet/modeling/architectures/picodet.py @@ -36,13 +36,14 @@ class PicoDet(BaseArch): __category__ = 'architecture' - def __init__(self, backbone, neck, head='PicoHead'): + def __init__(self, backbone, neck, head='PicoHead', nms_cpu=False): super(PicoDet, self).__init__() self.backbone = backbone self.neck = neck self.head = head self.export_post_process = True self.export_nms = True + self.nms_cpu = nms_cpu @classmethod def from_config(cls, cfg, *args, **kwargs): @@ -69,7 +70,10 @@ class PicoDet(BaseArch): else: scale_factor = self.inputs['scale_factor'] bboxes, bbox_num = self.head.post_process( - head_outs, scale_factor, export_nms=self.export_nms) + head_outs, + scale_factor, + export_nms=self.export_nms, + nms_cpu=self.nms_cpu) return bboxes, bbox_num def get_loss(self, ): diff --git a/ppdet/modeling/heads/pico_head.py b/ppdet/modeling/heads/pico_head.py index adcd05fc6b21b5ff50bc97e6e4385da0442e5a39..6e04173f5a08e804ee7d474c7927c96cc78dfb9c 100644 --- a/ppdet/modeling/heads/pico_head.py +++ b/ppdet/modeling/heads/pico_head.py @@ -242,6 +242,7 @@ class PicoHead(OTAVFLHead): self.nms_pre = nms_pre self.cell_offset = cell_offset self.eval_size = eval_size + self.device = paddle.device.get_device() self.use_sigmoid = self.loss_vfl.use_sigmoid if self.use_sigmoid: @@ -397,7 +398,11 @@ class PicoHead(OTAVFLHead): stride_tensor = paddle.concat(stride_tensor) return anchor_points, stride_tensor - def post_process(self, head_outs, scale_factor, export_nms=True): + def post_process(self, + head_outs, + scale_factor, + export_nms=True, + nms_cpu=False): pred_scores, pred_bboxes = head_outs if not export_nms: return pred_bboxes, pred_scores @@ -409,7 +414,12 @@ class PicoHead(OTAVFLHead): axis=-1).reshape([-1, 1, 4]) # scale bbox to origin image size. pred_bboxes /= scale_factor - bbox_pred, bbox_num, _ = self.nms(pred_bboxes, pred_scores) + if nms_cpu: + paddle.set_device("cpu") + bbox_pred, bbox_num, _ = self.nms(pred_bboxes, pred_scores) + paddle.set_device(self.device) + else: + bbox_pred, bbox_num, _ = self.nms(pred_bboxes, pred_scores) return bbox_pred, bbox_num @@ -767,7 +777,11 @@ class PicoHeadV2(GFLHead): stride_tensor = paddle.concat(stride_tensor) return anchor_points, stride_tensor - def post_process(self, head_outs, scale_factor, export_nms=True): + def post_process(self, + head_outs, + scale_factor, + export_nms=True, + nms_cpu=False): pred_scores, pred_bboxes = head_outs if not export_nms: return pred_bboxes, pred_scores