bytetrack.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (c) 2022 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. from ppdet.core.workspace import register, create
  18. from .meta_arch import BaseArch
  19. __all__ = ['ByteTrack']
  20. @register
  21. class ByteTrack(BaseArch):
  22. """
  23. ByteTrack network, see https://arxiv.org/abs/2110.06864
  24. Args:
  25. detector (object): detector model instance
  26. reid (object): reid model instance, default None
  27. tracker (object): tracker instance
  28. """
  29. __category__ = 'architecture'
  30. def __init__(self,
  31. detector='YOLOX',
  32. reid=None,
  33. tracker='JDETracker'):
  34. super(ByteTrack, self).__init__()
  35. self.detector = detector
  36. self.reid = reid
  37. self.tracker = tracker
  38. @classmethod
  39. def from_config(cls, cfg, *args, **kwargs):
  40. detector = create(cfg['detector'])
  41. if cfg['reid'] != 'None':
  42. reid = create(cfg['reid'])
  43. else:
  44. reid = None
  45. tracker = create(cfg['tracker'])
  46. return {
  47. "detector": detector,
  48. "reid": reid,
  49. "tracker": tracker,
  50. }
  51. def _forward(self):
  52. det_outs = self.detector(self.inputs)
  53. if self.training:
  54. return det_outs
  55. else:
  56. if self.reid is not None:
  57. assert 'crops' in self.inputs
  58. crops = self.inputs['crops']
  59. pred_embs = self.reid(crops)
  60. else:
  61. pred_embs = None
  62. det_outs['embeddings'] = pred_embs
  63. return det_outs
  64. def get_loss(self):
  65. return self._forward()
  66. def get_pred(self):
  67. return self._forward()