def __init__(self, ft_extrctor_prp, hypoth_prp, discrm_prp, **kwargs):
    final_results = defaultdict()
    self.criterion = kwargs['criterion']
    self.c3_value = kwargs['c3']
    self.grad_weight = kwargs['grad_weight']
    self.img_size = kwargs['img_size']
    self.num_chnnl = kwargs['chnnl']
    self.lr = kwargs['lr']
    self.momentum = kwargs['momentum']
    self.epochs = kwargs['epochs']
    num_tr_smpl = kwargs['tr_smpl']
    num_test_smpl = kwargs['test_smpl']
    self.trial = kwargs['Trials']
    self.tsklist = kwargs['tsk_list']
    self.num_tsk = len(self.tsklist)
    if (self.criterion == 'wasserstien'):
        self.stp_sz_sch = 30
    else:
        self.stp_sz_sch = 50
    self.device = torch.device(('cuda' if torch.cuda.is_available() else 'cpu'))
    self.alpha = (np.ones((self.num_tsk, self.num_tsk)) * (0.1 / (self.num_tsk - 1)))
    np.fill_diagonal(self.alpha, 0.9)
    self.wrdir = os.path.join(os.getcwd(), (((((('_'.join(self.tsklist) + '_') + str(num_tr_smpl)) + '_') + str(self.epochs)) + '_') + self.criterion), ('runs_' + str(self.c3_value)))
    try:
        os.makedirs(self.wrdir)
    except OSError:
        if (not os.path.isdir(self.wrdir)):
            raise
    with open(os.path.join(self.wrdir, (('info_itr_' + str(self.trial)) + '.json')), 'a') as outfile:
        json.dump([ft_extrctor_prp, hypoth_prp, discrm_prp], outfile)
        json.dump(kwargs, outfile)
    self.FE = util.feature_extractor(ft_extrctor_prp).construct().to(self.device)
    print(self.FE)
    self.hypothesis = [util.classifier(hypoth_prp).to(self.device) for _ in range(self.num_tsk)]
    print(self.hypothesis[0])
    self.discrm = {'{}{}'.format(i, j): util.classifier(discrm_prp).to(self.device) for i in range(self.num_tsk) for j in range((i + 1), self.num_tsk)}
    print(self.discrm['01'])
    all_parameters_h = sum([list(h.parameters()) for h in self.hypothesis], [])
    all_parameters_discrm = sum([list(self.discrm[d].parameters()) for d in self.discrm], [])
    self.optimizer = optim.SGD(((list(self.FE.parameters()) + list(all_parameters_h)) + list(all_parameters_discrm)), lr=self.lr, momentum=self.momentum)
    self.scheduler = lr_scheduler.StepLR(self.optimizer, step_size=self.stp_sz_sch, gamma=0.5)
    (train_loader, test_loader, validation_loader) = db.data_loading(self.img_size, num_tr_smpl, num_test_smpl, self.tsklist)
    self.writer = SummaryWriter(os.path.join(self.wrdir, ('itr' + str(self.trial))))
    Total_loss = []
    for epoch in range(self.epochs):
        self.scheduler.step(epoch)
        whole_loss = self.model_fit(train_loader, epoch)
        Total_loss.append(whole_loss)
        tasks_trAcc = self.model_eval(train_loader, epoch, 'train')
        tasks_valAcc = self.model_eval(validation_loader, epoch, 'validation')
        tasks_teAcc = self.model_eval(test_loader, epoch, 'test')
        if ((1.5 * np.mean(Total_loss[(- 5):(- 1)])) < Total_loss[(- 1)]):
            print('****** Increasing of training error')
            break
        final_results[('alpha_c3_' + str(self.c3_value))] = self.alpha.tolist()
        final_results[('Tasks_val_Acc_c3_' + str(self.c3_value))] = tasks_valAcc.tolist()
        final_results[('Tasks_test_Acc_c3_' + str(self.c3_value))] = tasks_teAcc.tolist()
        final_results[('Tasks_train_Acc_c3_' + str(self.c3_value))] = tasks_trAcc.tolist()
    with open(os.path.join(self.wrdir, (('info_itr_' + str(self.trial)) + '.json')), 'a') as outfile:
        json.dump(final_results, outfile)
    final_prmtr = defaultdict()
    final_prmtr['FE'] = self.FE.state_dict()
    for (i, h) in enumerate(self.hypothesis):
        final_prmtr[('hypo' + str(i))] = h.state_dict()
    for (k, D) in self.discrm.items():
        final_prmtr[('dicrm' + k)] = D.state_dict()
    torch.save(final_prmtr, os.path.join(self.wrdir, ('itr' + str(self.trial)), 'MTL_parameters.pt'))
    self.writer.close()
def __init__(self, ft_extrctor_prp, hypoth_prp, discrm_prp, **kwargs):
    final_results = defaultdict()
    self.criterion = kwargs['criterion']
    self.c3_value = kwargs['c3']
    self.grad_weight = kwargs['grad_weight']
    self.img_size = kwargs['img_size']
    self.num_chnnl = kwargs['chnnl']
    self.lr = kwargs['lr']
    self.momentum = kwargs['momentum']
    self.epochs = kwargs['epochs']
    num_tr_smpl = kwargs['tr_smpl']
    num_test_smpl = kwargs['test_smpl']
    self.trial = kwargs['Trials']
    self.tsklist = kwargs['tsk_list']
    self.num_tsk = len(self.tsklist)
    if (self.criterion == 'wasserstien'):
        self.stp_sz_sch = 30
    else:
        self.stp_sz_sch = 50
    self.device = torch.device(('cuda' if torch.cuda.is_available() else 'cpu'))
    self.alpha = (np.ones((self.num_tsk, self.num_tsk)) * (0.1 / (self.num_tsk - 1)))
    np.fill_diagonal(self.alpha, 0.9)
    self.wrdir = os.path.join(os.getcwd(), (((((('_'.join(self.tsklist) + '_') + str(num_tr_smpl)) + '_') + str(self.epochs)) + '_') + self.criterion), ('runs_' + str(self.c3_value)))
    try:
        os.makedirs(self.wrdir)
    except OSError:
        if (not os.path.isdir(self.wrdir)):
            raise
    with open(os.path.join(self.wrdir, (('info_itr_' + str(self.trial)) + '.json')), 'a') as outfile:
        json.dump([ft_extrctor_prp, hypoth_prp, discrm_prp], outfile)
        json.dump(kwargs, outfile)
    self.FE = util.feature_extractor(ft_extrctor_prp).construct().to(self.device)
    print(self.FE)
    self.hypothesis = [util.classifier(hypoth_prp).to(self.device) for _ in range(self.num_tsk)]
    print(self.hypothesis[0])
    self.discrm = {'{}{}'.format(i, j): util.classifier(discrm_prp).to(self.device) for i in range(self.num_tsk) for j in range((i + 1), self.num_tsk)}
    print(self.discrm['01'])
    all_parameters_h = sum([list(h.parameters()) for h in self.hypothesis], [])
    all_parameters_discrm = sum([list(self.discrm[d].parameters()) for d in self.discrm], [])
    self.optimizer = optim.SGD(((list(self.FE.parameters()) + list(all_parameters_h)) + list(all_parameters_discrm)), lr=self.lr, momentum=self.momentum)
    self.scheduler = lr_scheduler.StepLR(self.optimizer, step_size=self.stp_sz_sch, gamma=0.5)
    (train_loader, test_loader, validation_loader) = db.data_loading(self.img_size, num_tr_smpl, num_test_smpl, self.tsklist)
    self.writer = SummaryWriter(os.path.join(self.wrdir, ('itr' + str(self.trial))))
    Total_loss = []
    for epoch in range(self.epochs):
        self.scheduler.step(epoch)
        whole_loss = self.model_fit(train_loader, epoch)
        Total_loss.append(whole_loss)
        tasks_trAcc = self.model_eval(train_loader, epoch, 'train')
        tasks_valAcc = self.model_eval(validation_loader, epoch, 'validation')
        tasks_teAcc = self.model_eval(test_loader, epoch, 'test')
        if ((1.5 * np.mean(Total_loss[(- 5):(- 1)])) < Total_loss[(- 1)]):
            print('****** Increasing of training error')
            break
        final_results[('alpha_c3_' + str(self.c3_value))] = self.alpha.tolist()
        final_results[('Tasks_val_Acc_c3_' + str(self.c3_value))] = tasks_valAcc.tolist()
        final_results[('Tasks_test_Acc_c3_' + str(self.c3_value))] = tasks_teAcc.tolist()
        final_results[('Tasks_train_Acc_c3_' + str(self.c3_value))] = tasks_trAcc.tolist()
    with open(os.path.join(self.wrdir, (('info_itr_' + str(self.trial)) + '.json')), 'a') as outfile:
        json.dump(final_results, outfile)
    final_prmtr = defaultdict()
    final_prmtr['FE'] = self.FE.state_dict()
    for (i, h) in enumerate(self.hypothesis):
        final_prmtr[('hypo' + str(i))] = h.state_dict()
    for (k, D) in self.discrm.items():
        final_prmtr[('dicrm' + k)] = D.state_dict()
    torch.save(final_prmtr, os.path.join(self.wrdir, ('itr' + str(self.trial)), 'MTL_parameters.pt'))
    self.writer.close()