MINet icon indicating copy to clipboard operation
MINet copied to clipboard

RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead

Open abelucky opened this issue 3 years ago • 7 comments

作者你好,我在运行代码的时候遇到了这样的错误RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead,请问您知道这个问题出在哪里,应该怎么解决吗?

abelucky avatar Dec 29 '21 14:12 abelucky

你好读者,请检查一下报错是在第几行,是否你传入的参数有误? 代码在上传前已经检查好可运行的

abelucky @.***> 于2021年12月29日周三 15:14写道:

作者你好,我在运行代码的时候遇到了这样的错误RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead,请问您知道这个问题出在哪里,应该怎么解决吗?

— Reply to this email directly, view it on GitHub https://github.com/chunmeifeng/MINet/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR75XN6RVC57PIZJANYU4C3UTMJUFANCNFSM5K6A4HUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

chunmeifeng avatar Dec 29 '21 14:12 chunmeifeng

你好读者,请检查一下报错是在第几行,是否你传入的参数有误? 代码在上传前已经检查好可运行的 abelucky @.> 于2021年12月29日周三 15:14写道: 作者你好,我在运行代码的时候遇到了这样的错误RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead,请问您知道这个问题出在哪里,应该怎么解决吗? — Reply to this email directly, view it on GitHub <#2>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR75XN6RVC57PIZJANYU4C3UTMJUFANCNFSM5K6A4HUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.Message ID: @.>

作者你好,经过检查发现是这样的,在MINet-main/fastmri/models/MINet.py中报错: self.add_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std, 1) line160 NameError: name 'rgb_mean' is not defined 然后检查发现: scale = 2 rgb_range = 255 n_colors = 1 res_scale =0.1 act = nn.ReLU(True) 这里定义了rgb_range没有定义rgb_mean和rgb_std,我查看common.MeanShift这个类后尝试定义这两个参数: `class MeanShift(nn.Conv2d): def init( self, rgb_range, rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0), sign=-1):

    super(MeanShift, self).__init__(3, 3, kernel_size=1)
    std = torch.Tensor(rgb_std)
    self.weight.data = torch.eye(3).view(3, 3, 1, 1) / std.view(3, 1, 1, 1)
    self.bias.data = sign * rgb_range * torch.Tensor(rgb_mean) / std
    for p in self.parameters():
        p.requires_grad = False`

我用这里的rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0)定义了参数后就出现了RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead的报错,不知道是否是这里的参数有什么问题,如果您还记得一些细节的话,非常感谢!

abelucky avatar Dec 30 '21 03:12 abelucky

你好读者,请检查一下报错是在第几行,是否你传入的参数有误? 代码在上传前已经检查好可运行的 abelucky @.> 于2021年12月29日周三 15:14写道: 作者你好,我在运行代码的时候遇到了这样的错误RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead,请问您知道这个问题出在哪里,应该怎么解决吗? — Reply to this email directly, view it on GitHub <#2>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR75XN6RVC57PIZJANYU4C3UTMJUFANCNFSM5K6A4HUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.Message ID: _@**.**_>

作者你好,经过检查发现是这样的,在MINet-main/fastmri/models/MINet.py中报错: self.add_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std, 1) line160 NameError: name 'rgb_mean' is not defined 然后检查发现: scale = 2 rgb_range = 255 n_colors = 1 res_scale =0.1 act = nn.ReLU(True) 这里定义了rgb_range没有定义rgb_mean和rgb_std,我查看common.MeanShift这个类后尝试定义这两个参数: `class MeanShift(nn.Conv2d): def init( self, rgb_range, rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0), sign=-1):

    super(MeanShift, self).__init__(3, 3, kernel_size=1)
    std = torch.Tensor(rgb_std)
    self.weight.data = torch.eye(3).view(3, 3, 1, 1) / std.view(3, 1, 1, 1)
    self.bias.data = sign * rgb_range * torch.Tensor(rgb_mean) / std
    for p in self.parameters():
        p.requires_grad = False`

我用这里的rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0)定义了参数后就出现了RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead的报错,不知道是否是这里的参数有什么问题,如果您还记得一些细节的话,非常感谢!

您好 我也遇到了这个问题 迟迟没有解决 请问您解决了吗 希望能跟您交流一下

Nancy0220 avatar Mar 30 '22 02:03 Nancy0220

你好,请问参数是按照我公布的代码设置的吗

Nancy0220 @.***> 于2022年3月30日周三 04:42写道:

你好读者,请检查一下报错是在第几行,是否你传入的参数有误? 代码在上传前已经检查好可运行的 abelucky @.

> 于2021年12月29日周三 15:14写道: … <#m_8887720049471462977_> 作者你好,我在运行代码的时候遇到了这样的错误RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead,请问您知道这个问题出在哪里,应该怎么解决吗? — Reply to this email directly, view it on GitHub <#2 https://github.com/chunmeifeng/MINet/issues/2>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR75XN6RVC57PIZJANYU4C3UTMJUFANCNFSM5K6A4HUA https://github.com/notifications/unsubscribe-auth/AR75XN6RVC57PIZJANYU4C3UTMJUFANCNFSM5K6A4HUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.Message ID: _@._>

作者你好,经过检查发现是这样的,在MINet-main/fastmri/models/MINet.py中报错: self.add_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std, 1) line160 NameError: name 'rgb_mean' is not defined 然后检查发现: scale = 2 rgb_range = 255 n_colors = 1 res_scale =0.1 act = nn.ReLU(True) 这里定义了rgb_range没有定义rgb_mean和rgb_std,我查看common.MeanShift这个类后尝试定义这两个参数: `class MeanShift(nn.Conv2d): def init( self, rgb_range, rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0), sign=-1):

super(MeanShift, self).__init__(3, 3, kernel_size=1)

std = torch.Tensor(rgb_std)

self.weight.data = torch.eye(3).view(3, 3, 1, 1) / std.view(3, 1, 1, 1)

self.bias.data = sign * rgb_range * torch.Tensor(rgb_mean) / std

for p in self.parameters():

    p.requires_grad = False`

我用这里的rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0)定义了参数后就出现了RuntimeError: Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead的报错,不知道是否是这里的参数有什么问题,如果您还记得一些细节的话,非常感谢!

您好 我也遇到了这个问题 迟迟没有解决 请问您解决了吗 希望能跟您交流一下

— Reply to this email directly, view it on GitHub https://github.com/chunmeifeng/MINet/issues/2#issuecomment-1082561085, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR75XN3UFXYIX3C25GGJH33VCO5QNANCNFSM5K6A4HUA . You are receiving this because you commented.Message ID: @.***>

chunmeifeng avatar Mar 30 '22 09:03 chunmeifeng

Just remove that line and anything about meanshift. This is only for computer vision SR tasks, where each jpg file has 3 channels (rgb) and the range of each voxel is 0 to 255. The values 'rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0)' are calculated for a specific dataset 'DIV2K'. After rescaling the range of each channel to -1 and 1, meanshift adjusts the mean value of the dataset to 0. It is not needed in MRI SR.

HaoLiMRI avatar Apr 20 '22 16:04 HaoLiMRI

I just met the same problem ("Given groups=1, weight of size [64, 448, 3, 3], expected input[4, 896, 320, 320] to have 448 channels, but got 896 channels instead"). Perhaps the author could look into the code again to check the tensor shapes? Thanks. @chunmeifeng

mylyu avatar Dec 04 '22 13:12 mylyu

the problem can be fixed by modifying the line 166 in MINet.py self.last_conv = nn.Conv2d(n_feats*(n_resgroups+1), n_feats, 3, 1, 1) into: self.last_conv = nn.Conv2d(n_feats*(n_resgroups+1)*2, n_feats, 3, 1, 1

huihui43 avatar Mar 14 '24 12:03 huihui43