From d9b219a7ebf25ced8bb1bcd46bf11b6f287b3393 Mon Sep 17 00:00:00 2001 From: shangliang Xu Date: Sat, 2 Apr 2022 21:14:27 +0800 Subject: [PATCH] [PPYOLOE] alter eval_input_size (#5569) --- configs/ppyoloe/_base_/ppyoloe_crn.yml | 1 - configs/ppyoloe/_base_/ppyoloe_reader.yml | 10 +++++++--- ppdet/modeling/heads/ppyoloe_head.py | 14 +++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/configs/ppyoloe/_base_/ppyoloe_crn.yml b/configs/ppyoloe/_base_/ppyoloe_crn.yml index 2ad9a11a8..447a4618e 100644 --- a/configs/ppyoloe/_base_/ppyoloe_crn.yml +++ b/configs/ppyoloe/_base_/ppyoloe_crn.yml @@ -28,7 +28,6 @@ PPYOLOEHead: grid_cell_offset: 0.5 static_assigner_epoch: 100 use_varifocal_loss: True - eval_input_size: [640, 640] loss_weight: {class: 1.0, iou: 2.5, dfl: 0.5} static_assigner: name: ATSSAssigner diff --git a/configs/ppyoloe/_base_/ppyoloe_reader.yml b/configs/ppyoloe/_base_/ppyoloe_reader.yml index a7574de1f..058b4ee47 100644 --- a/configs/ppyoloe/_base_/ppyoloe_reader.yml +++ b/configs/ppyoloe/_base_/ppyoloe_reader.yml @@ -1,4 +1,8 @@ worker_num: 4 +eval_height: &eval_height 640 +eval_width: &eval_width 640 +eval_size: &eval_size [*eval_height, *eval_width] + TrainReader: sample_transforms: - Decode: {} @@ -20,17 +24,17 @@ TrainReader: EvalReader: sample_transforms: - Decode: {} - - Resize: {target_size: [640, 640], keep_ratio: False, interp: 2} + - Resize: {target_size: *eval_size, keep_ratio: False, interp: 2} - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True} - Permute: {} batch_size: 2 TestReader: inputs_def: - image_shape: [3, 640, 640] + image_shape: [3, *eval_height, *eval_width] sample_transforms: - Decode: {} - - Resize: {target_size: [640, 640], keep_ratio: False, interp: 2} + - Resize: {target_size: *eval_size, keep_ratio: False, interp: 2} - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True} - Permute: {} batch_size: 1 diff --git a/ppdet/modeling/heads/ppyoloe_head.py b/ppdet/modeling/heads/ppyoloe_head.py index 97b96259d..393709eb5 100644 --- a/ppdet/modeling/heads/ppyoloe_head.py +++ b/ppdet/modeling/heads/ppyoloe_head.py @@ -45,7 +45,7 @@ class ESEAttn(nn.Layer): @register class PPYOLOEHead(nn.Layer): - __shared__ = ['num_classes', 'trt', 'exclude_nms'] + __shared__ = ['num_classes', 'eval_size', 'trt', 'exclude_nms'] __inject__ = ['static_assigner', 'assigner', 'nms'] def __init__(self, @@ -61,7 +61,7 @@ class PPYOLOEHead(nn.Layer): static_assigner='ATSSAssigner', assigner='TaskAlignedAssigner', nms='MultiClassNMS', - eval_input_size=[], + eval_size=None, loss_weight={ 'class': 1.0, 'iou': 2.5, @@ -80,7 +80,7 @@ class PPYOLOEHead(nn.Layer): self.iou_loss = GIoULoss() self.loss_weight = loss_weight self.use_varifocal_loss = use_varifocal_loss - self.eval_input_size = eval_input_size + self.eval_size = eval_size self.static_assigner_epoch = static_assigner_epoch self.static_assigner = static_assigner @@ -127,7 +127,7 @@ class PPYOLOEHead(nn.Layer): self.proj.reshape([1, self.reg_max + 1, 1, 1])) self.proj_conv.weight.stop_gradient = True - if self.eval_input_size: + if self.eval_size: anchor_points, stride_tensor = self._generate_anchors() self.register_buffer('anchor_points', anchor_points) self.register_buffer('stride_tensor', stride_tensor) @@ -164,8 +164,8 @@ class PPYOLOEHead(nn.Layer): if feats is not None: _, _, h, w = feats[i].shape else: - h = int(self.eval_input_size[0] / stride) - w = int(self.eval_input_size[1] / stride) + h = int(self.eval_size[0] / stride) + w = int(self.eval_size[1] / stride) shift_x = paddle.arange(end=w) + self.grid_cell_offset shift_y = paddle.arange(end=h) + self.grid_cell_offset shift_y, shift_x = paddle.meshgrid(shift_y, shift_x) @@ -181,7 +181,7 @@ class PPYOLOEHead(nn.Layer): return anchor_points, stride_tensor def forward_eval(self, feats): - if self.eval_input_size: + if self.eval_size: anchor_points, stride_tensor = self.anchor_points, self.stride_tensor else: anchor_points, stride_tensor = self._generate_anchors(feats) -- GitLab