i am new to work with python and i want to run this code ,
from torch_geometric.datasets import Planetoidfrom torch_geometric.data import DataLoaderclass Preprocess():def __init__(self, config, d_name):self.root_dir = config.root_dirself.batch_size = config.batch_sizeself.cora = Planetoid(root='./data/cora', name='Cora')#self.citeseer = Planetoid(root='./data/citeseer', name='CiteSeer')#self.pubmed = Planetoid(root='./data/pubmed', name='PubMed')self.num_classes, self.num_node_features, self.data = self.get_data(d_name)def get_data(self, d_name):'''d_name = 'Cora', 'CiteSeer', 'PubMed''''dataset = Planetoid(root=self.root_dir + d_name , name=d_name)return dataset.num_classes, dataset.num_node_features, DataLoader(dataset, batch_size = self.batch_size)f=Preprocess(config, Cora)f.get_data(Cora)
but get this error: name 'config' is not defined
Best Answer
So, It is not a bug.
Look your constructor:
def __init__(self, config, d_name): self.root_dir = config.root_dir self.batch_size = config.batch_size etc...
And your instantiation:
f = Preprocess(config, Cora) f.get_data(Cora)
Note that you are passing a variable "config" that has not been declared before. Also, by the arg "config" type in the constructor, yout need pass an object as a parameter to the instantiation "f = Preprocess(args)", because the arg "config" needs to have an "root_dir" atribute.
Please, check the Pytorch documentation for more examples of how to use this framework. Don't give up, you can do it.