From 1e5372e993c17955d3545983e0346d5f717cac2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haian=20Huang=28=E6=B7=B1=E5=BA=A6=E7=9C=B8=29?= <1286304229@qq.com> Date: Wed, 17 May 2023 19:39:43 +0800 Subject: [PATCH] fix gardcam error using in mmdet (#779) --- mmyolo/utils/boxam_utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mmyolo/utils/boxam_utils.py b/mmyolo/utils/boxam_utils.py index 4a46f21c1..50d6c09ec 100644 --- a/mmyolo/utils/boxam_utils.py +++ b/mmyolo/utils/boxam_utils.py @@ -202,8 +202,10 @@ def __call__(self, *args, **kwargs): if self.is_need_loss: # Maybe this is a direction that can be optimized # self.detector.init_weights() - - self.detector.bbox_head.head_module.training = True + if hasattr(self.detector.bbox_head, 'head_module'): + self.detector.bbox_head.head_module.training = True + else: + self.detector.bbox_head.training = True if hasattr(self.detector.bbox_head, 'featmap_sizes'): # Prevent the model algorithm error when calculating loss self.detector.bbox_head.featmap_sizes = None @@ -219,7 +221,10 @@ def __call__(self, *args, **kwargs): return [loss] else: - self.detector.bbox_head.head_module.training = False + if hasattr(self.detector.bbox_head, 'head_module'): + self.detector.bbox_head.head_module.training = False + else: + self.detector.bbox_head.training = False with torch.no_grad(): results = self.detector.test_step(self.input_data) return results