From 30a2de164bcb991057b212b47846ea3c13715ee5 Mon Sep 17 00:00:00 2001 From: Laughing <61612323+Laughing-q@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:04:03 +0800 Subject: [PATCH] Fix `AutoBatch` when working with RT-DETR models (#18912) --- ultralytics/models/utils/ops.py | 2 +- ultralytics/utils/torch_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ultralytics/models/utils/ops.py b/ultralytics/models/utils/ops.py index eafc7440..7133072e 100644 --- a/ultralytics/models/utils/ops.py +++ b/ultralytics/models/utils/ops.py @@ -172,7 +172,7 @@ def get_cdn_group( bounding boxes, attention mask and meta information for denoising. If not in training mode or 'num_dn' is less than or equal to 0, the function returns None for all elements in the tuple. """ - if (not training) or num_dn <= 0: + if (not training) or num_dn <= 0 or batch is None: return None, None, None, None gt_groups = batch["gt_groups"] total_num = sum(gt_groups) diff --git a/ultralytics/utils/torch_utils.py b/ultralytics/utils/torch_utils.py index e1cd9de8..1f87ec79 100644 --- a/ultralytics/utils/torch_utils.py +++ b/ultralytics/utils/torch_utils.py @@ -667,7 +667,7 @@ def profile(input, ops, n=10, device=None, max_num_obj=0): m = m.half() if hasattr(m, "half") and isinstance(x, torch.Tensor) and x.dtype is torch.float16 else m tf, tb, t = 0, 0, [0, 0, 0] # dt forward, backward try: - flops = thop.profile(m, inputs=[x], verbose=False)[0] / 1e9 * 2 # GFLOPs + flops = thop.profile(deepcopy(m), inputs=[x], verbose=False)[0] / 1e9 * 2 # GFLOPs except Exception: flops = 0