diff --git a/deploy/pptracking/python/det_infer.py b/deploy/pptracking/python/det_infer.py index c52879453027e099d25cd0388083eb57d1f8aeea..cf99f0d70ac6c3f3989ea38a529197ff29fd23d8 100644 --- a/deploy/pptracking/python/det_infer.py +++ b/deploy/pptracking/python/det_infer.py @@ -39,6 +39,7 @@ from mot_utils import argsparser, Timer, get_current_memory_mb # Global dictionary SUPPORT_MODELS = { 'YOLO', + 'PPYOLOE', 'PicoDet', 'JDE', 'FairMOT', diff --git a/deploy/python/infer.py b/deploy/python/infer.py index 6136d0db1564436b054f230250a23bd9e6f4fe49..df206f22b59a796a59b44a0b3e8489c2d89e339b 100644 --- a/deploy/python/infer.py +++ b/deploy/python/infer.py @@ -40,10 +40,10 @@ from utils import argsparser, Timer, get_current_memory_mb, multiclass_nms, coco # Global dictionary SUPPORT_MODELS = { - 'YOLO', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', 'S2ANet', 'JDE', - 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', 'TOOD', 'RetinaNet', - 'StrongBaseline', 'STGCN', 'YOLOX', 'YOLOF', 'PPHGNet', 'PPLCNet', 'DETR', - 'CenterTrack' + 'YOLO', 'PPYOLOE', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', + 'S2ANet', 'JDE', 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', + 'TOOD', 'RetinaNet', 'StrongBaseline', 'STGCN', 'YOLOX', 'YOLOF', 'PPHGNet', + 'PPLCNet', 'DETR', 'CenterTrack' } TUNED_TRT_DYNAMIC_MODELS = {'DETR'} diff --git a/deploy/serving/python/web_service.py b/deploy/serving/python/web_service.py index 05b559a41ca91757ec0446f3b3ec487d46184a75..08be7d2c61904b3d3d2e21643c7eaddd3581f48b 100644 --- a/deploy/serving/python/web_service.py +++ b/deploy/serving/python/web_service.py @@ -30,9 +30,9 @@ import yaml # Global dictionary SUPPORT_MODELS = { - 'YOLO', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', 'S2ANet', 'JDE', - 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', 'TOOD', 'RetinaNet', - 'StrongBaseline', 'STGCN', 'YOLOX', 'HRNet' + 'YOLO', 'PPYOLOE', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', + 'S2ANet', 'JDE', 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', + 'TOOD', 'RetinaNet', 'StrongBaseline', 'STGCN', 'YOLOX', 'HRNet' } GLOBAL_VAR = {} diff --git a/deploy/third_engine/demo_onnx_trt/trt_infer.py b/deploy/third_engine/demo_onnx_trt/trt_infer.py index e48f144cde7f24662cb118ba665fb0c1ba3e9a60..2d1381f2553c8fed9b702295f1db0ab83a68c71a 100644 --- a/deploy/third_engine/demo_onnx_trt/trt_infer.py +++ b/deploy/third_engine/demo_onnx_trt/trt_infer.py @@ -51,9 +51,9 @@ TRT_LOGGER = trt.Logger() trt.init_libnvinfer_plugins(TRT_LOGGER, namespace="") # Global dictionary SUPPORT_MODELS = { - 'YOLO', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', 'S2ANet', 'JDE', - 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', 'TOOD', 'RetinaNet', - 'StrongBaseline', 'STGCN', 'YOLOX', 'HRNet' + 'YOLO', 'PPYOLOE', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', + 'S2ANet', 'JDE', 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', + 'TOOD', 'RetinaNet', 'StrongBaseline', 'STGCN', 'YOLOX', 'HRNet' } @@ -205,8 +205,8 @@ def create_trt_bindings(engine, context): "is_input": True if engine.binding_is_input(name) else False } if engine.binding_is_input(name): - bindings[name]['cpu_data'] = np.random.randn( - *shape).astype(np.float32) + bindings[name]['cpu_data'] = np.random.randn(*shape).astype( + np.float32) bindings[name]['cuda_ptr'] = cuda.mem_alloc(bindings[name][ 'cpu_data'].nbytes) else: diff --git a/deploy/third_engine/onnx/infer.py b/deploy/third_engine/onnx/infer.py index 9dbe2bde9e0d9e90639f53331a91fdecbeaefb8b..e916af9d016c72b7964f980a1a623d5d7e8ab8a1 100644 --- a/deploy/third_engine/onnx/infer.py +++ b/deploy/third_engine/onnx/infer.py @@ -23,9 +23,9 @@ from preprocess import Compose # Global dictionary SUPPORT_MODELS = { - 'YOLO', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', 'S2ANet', 'JDE', - 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', 'TOOD', 'RetinaNet', - 'StrongBaseline', 'STGCN', 'YOLOX', 'HRNet' + 'YOLO', 'PPYOLOE', 'RCNN', 'SSD', 'Face', 'FCOS', 'SOLOv2', 'TTFNet', + 'S2ANet', 'JDE', 'FairMOT', 'DeepSORT', 'GFL', 'PicoDet', 'CenterNet', + 'TOOD', 'RetinaNet', 'StrongBaseline', 'STGCN', 'YOLOX', 'HRNet' } parser = argparse.ArgumentParser(description=__doc__) diff --git a/ppdet/engine/export_utils.py b/ppdet/engine/export_utils.py index 136bea3411dee26b8acbe3d0de5d549de5784655..eb8e181690b507e0851a25134a2662b9a51e7d3c 100644 --- a/ppdet/engine/export_utils.py +++ b/ppdet/engine/export_utils.py @@ -29,6 +29,7 @@ logger = setup_logger('ppdet.engine') # Global dictionary TRT_MIN_SUBGRAPH = { 'YOLO': 3, + 'PPYOLOE': 3, 'SSD': 60, 'RCNN': 40, 'RetinaNet': 40, @@ -193,7 +194,7 @@ def _dump_infer_config(config, path, image_shape, model): arch_state = True break - if infer_arch in ['YOLOX', 'YOLOF']: + if infer_arch in ['PPYOLOE', 'YOLOX', 'YOLOF']: infer_cfg['arch'] = infer_arch infer_cfg['min_subgraph_size'] = TRT_MIN_SUBGRAPH[infer_arch] arch_state = True diff --git a/ppdet/modeling/architectures/__init__.py b/ppdet/modeling/architectures/__init__.py index 83ab3e0ad842ab473325f9854934f219158a0450..c89106c4f5f0b69fca11676fd297177938d99fa1 100644 --- a/ppdet/modeling/architectures/__init__.py +++ b/ppdet/modeling/architectures/__init__.py @@ -16,6 +16,7 @@ from . import meta_arch from . import faster_rcnn from . import mask_rcnn from . import yolo +from . import ppyoloe from . import cascade_rcnn from . import ssd from . import fcos @@ -44,6 +45,7 @@ from .meta_arch import * from .faster_rcnn import * from .mask_rcnn import * from .yolo import * +from .ppyoloe import * from .cascade_rcnn import * from .ssd import * from .fcos import * diff --git a/ppdet/modeling/architectures/ppyoloe.py b/ppdet/modeling/architectures/ppyoloe.py new file mode 100644 index 0000000000000000000000000000000000000000..0d0e926f49bd164382b9707efd5d44211e9beaec --- /dev/null +++ b/ppdet/modeling/architectures/ppyoloe.py @@ -0,0 +1,99 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from ppdet.core.workspace import register, create +from .meta_arch import BaseArch + +__all__ = ['PPYOLOE'] +# PP-YOLOE and PP-YOLOE+ are recommended to use this architecture +# PP-YOLOE and PP-YOLOE+ can also use the same architecture of YOLOv3 in yolo.py + + +@register +class PPYOLOE(BaseArch): + __category__ = 'architecture' + __inject__ = ['post_process'] + + def __init__(self, + backbone='CSPResNet', + neck='CustomCSPPAN', + yolo_head='PPYOLOEHead', + post_process='BBoxPostProcess', + for_mot=False): + """ + PPYOLOE network, see https://arxiv.org/abs/2203.16250 + + Args: + backbone (nn.Layer): backbone instance + neck (nn.Layer): neck instance + yolo_head (nn.Layer): anchor_head instance + post_process (object): `BBoxPostProcess` instance + for_mot (bool): whether return other features for multi-object tracking + models, default False in pure object detection models. + """ + super(PPYOLOE, self).__init__() + self.backbone = backbone + self.neck = neck + self.yolo_head = yolo_head + self.post_process = post_process + self.for_mot = for_mot + + @classmethod + def from_config(cls, cfg, *args, **kwargs): + # backbone + backbone = create(cfg['backbone']) + + # fpn + kwargs = {'input_shape': backbone.out_shape} + neck = create(cfg['neck'], **kwargs) + + # head + kwargs = {'input_shape': neck.out_shape} + yolo_head = create(cfg['yolo_head'], **kwargs) + + return { + 'backbone': backbone, + 'neck': neck, + "yolo_head": yolo_head, + } + + def _forward(self): + body_feats = self.backbone(self.inputs) + neck_feats = self.neck(body_feats, self.for_mot) + + if self.training: + yolo_losses = self.yolo_head(neck_feats, self.inputs) + return yolo_losses + else: + yolo_head_outs = self.yolo_head(neck_feats) + if self.post_process is not None: + bbox, bbox_num = self.post_process( + yolo_head_outs, self.yolo_head.mask_anchors, + self.inputs['im_shape'], self.inputs['scale_factor']) + else: + bbox, bbox_num = self.yolo_head.post_process( + yolo_head_outs, self.inputs['scale_factor']) + output = {'bbox': bbox, 'bbox_num': bbox_num} + + return output + + def get_loss(self): + return self._forward() + + def get_pred(self): + return self._forward() diff --git a/ppdet/modeling/architectures/yolo.py b/ppdet/modeling/architectures/yolo.py index f23f0ddd4f7decf4f1c3d304f661c74884207dec..78c7654913c683108d96fa55c8f9bf450cfbc961 100644 --- a/ppdet/modeling/architectures/yolo.py +++ b/ppdet/modeling/architectures/yolo.py @@ -21,6 +21,8 @@ from .meta_arch import BaseArch from ..post_process import JDEBBoxPostProcess __all__ = ['YOLOv3'] +# YOLOv3,PP-YOLO,PP-YOLOv2,PP-YOLOE,PP-YOLOE+ use the same architecture as YOLOv3 +# PP-YOLOE and PP-YOLOE+ are recommended to use PPYOLOE architecture in ppyoloe.py @register @@ -99,6 +101,7 @@ class YOLOv3(BaseArch): yolo_head_outs = self.yolo_head(neck_feats) if self.for_mot: + # the detection part of JDE MOT model boxes_idx, bbox, bbox_num, nms_keep_idx = self.post_process( yolo_head_outs, self.yolo_head.mask_anchors) output = { @@ -110,13 +113,16 @@ class YOLOv3(BaseArch): } else: if self.return_idx: + # the detection part of JDE MOT model _, bbox, bbox_num, _ = self.post_process( yolo_head_outs, self.yolo_head.mask_anchors) elif self.post_process is not None: + # anchor based YOLOs: YOLOv3,PP-YOLO,PP-YOLOv2 use mask_anchors bbox, bbox_num = self.post_process( yolo_head_outs, self.yolo_head.mask_anchors, self.inputs['im_shape'], self.inputs['scale_factor']) else: + # anchor free YOLOs: PP-YOLOE, PP-YOLOE+ bbox, bbox_num = self.yolo_head.post_process( yolo_head_outs, self.inputs['scale_factor']) output = {'bbox': bbox, 'bbox_num': bbox_num}