Converting HDF file to Pytorch torch geometric data format

I am trying to convert a hdf5 file to a torch geometric format by wrapping the loaded input with the function but I am getting the following error. Has anyone happened to run into this before?

class HDFDataset(

  def __init__(self, path, **kwargs):
    print('Path: ', path)
    '''Initialiser for HDFDataset class'''
    self.files = h5py.File(path, 'r') = list((self.files).keys())

  def __len__(self):
    return len(

  def __getitem__(self, idx):
    '''Return training information at provided index'''
    if not 0 <= idx < len(self):
      raise Exception(f'Event number {idx} invalid – must be in range 0 -> {len(self)-1}.')
    # Retrieve datasets from graph at index
    f = self.files
    ret = { dataset: f[str(idx)][dataset][:] for dataset in f[str(idx)].keys() }
    ret['edge_index'] = torch.tensor(ret['edge_index'][:])

Traceback (most recent call last):
File “”, line 80, in
print(‘HDF DataLoader ‘, next(iter(h_loader)))
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch/utils/data/”, line 517, in next
data = self._next_data()
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch/utils/data/”, line 557, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch/utils/data/_utils/”, line 47, in fetch
return self.collate_fn(data)
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch_geometric/data/”, line 36, in call
return self.collate(batch)
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch_geometric/data/”, line 16, in collate
return Batch.from_data_list(batch, self.follow_batch,
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch_geometric/data/”, line 105, in from_data_list
inc =, item)
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch_geometric/data/”, line 190, in inc
return self.num_nodes if bool(’(index|face)’, key)) else 0
File “/Users/songhyunlee/venv/lib/python3.8/site-packages/torch_geometric/data/”, line 215, in num_nodes
return item.size(self.cat_dim(key, item))
TypeError: ‘int’ object is not callable

I guess you are using a numpy array, which returns an int when accessing the size attribute, while PyTorch tensors provide a size() method, which would return the size of the tensor:

a = np.random.randn(3, 2)
> 6
> TypeError: 'int' object is not callable

so you could transform the numpy array to a tensor.