pytorch_compact_bilinear_pooling icon indicating copy to clipboard operation
pytorch_compact_bilinear_pooling copied to clipboard

merge

Open ahuxjz opened this issue 5 years ago • 11 comments

What if I want to merge two feature maps? The shape of the feature map is (batch_size, channel, w, h) ,,,, Thank you !

ahuxjz avatar Sep 21 '19 01:09 ahuxjz

Hello. Would it be possible that you share more details of what you are trying to do?

gdlg avatar Sep 21 '19 10:09 gdlg

你好。您是否有可能分享您想做的更多细节? 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

ahuxjz avatar Sep 21 '19 10:09 ahuxjz

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.

gdlg avatar Sep 21 '19 12:09 gdlg

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)?

ahuxjz avatar Sep 21 '19 12:09 ahuxjz

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.

gdlg avatar Sep 21 '19 16:09 gdlg

不,我认为(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)

ahuxjz avatar Sep 22 '19 00:09 ahuxjz

不,我认为(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.

ziqiangchen avatar Aug 06 '20 01:08 ziqiangchen

Thanks @ziqiangchen . That's right, input_size should be 3.

gdlg avatar Aug 06 '20 20:08 gdlg

你好,一直提示这个问题: 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。

ccwang-nwpu avatar Apr 04 '21 14:04 ccwang-nwpu

你好,一直提示这个问题: 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.

ANNAZSH avatar Feb 17 '23 07:02 ANNAZSH

你好,一直提示这个问题: 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.

studkf avatar Feb 25 '23 09:02 studkf