deepsort.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import absolute_import
  15. from __future__ import division
  16. from __future__ import print_function
  17. import paddle
  18. from ppdet.core.workspace import register, create
  19. from .meta_arch import BaseArch
  20. from ppdet.modeling.mot.utils import Detection, get_crops, scale_coords, clip_box
  21. __all__ = ['DeepSORT']
  22. @register
  23. class DeepSORT(BaseArch):
  24. """
  25. DeepSORT network, see https://arxiv.org/abs/1703.07402
  26. Args:
  27. detector (object): detector model instance
  28. reid (object): reid model instance
  29. tracker (object): tracker instance
  30. """
  31. __category__ = 'architecture'
  32. def __init__(self,
  33. detector='YOLOv3',
  34. reid='PCBPyramid',
  35. tracker='DeepSORTTracker'):
  36. super(DeepSORT, self).__init__()
  37. self.detector = detector
  38. self.reid = reid
  39. self.tracker = tracker
  40. @classmethod
  41. def from_config(cls, cfg, *args, **kwargs):
  42. if cfg['detector'] != 'None':
  43. detector = create(cfg['detector'])
  44. else:
  45. detector = None
  46. reid = create(cfg['reid'])
  47. tracker = create(cfg['tracker'])
  48. return {
  49. "detector": detector,
  50. "reid": reid,
  51. "tracker": tracker,
  52. }
  53. def _forward(self):
  54. crops = self.inputs['crops']
  55. outs = {}
  56. outs['embeddings'] = self.reid(crops)
  57. return outs
  58. def get_pred(self):
  59. return self._forward()