Dynamic-convolution-Pytorch
Dynamic-convolution-Pytorch copied to clipboard
想请教以下用3D动态卷积的时候报错问题
很感谢你的分享,但是我在调试过程中发现当输入为(128,1,20,30,30)这个tensor的通道为1时,代码会报错, File "D:\anaconda3\envs\py38\lib\site-packages\torch\nn\modules\conv.py", line 557, in init super(Conv3d, self).init( File "D:\anaconda3\envs\py38\lib\site-packages\torch\nn\modules\conv.py", line 83, in init self.reset_parameters() File "D:\anaconda3\envs\py38\lib\site-packages\torch\nn\modules\conv.py", line 86, in reset_parameters init.kaiming_uniform_(self.weight, a=math.sqrt(5)) File "D:\anaconda3\envs\py38\lib\site-packages\torch\nn\init.py", line 381, in kaiming_uniform_ fan = _calculate_correct_fan(tensor, mode) File "D:\anaconda3\envs\py38\lib\site-packages\torch\nn\init.py", line 350, in _calculate_correct_fan fan_in, fan_out = _calculate_fan_in_and_fan_out(tensor) File "D:\anaconda3\envs\py38\lib\site-packages\torch\nn\init.py", line 282, in _calculate_fan_in_and_fan_out receptive_field_size = tensor[0][0].numel() IndexError: index 0 is out of bounds for dimension 0 with size 0
要不贴下你完整的代码
下面是我的完整代码:我是用来学一下动态卷积,所以只是产生了一个随机的tensor来理解代码 if name == 'main': x = torch.randn(128, 1, 180, 20, 20) model = Dynamic_conv3d(in_planes=1, out_planes=1, kernel_size=3, ratio=0.25, padding=1,) x = x.to('cuda:0') model.to('cuda') # model.attention.cuda() # nn.Conv3d() out = model(x)
这是你的源码,问题应该是出在这 class attention3d(nn.Module): def init(self, in_planes, ratios, K, temperature): super(attention3d, self).init() assert temperature%3==1 self.avgpool = nn.AdaptiveAvgPool3d(1) if in_planes != 3: hidden_planes = int(in_planes * ratios) else: hidden_planes = K self.fc1 = nn.Conv3d(in_planes, hidden_planes, 1, bias=False) self.fc2 = nn.Conv3d(hidden_planes, K, 1, bias=False) self.temperature = temperature 我调试了一下,当输入的tensor通道数为1的时候,执行if语句,hidden_planes=0,导致下面进行fc1的时候输出的通道为0,所以才报的错,另外,在调试过程中我还发现output会出现Nan的情况,不知道是啥原因(笑哭),还想向你请教一下
Nan的话,按照2d里面的torch.randn改一下 另外hidden_planes = int(in_planes * ratios)改为hidden_planes = int(in_planes * ratios)+1即可。我现在重新改下代码。
好的,非常感谢
代码改好了,你帮我改了个bug😁
😁
您好 我在3d里面也遇到的output为nan的情况 请问您是改了哪行代码?
这个源代码的作者已经把这个bug改过来了,你直接用现有的代码就可以了
------------------ 原始邮件 ------------------ 发件人: "kaijieshi7/Dynamic-convolution-Pytorch" @.>; 发送时间: 2021年5月12日(星期三) 下午2:56 @.>; @.@.>; 主题: Re: [kaijieshi7/Dynamic-convolution-Pytorch] 想请教以下用3D动态卷积的时候报错问题 (#5)
您好 我在3d里面也遇到的output为nan的情况 请问您是改了哪行代码?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
这个源代码的作者已经把这个bug改过来了,你直接用现有的代码就可以了 … ------------------ 原始邮件 ------------------ 发件人: "kaijieshi7/Dynamic-convolution-Pytorch" @.>; 发送时间: 2021年5月12日(星期三) 下午2:56 @.>; @.@.>; 主题: Re: [kaijieshi7/Dynamic-convolution-Pytorch] 想请教以下用3D动态卷积的时候报错问题 (#5) 您好 我在3d里面也遇到的output为nan的情况 请问您是改了哪行代码? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
我用的就是作者现在的代码 发现还是会输出nan 我把bias设置为Falsej就好了。