sw-gong/MoNet

RuntimeError: The size of tensor a (4096) must match the size of tensor b (25) at non-singleton dimension 1

sure7018 opened this issue · 3 comments

The code is:
def message(self, x_j, pseudo):
(E, D), K = pseudo.size(), self.mu.size(0)
print("E:")
print(E)
print("D:")
print(D)
print("K:")
print(K)
gaussian = -0.5 * (pseudo.view(E, 1, D) - self.mu.view(1, K, D))**2
print("######################")
print(gaussian.shape)
a = EPS + self.sigma.view(1, K, D)**2
print("!!!!!!!!!!!!!!!!!!!!!")
print(a.shape)
gaussian = gaussian / (EPS + self.sigma.view(1, K, D)**2)
print("@@@@@@@@@@@@@@@@@@@@@@@@@@")
print(gaussian.shape)
gaussian = torch.exp(gaussian.sum(dim=-1, keepdim=True)) # [E, K, 1]
print("$$$$$$$$$$$$$$$$$$$$$$$$$$")
print(gaussian.shape)
print("x_j:")
print(x_j.shape)
return (x_j * gaussian).sum(dim=1)

And the error is:

Loading model check point from checkpoints/SGRN/res101_faster_rcnn_iter_1200000.pth
load_state_dict in network_gcn
Loaded.
Loaded.
test_net, num_images=4961
fc7 = torch.Size([128, 2048])
E:
4096
D:
2
K:
25
######################
torch.Size([4096, 25, 2])
!!!!!!!!!!!!!!!!!!!!!
torch.Size([1, 25, 2])
@@@@@@@@@@@@@@@@@@@@@@@@@@
torch.Size([4096, 25, 2])
$$$$$$$$$$$$$$$$$$$$$$$$$$
torch.Size([4096, 25, 1])
x_j:
torch.Size([128, 4096, 2048])
Traceback (most recent call last):
File "tools/test_net.py", line 159, in
test_net(net, imdb, filename, max_per_image=100) #args.max_per_image)
File "/home1/lws/SGRN/tools/../lib/model/test.py", line 145, in test_net
scores, boxes = im_detect(net, im)
File "/home1/lws/SGRN/tools/../lib/model/test.py", line 107, in im_detect
blobs['im_info'])
File "/home1/lws/SGRN/tools/../lib/nets/network_gcn.py", line 551, in test_image
self.forward(image, im_info, None, mode='TEST')
File "/home1/lws/SGRN/tools/../lib/nets/network_gcn.py", line 503, in forward
rois, cls_prob, bbox_pred = self._predict()
File "/home1/lws/SGRN/tools/../lib/nets/network_gcn.py", line 474, in _predict
f = self.gaussian(represent, relation, U)
File "/home/user/anaconda3/envs/sgrn/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/home1/lws/SGRN/tools/../lib/conv/gmm_conv.py", line 47, in forward
out = self.propagate(edge_index, x=out, pseudo=pseudo)
File "/home/user/anaconda3/envs/sgrn/lib/python3.7/site-packages/torch_geometric/nn/conv/message_passing.py", line 269, in propagate
out = self.message(**msg_kwargs)
File "/home1/lws/SGRN/tools/../lib/conv/gmm_conv.py", line 76, in message
return (x_j * gaussian).sum(dim=1)
RuntimeError: The size of tensor a (4096) must match the size of tensor b (25) at non-singleton dimension 1

vox-1 commented

I met the same problem, did you solve it?

Your x_j should have size torch.Size ([4096, K, in_channels]) with K the kernel size (25 in the above example). in_channels represents the dimension of each input nodes (I think 2048 in your example?).

I met the same problem, did you solve it?

I suggest instead using the more up-to-date version found here built into PyTorch geometric:
https://pytorch-geometric.readthedocs.io/en/latest/modules/nn.html#torch_geometric.nn.conv.GMMConv