Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nms_cpu for layout_picodet #8453

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PicoDet:
backbone: LCNet
neck: CSPPAN
head: PicoHead
nms_cpu: True

LCNet:
scale: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PicoDet:
backbone: LCNet
neck: CSPPAN
head: PicoHead
nms_cpu: True

LCNet:
scale: 2.5
Expand Down
8 changes: 6 additions & 2 deletions ppdet/modeling/architectures/picodet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -69,7 +70,10 @@ def _forward(self):
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, ):
Expand Down
20 changes: 17 additions & 3 deletions ppdet/modeling/heads/pico_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def __init__(self,
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:
Expand Down Expand Up @@ -397,7 +398,11 @@ def _generate_anchors(self, feats=None):
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
Expand All @@ -409,7 +414,12 @@ def post_process(self, head_outs, scale_factor, export_nms=True):
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


Expand Down Expand Up @@ -767,7 +777,11 @@ def _generate_anchors(self, feats=None):
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
Expand Down