Home > database >  calling function from class inner another class
calling function from class inner another class

Time:10-17

i have class config inner class preprocessor and i want to calling get_data function

from torch_geometric.datasets import Planetoid
from torch_geometric.data import DataLoader
class Preprocess():
    class config():    
      root_dir = './data/'
      batch_size = 1
      hidden_dim = 16 
      dropout_rate = 0.5
      l2_reg = 5*10e-4
      learning_rate = 0.01
      epochs = 200
      loss_type = 'cross_entropy' # or nll_loss

  def __init__(self, config, d_name):
    self.root_dir = config.root_dir
    self.batch_size = config.batch_size
    
    self.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 i have the error: NameError: name 'config' is not defined

CodePudding user response:

You need to either use Preprocess.config or self.config to access the config class

CodePudding user response:

You need to put Preprocess.config because that's where it's defined

  • Related