def setFileName(self, dataset: GraphDataset, args: ArgumentParser): """ sets the generic name for the output file Parameters ---------- dataset: GraphDataset args: ArgumentParser - command line inputs """ if self.singleGNN is None: self.file_name = fileNamer( dataset_name=dataset.name, l_inf=args.l_inf, l_0=args.l_0, num_layers=args.num_layers, seed=args.seed, targeted=args.targeted, continuous_epochs=args.continuous_epochs, start=self.start_to_file, end=self.end_to_file) else: self.file_name = fileNamer( dataset_name=dataset.name, model_name=args.singleGNN.string(), l_inf=args.l_inf, l_0=args.l_0, num_layers=args.num_layers, seed=args.seed, targeted=args.targeted, continuous_epochs=args.continuous_epochs, start=self.start_to_file, end=self.end_to_file)
def setFileName(self, dataset: GraphDataset, args: ArgumentParser): """ information at the generic base class oneGNNSAttack """ if self.singleGNN is None: self.file_name = fileNamer( dataset_name=dataset.name, l_inf=args.l_inf, num_layers=args.num_layers, seed=args.seed, targeted=args.targeted, continuous_epochs=args.continuous_epochs, start=self.start_to_file, end=self.end_to_file) else: self.file_name = fileNamer( dataset_name=dataset.name, model_name=args.singleGNN.string(), l_inf=args.l_inf, num_layers=args.num_layers, seed=args.seed, targeted=args.targeted, continuous_epochs=args.continuous_epochs, start=self.start_to_file, end=self.end_to_file)
def train(self, dataset, attack=None): model = self.model folder_name = osp.join(getGitPath(), 'models') if attack is None: folder_name = osp.join(folder_name, 'basic_models') targeted, attack_epochs = None, None else: folder_name = osp.join(folder_name, 'adversarial_models') targeted, attack_epochs = attack.targeted, attack.attack_epochs file_name = fileNamer(node_model=self.node_model, dataset_name=dataset.name, model_name=model.name, num_layers=model.num_layers, patience=self.patience, seed=self.seed, targeted=targeted, attack_epochs=attack_epochs, end='.pt') model_path = osp.join(folder_name, file_name) # load model and optimizer if not osp.exists(model_path): # train model model, model_log, test_acc = self.useTrainer(data=dataset.data, attack=attack) torch.save((model.state_dict(), model_log, test_acc), model_path) else: model_state_dict, model_log, test_acc = torch.load(model_path) model.load_state_dict(model_state_dict) print(model_log + '\n') self.basic_log = model_log self.clean = test_acc
def setFileName(self, dataset, args): if self.singleGNN is None: self.file_name = fileNamer(dataset_name=dataset.name, num_layers=args.num_layers, seed=args.seed, targeted=args.targeted, attack_epochs=args.attEpochs, start=self.start_to_file, end=self.end_to_file) else: self.file_name = fileNamer(dataset_name=dataset.name, model_name=args.singleGNN.string(), num_layers=args.num_layers, seed=args.seed, targeted=args.targeted, attack_epochs=args.attEpochs, start=self.start_to_file, end=self.end_to_file)