From eda775852131cd560c5f337c75f30bebf9c809a9 Mon Sep 17 00:00:00 2001 From: Laughing <61612323+Laughing-q@users.noreply.github.com> Date: Mon, 19 Jun 2023 22:09:06 +0800 Subject: [PATCH] [RTDETR]fix "Grad strides do not match bucket view strides" when training with DDP (#3255) --- ultralytics/nn/modules/transformer.py | 2 +- ultralytics/vit/utils/ops.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/ultralytics/nn/modules/transformer.py b/ultralytics/nn/modules/transformer.py index 89a7d91..b3304cc 100644 --- a/ultralytics/nn/modules/transformer.py +++ b/ultralytics/nn/modules/transformer.py @@ -77,7 +77,7 @@ class AIFI(TransformerEncoderLayer): pos_embed = self.build_2d_sincos_position_embedding(w, h, c) # flatten [B, C, H, W] to [B, HxW, C] x = super().forward(x.flatten(2).permute(0, 2, 1), pos=pos_embed.to(device=x.device, dtype=x.dtype)) - return x.permute((0, 2, 1)).view([-1, c, h, w]) + return x.permute(0, 2, 1).view([-1, c, h, w]).contiguous() @staticmethod def build_2d_sincos_position_embedding(w, h, embed_dim=256, temperature=10000.): diff --git a/ultralytics/vit/utils/ops.py b/ultralytics/vit/utils/ops.py index 6585987..e8978a5 100644 --- a/ultralytics/vit/utils/ops.py +++ b/ultralytics/vit/utils/ops.py @@ -31,9 +31,6 @@ class HungarianMatcher(nn.Module): _cost_mask(bs, num_gts, masks=None, gt_mask=None): Computes the mask cost and dice cost if masks are predicted. """ - class HungarianMatcher(nn.Module): - ... - def __init__(self, cost_gain=None, use_fl=True, with_mask=False, num_sample_points=12544, alpha=0.25, gamma=2.0): super().__init__() if cost_gain is None: