pytorch_compact_bilinear_pooling
pytorch_compact_bilinear_pooling copied to clipboard
merge
What if I want to merge two feature maps? The shape of the feature map is (batch_size, channel, w, h) ,,,, Thank you !
Hello. Would it be possible that you share more details of what you are trying to do?
你好。您是否有可能分享您想做的更多细节? I now want to bilinear pooling the two feature maps generated by cnn. The shape of the feature map is (batch_size, channel, w, h). What should I do? Thank you
The only difficulty that I can think of is that you need to permute your feature maps to be of shape (batch_size, w, h, channel) before the pooling layer because the “channel” dimension is expected to be the last one. Apart from that, have a look at the README.
The only difficulty that I can think of is that you need to permute your feature maps to be of shape (batch_size, w, h, channel) before the pooling layer because the “channel” dimension is expected to be the last one. Apart from that, have a look at the README. But your input is two-dimensional, so should I change (b, c, w, h) to (b, a)?
No, I think that (b, w, h, c) should work. Just make sure that “c” is last. That’s because the FFT works on the last dimension.
不,我认为(b,w,h,c)应该起作用。只要确保“ c”为最后。那是因为FFT适用于最后一个维度。
I tried to use it like this, but I got an error.
“”s = s.view(s_view)
RuntimeError: shape '[1, 1, 1, 3]' is invalid for input of size 4“”
input_size=(4,32,32,3) output_size = 4096 mcb = CompactBilinearPooling(input_size, input_size, output_size).cuda() x = torch.rand(4,32,32,3).cuda() y = torch.rand(4,32,32,3).cuda()
z = mcb(x,y) print(z)
不,我认为(b,w,h,c)应该起作用。只要确保“ c”为最后。那是因为FFT适用于最后一个维度。
I tried to use it like this, but I got an error. “”s = s.view(s_view) RuntimeError: shape '[1, 1, 1, 3]' is invalid for input of size 4“”
input_size=(4,32,32,3) output_size = 4096 mcb = CompactBilinearPooling(input_size, input_size, output_size).cuda() x = torch.rand(4,32,32,3).cuda() y = torch.rand(4,32,32,3).cuda()
z = mcb(x,y) print(z)
you should set the input_size = 3, the input_size is equal with the channel numbers(I Guess). Then ,the code can get a right result.
Thanks @ziqiangchen . That's right, input_size should be 3.
你好,一直提示这个问题: im_fx = fx.select(-1, 1) IndexError: select(): index 1 out of range for tensor of size [4, 1] at dimension 1 请问是torch版本的问题导致fft结果不同吗?我的torch是1.8.0,所以用的是torch.fft.rfft。
你好,一直提示这个问题: im_fx = fx.select(-1, 1) IndexError: select(): index 1 out of range for tensor of size [4, 1] at dimension 1 请问是torch版本的问题导致fft结果不同吗?我的torch是1.8.0,所以用的是torch.fft.rfft。
hello,Imet the same issue. Have you sovled it? Could you share it? Thank you.
你好,一直提示这个问题: im_fx = fx.select(-1, 1) IndexError: select(): index 1 out of range for tensor of size [4, 1] at dimension 1 请问是torch版本的问题导致fft结果不同吗?我的torch是1.8.0,所以用的是torch.fft.rfft。
hello,Imet the same issue. Have you sovled it? Could you share it? Thank you.
I think it's a problem with the pytorch version. In version 0.4.0, torch.rfft has the following parameters:
torch.rfft(input, signal_ndim, normalized=False, onesided=True) → Tensor
where signal_ndim stands for the number of dimensions.
So I guess you could change torch.rfft(px, 1)
to torch.fft.rfft(px, dim=1)
.
I hope this helps you.