Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Graph' object has no attribute 'train_mask' #432

Open
Song-xx opened this issue Jun 13, 2023 · 2 comments
Open

AttributeError: 'Graph' object has no attribute 'train_mask' #432

Song-xx opened this issue Jun 13, 2023 · 2 comments

Comments

@Song-xx
Copy link

Song-xx commented Jun 13, 2023

❓ Questions & Help

I am using unsup_graphsage to train on cora dataset. This error happens.

my enviroment is:

cogdl==0.6.0
macos m1
python=3.9

the error message is :

Traceback (most recent call last):
  ......
  File "/Users/xxx/python3.9/site-packages/cogdl/pipelines.py", line 204, in __call__
    model = train(self.args)
  File "/Users/xxx/python3.9/site-packages/cogdl/experiments.py", line 147, in train
    dataset_wrapper = dw_class(dataset, **data_wrapper_args)
  File "/Users/xxx/python3.9/site-packages/cogdl/wrappers/data_wrapper/node_classification/unsup_graphsage_dw.py", line 18, in __init__
    dataset, sizes=sample_size, batch_size=batch_size, mask=dataset.data.train_mask
AttributeError: 'Graph' object has no attribute 'train_mask'

The problem code lies in:

class UnsupGraphSAGEDataWrapper(DataWrapper):
    @staticmethod
    def add_args(parser):
        # fmt: off
        parser.add_argument("--batch-size", type=int, default=128)
        parser.add_argument("--sample-size", type=int, nargs='+', default=[10, 10])
        # fmt: on

    def __init__(self, dataset, batch_size: int, sample_size: list):
        super(UnsupGraphSAGEDataWrapper, self).__init__(dataset)
        self.dataset = dataset
        self.train_dataset = UnsupNeighborSamplerDataset(
            dataset, sizes=sample_size, batch_size=batch_size, mask=dataset.data.train_mask
        )
        self.val_dataset = UnsupNeighborSamplerDataset(
            dataset, sizes=sample_size, batch_size=batch_size * 2, mask=dataset.data.val_mask
        )
        self.test_dataset = UnsupNeighborSamplerDataset(
            dataset=self.dataset,
            mask=None,
            sizes=[-1],
            batch_size=batch_size * 2,
        )
        self.x = self.dataset.data.x
        self.y = self.dataset.data.y
        self.batch_size = batch_size
        self.sample_size = sample_size

I tried to find a solution but failed. Any one can help me ? thx

@cenyk1230
Copy link
Member

Hi @Song-xx ,

Could you please give the exact code/script for reproducing the error? Do you use experiment or pipeline or other APIs?

@Song-xx
Copy link
Author

Song-xx commented Jun 14, 2023

I juse use the pipeline by 'from cogdl import pipeline'. The code I use is similar to these in the tutorial:

data = build_dataset_from_name('cora').data
edge_index = np.array([[x, y] for x, y in zip(
    data.edge_index[0].tolist(), data.edge_index[1].tolist())])
generator = pipeline("generate-emb", model='unsup_graphsage', return_model=True,
                     num_features=-1, hidden_size=emb_dim, cpu=True,
                     cpu_inference=True, no_test=True)
emb = generator(edge_index, data.x.numpy())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants