Can't get attribute 'DGLHeteroGraph' on <module 'dgl.heterograph' from '/usr/local/lib/python3.10/dist-packages/dgl/heterograph.py'>
❓ Questions and Help
Hi,
I was trying to load a constructed dgl graph. but got the following error. Any advice for this? Thanks.
Can't get attribute 'DGLHeteroGraph' on <module 'dgl.heterograph' from '/usr/local/lib/python3.10/dist-packages/dgl/heterograph.py'>
Hi @22842219, could you follow the bug report template to provide more details?
meet the same problem when using MNIST dataset at https://data.dgl.ai/dataset/benchmarking-gnns/MNIST.pkl
how to reproduce
curl https://data.dgl.ai/dataset/benchmarking-gnns/MNIST.pkl -o MNIST.pkl -J -L -k
with open("MNIST.pkl","rb") as f:
f = pickle.load(f)
error
Traceback (most recent call last):
File "test.py", line 4, in <module>
f = pickle.load(f)
AttributeError: Can't get attribute 'DGLHeteroGraph' on <module 'dgl.heterograph' from '/home/ubuntu/.local/lib/python3.8/site-packages/dgl/heterograph.py'>
This is a known issue. Please refer to https://github.com/dmlc/dgl/issues/5574.
If you use the new version of DGL, you can dump a new graph pkl file.
how to deal with this problem?? @paoxiaode , looking for your reply, thx.
how to deal with this problem?? @paoxiaode , looking for your reply, thx.
@leaves520 This problem is due to the pkl file being dumped under an older version of DGL.
If you want to use the PATTERN, CLUSTER dataset, you can refer to https://github.com/dmlc/dgl/blob/master/python/dgl/data/pattern.py, they are now supported by DGL.
If you want to use the not DGL built-in dataset dataset(CIFAR 10 or MNIST), you can refer to https://github.com/graphdeeplearning/benchmarking-gnns/blob/master/data/superpixels/prepare_superpixels_MNIST.ipynb, use the code like below to re-dump the dataset pkl file
import pickle
import time
from data.superpixels import SuperPixDatasetDGL
from data.data import LoadData
from torch.utils.data import DataLoader
from data.superpixels import SuperPixDataset
DATASET_NAME = 'MNIST'
dataset = SuperPixDatasetDGL(DATASET_NAME)
with open('data/superpixels/MNIST.pkl','wb') as f:
pickle.dump([dataset.train,dataset.val,dataset.test],f)
This issue has been automatically marked as stale due to lack of activity. It will be closed if no further activity occurs. Thank you
How to solve this for ZINC dataset.
How to solve this for ZINC dataset.
Yes, please.
How to solve this for ZINC dataset.
Hi, I'm not sure if you still need, but if you want to use a new version DGL to load a dataset generated by old version DGL(with DGLHeteroGraph), you can define a class in the lib of DGL(/your_dir/miniconda3/envs/your_env_name/lib/python3.12/site-packages/dgl/heterograph.py) like this
class DGLHeteroGraph(DGLGraph):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Also add the DGLHeteroGraph to __all__ = ["DGLGraph", "combine_names"], and import DGLHeteroGraph in the __init__.py. I have tried and it works for me.