Gumpest / YOLOv5-Multibackbone-Compression

YOLOv5 Series Multi-backbone(TPH-YOLOv5, Ghostnet, ShuffleNetv2, Mobilenetv3Small, EfficientNetLite, PP-LCNet, SwinTransformer YOLO), Module(CBAM, DCN), Pruning (EagleEye, Network Slimming), Quantization (MQBench) and Deployment (TensorRT, ncnn) Compression Tool Box.
991 stars 201 forks source link

您好,使用SwimTransformer出错 #36

Open xiaoyi-creator opened 2 years ago

xiaoyi-creator commented 2 years ago

from models.SwinTransformer import SwinTransformerLayer出错, Traceback (most recent call last): File "train.py", line 24, in import test # import test.py to get mAP after each epoch File "/content/drive/My Drive/yolov5-5.0/test.py", line 12, in from models.experimental import attempt_load File "/content/drive/My Drive/yolov5-5.0/models/experimental.py", line 7, in from models.common import Conv, DWConv File "/content/drive/My Drive/yolov5-5.0/models/common.py", line 20, in from models.SwinTransformer import SwinTransformerLayer File "/content/drive/My Drive/yolov5-5.0/models/SwinTransformer.py", line 9, in from timm.models.layers import DropPath, to_2tuple, truncnormal ModuleNotFoundError: No module named 'timm' 请问怎么解决呢?

xiaoyi-creator commented 2 years ago

我通过导入pip install timm的方式解决了这个问题,但是运行还是出现了新的问题 Traceback (most recent call last): File "train.py", line 542, in train(hyp, opt, device, tb_writer) File "train.py", line 88, in train model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create File "/content/drive/My Drive/yolov5-5.0/models/yolo.py", line 85, in init self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch]) # model, savelist File "/content/drive/My Drive/yolov5-5.0/models/yolo.py", line 244, in parsemodel m = nn.Sequential([m(args) for _ in range(n)]) if n > 1 else m(*args) # module File "/content/drive/My Drive/yolov5-5.0/models/common.py", line 308, in init super().init(c1, c2, c2, n, shortcut, g, e) TypeError: init() takes from 3 to 7 positional arguments but 8 were given,正在想办法解决,但是 目前还没成功

xiaoyi-creator commented 2 years ago

下载了您的代码来尝试SWinTr但是还是会报错 Sizes of tensors must match except in dimension 1. Expected size 24 but got size 19 for tensor number 1 in the list.,我尝试修改了一些东西错误消失,但是又出现了写的错误 File "E:\GoogleDownload\YOLOv5-Multibackbone-Compression-main\utils\datasets.py", line 388, in init self.mosaic_border = [-img_size // 2, -img_size // 2] TypeError: bad operand type for unary -: 'list'

Gumpest commented 2 years ago

下载了您的代码来尝试SWinTr但是还是会报错 Sizes of tensors must match except in dimension 1. Expected size 24 but got size 19 for tensor number 1 in the list.,我尝试修改了一些东西错误消失,但是又出现了写的错误 File "E:\GoogleDownload\YOLOv5-Multibackbone-Compression-main\utils\datasets.py", line 388, in init self.mosaic_border = [-img_size // 2, -img_size // 2] TypeError: bad operand type for unary -: 'list'

Fixing...

Gumpest commented 2 years ago

Please git pull again.

xiaoyi-creator commented 2 years ago

使用您的代码训练 Epoch gpu_mem box obj cls labels img_size 0% 0/1701 [00:00<?, ?it/s]/usr/local/lib/python3.7/dist-packages/torch/autocast_mode.py:141: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling') 0/299 0G 0.1069 0.04991 0 5 640: 0% 1/1701 [00:27<12:46:40, 27.06s/it]/usr/local/lib/python3.7/dist-packages/torch/autocast_mode.py:141: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling')会报这个,我放到租用的GPU还是会报; 尝试移植SWImTR到自己的工程任然报错File "/content/drive/My Drive/yolov5-5.0/models/common.py", line 308, in init super().init(c1, c2, c2, n, shortcut, g, e) TypeError: init() takes from 3 to 7 positional arguments but 8 were given。 想问一下您训练的时候使用的GPU型号,我可以去租赁同等算力的GPU尝试一下

XhHello commented 2 years ago

大佬,我添加您的Swin,然后在这个模块的return这一行报错了。 class C3(nn.Module):

CSP Bottleneck with 3 convolutions

def __init__(self, c1, c2, c2o, n=1, shortcut=True, g=1, e=[0.5,0.5], rate=[1.0 for _ in range(12)]):  # ch_in, ch_out, number, shortcut, groups, expansion 
    super().__init__()
    # c_ = int(c2 * e)  # hidden channels
    if isinstance(e,list):
        c1_ = int(c2o * e[0])
        c2_ = int(c2o * e[1])
    else:
        c1_ = int(c2o * e)
        c2_ = int(c2o * e)
    self.cv1 = Conv(c1, c1_, 1, 1)
    print("cv1的尺度", self.cv1)
    self.cv2 = Conv(c1, c2_, 1, 1)
    print("cv2的尺度",self.cv2)
    self.cv3 = Conv(c1_+c2_, c2, 1)  # act=FReLU(c2)
    self.m = nn.Sequential(*[Bottleneck(c1_, c1_, shortcut, g, e=rate[i]) for i in range(n)])
    # self.m = nn.Sequential(*[CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)])

def forward(self, x):
    # print(self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1)).shape)
    return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1))

下面是报错信息,不知您是否遇到过这种问题,我输出了尺度,觉得cat的时候尺度是对得上的啊, 发生异常: RuntimeError (note: full exception trace is shown but execution is paused at: forward) Sizes of tensors must match except in dimension 1. Got 8 and 1 in dimension 2 (The offending index is 1)

Gumpest commented 2 years ago

使用您的代码训练 Epoch gpu_mem box obj cls labels img_size 0% 0/1701 [00:00<?, ?it/s]/usr/local/lib/python3.7/dist-packages/torch/autocast_mode.py:141: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling warnings.warn('User provided device_type of 'cuda', but CUDA is not available. Disabling') 0/299 0G 0.1069 0.04991 0 5 640: 0% 1/1701 [00:27<12:46:40, 27.06s/it]/usr/local/lib/python3.7/dist-packages/torch/autocast_mode.py:141: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling warnings.warn('User provided device_type of 'cuda', but CUDA is not available. Disabling')会报这个,我放到租用的GPU还是会报; 尝试移植SWImTR到自己的工程任然报错File "/content/drive/My Drive/yolov5-5.0/models/common.py", line 308, in init super().init(c1, c2, c2, n, shortcut, g, e) TypeError: init() takes from 3 to 7 positional arguments but 8 were given。 想问一下您训练的时候使用的GPU型号,我可以去租赁同等算力的GPU尝试一下

应该是您移植时的错误,传参出现异常;GPU RTX 3090 *2

Gumpest commented 2 years ago

大佬,我添加您的Swin,然后在这个模块的return这一行报错了。 class C3(nn.Module): # CSP Bottleneck with 3 convolutions def init(self, c1, c2, c2o, n=1, shortcut=True, g=1, e=[0.5,0.5], rate=[1.0 for _ in range(12)]): # ch_in, chout, number, shortcut, groups, expansion super().init() # c = int(c2 e) # hidden channels if isinstance(e,list): c1_ = int(c2o e[0]) c2 = int(c2o * e[1]) else: c1 = int(c2o e) c2_ = int(c2o e) self.cv1 = Conv(c1, c1, 1, 1) print("cv1的尺度", self.cv1) self.cv2 = Conv(c1, c2, 1, 1) print("cv2的尺度",self.cv2) self.cv3 = Conv(c1+c2, c2, 1) # act=FReLU(c2) self.m = nn.Sequential([Bottleneck(c1, c1, shortcut, g, e=rate[i]) for i in range(n)]) # self.m = nn.Sequential([CrossConv(c, c, 3, 1, g, 1.0, shortcut) for _ in range(n)])

def forward(self, x):
    # print(self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1)).shape)
    return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1))

下面是报错信息,不知您是否遇到过这种问题,我输出了尺度,觉得cat的时候尺度是对得上的啊, 发生异常: RuntimeError (note: full exception trace is shown but execution is paused at: forward) Sizes of tensors must match except in dimension 1. Got 8 and 1 in dimension 2 (The offending index is 1)

若是git 最新版的Hub,应该是不会报错的

XhHello commented 2 years ago

大佬,您的意思是,让我重新下载您最新的代码是吗,我是用的5.0版本的yolov5,然后把您写的Swin相关模块,复制到自己代码中,但是报错了。然而,我直接运行昨天刚下载的您的仓库的代码就 可以跑通,这是啥原因啊,是因为我自己用的是5.0版本吗

------------------ 原始邮件 ------------------ 发件人: "Gumpest/YOLOv5-Multibackbone-Compression" @.>; 发送时间: 2021年12月13日(星期一) 晚上7:21 @.>; @.**@.>; 主题: Re: [Gumpest/YOLOv5-Multibackbone-Compression] 您好,使用SwimTransformer出错 (Issue #36)

大佬,我添加您的Swin,然后在这个模块的return这一行报错了。 class C3(nn.Module): # CSP Bottleneck with 3 convolutions def init(self, c1, c2, c2o, n=1, shortcut=True, g=1, e=[0.5,0.5], rate=[1.0 for _ in range(12)]): # ch_in, chout, number, shortcut, groups, expansion super().init() # c = int(c2 e) # hidden channels if isinstance(e,list): c1_ = int(c2o e[0]) c2 = int(c2o * e[1]) else: c1 = int(c2o e) c2_ = int(c2o e) self.cv1 = Conv(c1, c1, 1, 1) print("cv1的尺度", self.cv1) self.cv2 = Conv(c1, c2, 1, 1) print("cv2的尺度",self.cv2) self.cv3 = Conv(c1+c2, c2, 1) # act=FReLU(c2) self.m = nn.Sequential([Bottleneck(c1, c1, shortcut, g, e=rate[i]) for i in range(n)]) # self.m = nn.Sequential([CrossConv(c, c, 3, 1, g, 1.0, shortcut) for _ in range(n)]) def forward(self, x): # print(self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1)).shape) return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1))
下面是报错信息,不知您是否遇到过这种问题,我输出了尺度,觉得cat的时候尺度是对得上的啊, 发生异常: RuntimeError (note: full exception trace is shown but execution is paused at: forward) Sizes of tensors must match except in dimension 1. Got 8 and 1 in dimension 2 (The offending index is 1)

若是git 最新版的Hub,应该是不会报错的

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

XhHello commented 2 years ago

大佬,您的意思是,让我重新下载您最新的代码是吗,我是用的5.0版本的yolov5,然后把您写的Swin相关模块,复制到自己代码中,但是报错了。然而,我直接运行昨天刚下载的您的仓库的代码就 可以跑通,这是啥原因啊,是因为我自己用的是5.0版本吗

xiaoyi-creator commented 2 years ago

我使用了您的代码训练,租用了同等算力的GPU但是还是会报错
File "/user-data/yolov5-5.0/models/SwinTransformer.py", line 88, in forward x = (attn @ v).transpose(1, 2).reshape(B_, N, C) RuntimeError: expected scalar type Float but found Half 不知道为什么

Gumpest commented 2 years ago

我使用了您的代码训练,租用了同等算力的GPU但是还是会报错 File "/user-data/yolov5-5.0/models/SwinTransformer.py", line 88, in forward x = (attn @ v).transpose(1, 2).reshape(B_, N, C) RuntimeError: expected scalar type Float but found Half 不知道为什么

您好,请在命令行中添加 --nohalf即可

xiaoyi-creator commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误

xiaoyi-creator commented 2 years ago

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

Gumpest commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误

您好 请告知一下你的训练命令行,我来试一下

XhHello commented 2 years ago

你好,我是运行的yolo.py文件,没有train,我遇到的问题是,将这个大佬的Swin添加都自己的5.0版本代码中会报错

------------------ 原始邮件 ------------------ 发件人: "Gumpest/YOLOv5-Multibackbone-Compression" @.>; 发送时间: 2021年12月15日(星期三) 上午10:44 @.>; @.**@.>; 主题: Re: [Gumpest/YOLOv5-Multibackbone-Compression] 您好,使用SwimTransformer出错 (Issue #36)

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

xiaoyi-creator commented 2 years ago

我下载了您的程序,但是我使用了自己的数据集,运行命令: python train.py --data my.yaml --weights yolov5s.pt --cfg models/accModels/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml --hyp data/hyps/hyp.visdrone.yaml --epochs 60 --batch-size 2 --img 640 --nohalf 您觉得有可能是我数据集的问题吗 我百度查找相关错误,有说是因为nc的数值不对引起的,但是我检查了数值并没有问题

XhHello commented 2 years ago

Please git pull again.

大佬,请问我将您写的Swin的代码放到我使用的5.0版的v5上会报通道出错,但是我down您的仓库的代码就可以跑,我查看了每一层的通道数,发现5.0版和6.0版是一样的,但是在5.0上就会报错,请问这个是v5版本不同导致的吗,您写的代码 只能在6.0版本上运行吗

Gumpest commented 2 years ago

我下载了您的程序,但是我使用了自己的数据集,运行命令: python train.py --data my.yaml --weights yolov5s.pt --cfg models/accModels/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml --hyp data/hyps/hyp.visdrone.yaml --epochs 60 --batch-size 2 --img 640 --nohalf 您觉得有可能是我数据集的问题吗 我百度查找相关错误,有说是因为nc的数值不对引起的,但是我检查了数值并没有问题

my.yaml 以及/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml都需要改成对应的nc

Gumpest commented 2 years ago

Please git pull again.

大佬,请问我将您写的Swin的代码放到我使用的5.0版的v5上会报通道出错,但是我down您的仓库的代码就可以跑,我查看了每一层的通道数,发现5.0版和6.0版是一样的,但是在5.0上就会报错,请问这个是v5版本不同导致的吗,您写的代码 只能在6.0版本上运行吗

目前是只支持v6版本

yxwhn commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误 你好,我也遇到了同样的问题,请问您现在解决了吗?

yxwhn commented 2 years ago

我下载了您的程序,但是我使用了自己的数据集,运行命令: python train.py --data my.yaml --weights yolov5s.pt --cfg models/accModels/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml --hyp data/hyps/hyp.visdrone.yaml --epochs 60 --batch-size 2 --img 640 --nohalf 您觉得有可能是我数据集的问题吗 我百度查找相关错误,有说是因为nc的数值不对引起的,但是我检查了数值并没有问题

您好,我也遇到了同样的问题,我也是用的自己的数据集,出现了和你一样的问题,请问您解决了吗?

yxwhn commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误

您好 请告知一下你的训练命令行,我来试一下

您好,我也遇到了这个问题。请问这是由于数据集原因引起的吗?现在就是在第一轮计算map时报错

XhHello commented 2 years ago

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我下载作者仓库的代码就可以跑通

XhHello commented 2 years ago

Please git pull again.

大佬,请问我将您写的Swin的代码放到我使用的5.0版的v5上会报通道出错,但是我down您的仓库的代码就可以跑,我查看了每一层的通道数,发现5.0版和6.0版是一样的,但是在5.0上就会报错,请问这个是v5版本不同导致的吗,您写的代码 只能在6.0版本上运行吗

目前是只支持v6版本

5.0版本和6.0版本差别这么大吗,为啥没法跑啊

yxwhn commented 2 years ago

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我下载作者仓库的代码就可以跑通

你用的是自己的数据集吗?

missbook520 commented 2 years ago

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我下载作者仓库的代码就可以跑通

你用的是自己的数据集吗?

我用的是自己的数据集,也是这个问题,请问您解决了吗

XhHello commented 2 years ago

直接使用仓库的代码可以跑通,是自己的数据集

------------------ 原始邮件 ------------------ 发件人: "Gumpest/YOLOv5-Multibackbone-Compression" @.>; 发送时间: 2022年1月9日(星期天) 上午9:49 @.>; @.**@.>; 主题: Re: [Gumpest/YOLOv5-Multibackbone-Compression] 您好,使用SwimTransformer出错 (Issue #36)

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我下载作者仓库的代码就可以跑通

你用的是自己的数据集吗?

我用的是自己的数据集,也是这个问题,请问您解决了吗

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

yxwhn commented 2 years ago

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我下载作者仓库的代码就可以跑通

你用的是自己的数据集吗?

我用的是自己的数据集,也是这个问题,请问您解决了吗

没有解决,希望作者能回复一下,我下载了yolov5 6.0然后吧swintransformer移值过去,就会报这个错误

luohao136486939 commented 2 years ago

在train.py中的img_size 使用默认的,不要640,不要640,不要640

luohao136486939 commented 2 years ago

在train.py中的img_size 使用默认的,不要640,不要640,不要640

在train.py中的img_size 使用默认的,不要640,不要640,不要640

missbook520 commented 2 years ago

请问是作者默认的1536吗,还是train.py中默认的608?

luohao136486939 commented 2 years ago

请问是作者默认的1536吗,还是train.py中默认的608?

train.py中的难道不是不是604么?604我这里能跑

yxwhn commented 2 years ago

请问是作者默认的1536吗,还是train.py中默认的608?

train.py中的难道不是不是604么?604我这里能跑

谢谢,按照你说的,改成默认的就可以跑了,但我想跑640×640的话,需要改哪些东西呢?

ljh9999 commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

ljh9999 commented 2 years ago

请问是作者默认的1536吗,还是train.py中默认的608?

train.py中的难道不是不是604么?604我这里能跑

代码里默认是608不是604吧 parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=608, help='train, val image size (pixels)') 而且作者的baseTrain.sh尺寸是1536

ltz-sss commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

您好!请问您解决这个问题了吗?

Sa-UpWorld commented 2 years ago

RuntimeError: shape '[8, 3, 7, 2, 7, 256]' is invalid for input of size 860160 我也遇到了这个问题,定位到的是swintransformer的x = x.view(B, H // window_size, window_size, W // window_size, window_size, C)程序 请问大佬们解决了吗,我用的自己的训练集,img-size=640跑的,第一轮训练后跑val时候就出现了这个错误

Sa-UpWorld commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误

您好 请告知一下你的训练命令行,我来试一下

您好,我也遇到了这个问题。请问这是由于数据集原因引起的吗?现在就是在第一轮计算map时报错

请问您解决了吗,我也碰到了这样的问题

Sa-UpWorld commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误 您好,请问解决了吗,我也遇到了这个问题

Sa-UpWorld commented 2 years ago

/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml都需要改成对应的nc

请问您这个问题解决了吗

Sa-UpWorld commented 2 years ago

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我直接运行昨天刚下载的您的仓库的代码就 可以跑通,

你说的跑的通是SwinTransformer可以跑通吗,我总是在第一轮训练计算map时出现错误

我下载作者仓库的代码就可以跑通

你用的是自己的数据集吗?

我用的是自己的数据集,也是这个问题,请问您解决了吗

没有解决,希望作者能回复一下,我下载了yolov5 6.0然后吧swintransformer移值过去,就会报这个错误

请问您解决了吗,我也遇到了这个问题

Sa-UpWorld commented 2 years ago

我使用了您的代码训练,租用了同等算力的GPU但是还是会报错 File "/user-data/yolov5-5.0/models/SwinTransformer.py", line 88, in forward x = (attn @ v).transpose(1, 2).reshape(B_, N, C) RuntimeError: expected scalar type Float but found Half 不知道为什么

兄弟,请问解决了吗,我也遇到了同样的问题 shape '[8, 3, 7, 2, 7, 256]' is invalid for input of size 860160

Sa-UpWorld commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

兄弟,请问你解决了吗

CARL728 commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

兄弟,请问你解决了吗

我也有这个问题

CARL728 commented 2 years ago

按照您意见加上--nohalf之后又出现了新的错误 File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 242, in forward x_windows = window_partition(shifted_x, self.window_size) # nW*B, window_size, window_size, C File "/user-data/YOLOv5-Multibackbone-Compression-main/models/SwinTransformer.py", line 122, in window_partition x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) RuntimeError: shape '[32, 2, 8, 2, 8, 512]' is invalid for input of size 5505024,您在帮忙看一下是哪里的问题呢,我使用的还是您的程序,但是还是会有这个错误

您好 请告知一下你的训练命令行,我来试一下

python train.py --data VOC.yaml --weights yolov5l.pt --cfg models/accModels/yolov5xP2CBAM-Swin-BiFPN-SPP.yaml --hyp data/hyps/hyp.visdrone.yaml --epochs 30 --batch-size 2 --nohalf --device cuda:0 --img 608

CARL728 commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

兄弟,请问你解决了吗 我好像解决了 根据你的数据集来看 img不能太大 放小一点

CARL728 commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

兄弟,请问你解决了吗

但是放小之前是 每次第一轮训练完就报错,现在是第一轮训练 验证了一大半的时候报错

XhHello commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

兄弟,请问你解决了吗 我好像解决了 根据你的数据集来看 img不能太大 放小一点

朋友,我也遇到过这个报错,请问你是如何解决的。

Sa-UpWorld commented 2 years ago

训练使用yolov5xP2CBAM-Swin-BiFPN-SPP这个模型的时候,第一轮训练结束进行val的时候报错,定位到代码是这一行: x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 出现了尺寸不匹配这个问题。请问有大神可以解释一下原因嘛,不胜感激。

兄弟,请问你解决了吗 我好像解决了 根据你的数据集来看 img不能太大 放小一点

这种方式第一轮训练没有问题,第一轮验证大半时还是会出现这个错误