TypeError: 'int' object is not callable in PYG HeteroConv #8153
Replies: 2 comments 8 replies
-
Mh, this looks correct to me (except for the import torch
from torch_geometric.data import HeteroData
from torch_geometric.nn import GCNConv, HeteroConv
conv = HeteroConv(
{
('ntype1', 'etype1', 'ntype1'): GCNConv(-1, 32),
('ntype2', 'etype2', 'ntype2'): GCNConv(-1, 32),
('ntype3', 'etype3', 'ntype3'): GCNConv(-1, 32),
}, aggr='sum')
data = HeteroData()
data['ntype1'].x = torch.randn(10, 16)
data['ntype2'].x = torch.randn(10, 16)
data['ntype3'].x = torch.randn(10, 16)
data['ntype1', 'etype1', 'ntype1'].edge_index = torch.randint(0, 10, (2, 20))
data['ntype1', 'etype1', 'ntype1'].edge_weight = torch.rand(20)
data['ntype2', 'etype2', 'ntype2'].edge_index = torch.randint(0, 10, (2, 20))
data['ntype2', 'etype2', 'ntype2'].edge_index = torch.randint(0, 10, (2, 20))
data['ntype3', 'etype3', 'ntype3'].edge_weight = torch.rand(20)
data['ntype3', 'etype3', 'ntype3'].edge_weight = torch.rand(20)
out_dict = conv(data.x_dict, data.edge_index_dict, data.edge_weight_dict) |
Beta Was this translation helpful? Give feedback.
-
In case it helps, I was also facing the same error In my case, when I was creating the hetero-data I was mistakenly setting the node feature tensors |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I apply the HetroConv via this below mentioned code, but every time I find this error, 'int' object is not callable. Can you help me to fix this error?
Exact error message is :
Traceback (most recent call last): File "/hetegeneousgraph/code/src/method/model1/main.py", line 248, in <module> train(model, optimizer, train_data) File "/hetegeneousgraph/code/src/method/model1/main.py", line 58, in train trn_loss = train_epoch() File "/hetegeneousgraph/code/src/method/model1/main.py", line 40, in train_epoch score = model(data.x_dict, data.edge_index_dict, data.edge_weight_dict) File "/.conda/envs/foo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "/hetegeneousgraph/code/src/method/model1/model1.py", line 28, in forward h = self.conv1(x_dict, edge_index_dict, edge_weight_dict) File "/.conda/envs/foo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "/.conda/envs/foo/lib/python3.10/site-packages/torch_geometric/nn/conv/hetero_conv.py", line 136, in forward out = conv(x_dict[src], edge_index, *args, **kwargs) File "/.conda/envs/foo/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "/.conda/envs/foo/lib/python3.10/site-packages/torch_geometric/nn/conv/gcn_conv.py", line 211, in forward edge_index, edge_weight, x.size(self.node_dim), TypeError: 'int' object is not callable
The code which I used is this one, which is shown below:
`import torch
from torch_geometric.nn import GCNConv, HeteroConv
class Model(torch.nn.Module):
def init(self, out_channels, hidden_channels=512):
super().init()
def forward(self, x_dict, edge_index_dict, edge_weight_dict):
My data Object is of this shape
HeteroData( ntype1={ x=[8704, 8704] }, ntype2={ x=[8704, 8704] }, ntype3={ x=[8704, 8704] }, (ntype1, etype1, ntype1)={ edge_index=[2, 1511590], edge_weight=[1511590] }, (ntype2, etype2, ntype2)={ edge_index=[2, 1645254], edge_weight=[1645254] }, (ntype3, etype3, ntype3)={ edge_index=[2, 322990] }, (ntype3, etype3, ntype3)={ edge_weight=[322990] } )
main function
model = Model(out_channels=5) out = model(data.x_dict, data.edge_index_dict, data.edge_weight_dict)
Beta Was this translation helpful? Give feedback.
All reactions