def score(self, epoch_counter): """ Scoring on the test set. """ print("\n\nModel evaluation.\n") start_time = time.time() self.model.eval() self.scores = [] self.ground_truth = [] for test_graph_pair in tqdm(self.testing_graphs): data = process_pair(test_graph_pair) self.ground_truth.append(calculate_normalized_ged(data)) data = self.transfer_to_torch(data) target = data["target"] prediction = self.model(data) print("\n" + str(test_graph_pair) + "- " + "Similarity/Target: " + str(prediction) + " / " + str(target)) self.scores.append(calculate_loss(prediction, target)) print("--- %s seconds ---" % (time.time() - start_time)) model_error = self.print_evaluation() print('\n\n >>>>>>>>>>>>>>>>>>\t' + str(model_error) + '\n') with open("./outputFiles/test/test_error_graph.txt", "a") as test_error_writer: test_error_writer.write( str(epoch_counter) + ',' + str(model_error) + '\n') test_error_writer.close()
def score(self): """ Scoring on the test set. """ print("\n\nModel evaluation.\n") self.model.eval() self.scores = [] self.ground_truth = [] preds = [] truths = [] for graph_pair in tqdm(self.testing_graphs): data = process_pair(graph_pair) self.ground_truth.append(calculate_normalized_ged(data)) data = self.transfer_to_torch(data) target = data["target"] prediction = self.model(data) self.scores.append(calculate_loss(prediction, target)) preds.append(0 if prediction.item() < 0.5 else 1) truths.append(int(data["target"].item())) self.print_evaluation() plot_confusion_matrix(np.array(truths), np.array(preds), np.array([0, 1]), title='SimGNN confusion matrix')
def get_train_baseline_error(self): """ Calculates the baseline error of the training data """ self.train_ground_truth = [] for graph_pair in tqdm(self.training_graphs): data = process_pair(graph_pair) self.train_ground_truth.append(calculate_normalized_ged(data)) norm_ged_mean = np.mean(self.train_ground_truth) base_train_error = np.mean([(n - norm_ged_mean)**2 for n in self.train_ground_truth]) print("\nBaseline Training error: " + str(round(base_train_error, 5)))
def load_model_parallel(self, pairList): #print("Parallel Execution of funcGNN from pretrained model") #self.model = funcGNN(self.args, self.number_of_labels) #self.model.load_state_dict(torch.load('./model_state.pth')) #self.model.eval() data = process_pair(pairList) self.ground_truth.append(calculate_normalized_ged(data)) data = self.transfer_to_torch(data) target = data["target"] prediction = self.model(data) #print("\n" + str(pairList) + "- " + "Similarity/Target: " + str(prediction) + " / " + str(target)) self.scores.append(calculate_loss(prediction, target))
def score(self): """ Scoring on the test set. """ print("\n\nModel evaluation.\n") self.scores = [] self.ground_truth = [] for graph_pair in tqdm(self.testing_graphs): data = process_pair(graph_pair) self.ground_truth.append(calculate_normalized_ged(data)) data = self.transfer_to_torch(data) target = self.model(data) prediction = self.model(data) self.scores.append(calculate_loss(prediction, target)) self.print_evaluation()
def load_model(self): print("\nSerial Execution of funcGNN from pretrained model") start_time = time.time() self.model = funcGNN(self.args, self.number_of_labels) self.model.load_state_dict(torch.load('./model_state.pth')) self.model.eval() self.scores = [] self.ground_truth = [] for test_graph_pair in tqdm(self.random_graphs): data = process_pair(test_graph_pair) self.ground_truth.append(calculate_normalized_ged(data)) data = self.transfer_to_torch(data) target = data["target"] prediction = self.model(data) #print("\n" + str(test_graph_pair) + "- " + "Similarity/Target: " + str(prediction) + " / " + str(target)) self.scores.append(calculate_loss(prediction, target)) self.scores.append( torch.nn.functional.mse_loss(prediction, data["target"])) print("--- %s seconds ---" % (time.time() - start_time))
def score(self): """ Scoring on the test set. """ print("\n\nModel evaluation.\n") if path.isfile(self.args.saved_model): self.model=torch.load(self.args.saved_model) self.model.train(False) self.model.eval() self.scores = [] self.ground_truth = [] for graph_pair in tqdm(self.testing_graphs): data = process_pair(graph_pair) data_org = data.copy() self.ground_truth.append(calculate_normalized_ged(data)) data = self.transfer_to_torch(data) target = data["target"] prediction = self.model(data) print(f'Test target: {data_org["ged"]} {reverse_normalized_ged(-math.log(target),data_org)}, prediction: {reverse_normalized_ged(-math.log(prediction),data_org)}') self.scores.append(calculate_loss(prediction, target)) self.print_evaluation()