Calling function in main()

from train_test import test 
class Trainer():
  def __init__(self, method, data_unlabeled, subset, labeled_set, cycle, args):
        self.method = method 
        self.data_unlabeled = data_unlabeled  
        self.subset = subset 
        self.labeled_set = labeled_set 
        self.cycle = cycle 
        self.args = args 

     def query_samples(self, method, data_unlabeled, subset, labeled_set, cycle, args,  param):
        optimizer_target = getattr(optim, param['optimizer'])(net.parameters(), lr = 
     self.query= query_samples
  def objective(self,train):
     params = {}
     model = Trainer()
     model = model.query(params)
     accuracy = model.test(trial)
     return accuracy 

if __name__ == '__main__':

    study = optuna.create_study(direction="maximize")
    study.optimize(lambda trial: Trainer.objective(trial))

init__() missing 6 required positional arguments: ‘method’, ‘data_unlabeled’, ‘subset’, ‘labeled_set’, ‘cycle’, and ‘args’

how to pass these arguments in Trainer class and then call query_samples or query()

If I take out the objective() from Trainer class, I am unable to call the objective function in my main() because of self

File “”, line 94, study.optimize(lambda trial: objective(trial)) TypeError: objective() missing 1 required positional argument: ‘trial’


  • you are initializing Trainer object inside a function of the class