Skip to content
Snippets Groups Projects
Commit 0aaa27eb authored by Fanis Baikas's avatar Fanis Baikas
Browse files

Changes in knn_random_subsets.py to create log and numpy_arrays directories...

Changes in knn_random_subsets.py to create log and numpy_arrays directories automatically. Moved y_pred tensor to device in k_neareast_neighbors.py to avoid problems when running with cuda.
parent 6f039985
No related branches found
No related tags found
No related merge requests found
......@@ -104,5 +104,5 @@ class kNearestNeighbors(object):
kNN_labels_counts = np.bincount(kNN_labels)
y_pred_np[i] = np.argmax(kNN_labels_counts)
y_pred = torch.from_numpy(y_pred_np)
y_pred = torch.from_numpy(y_pred_np).to(self.device)
return y_pred
......@@ -74,6 +74,11 @@ if comm.rank == 0:
# Redirect stdout of the first process to write output to file
orig_stdout = sys.stdout
# Create log directory if it doesn't exist
if not os.path.exists('log/'):
os.mkdir('log')
f = open('log/output_log_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions) + '.txt', 'w')
sys.stdout = f
......@@ -211,14 +216,12 @@ if comm.rank == 0:
print('\n' + 'max value: %0.4f, example idx %d, count = %d' % (example_value_table[max_value_example_idx, 0], max_value_example_idx, example_value_table[max_value_example_idx, 1]))
print('min value: %0.4f, example idx %d, count = % d' % (example_value_table[min_value_example_idx, 0], min_value_example_idx, example_value_table[min_value_example_idx, 1]))
path = 'numpy_arrays/subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions)
if not os.path.exists(path):
os.mkdir(path)
path = 'numpy_arrays/subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions) + '/'
os.makedirs(path, exist_ok=True)
np.save(path + '/acc_table_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions), acc_table)
np.save(path + '/idxs_table_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions), idxs_table)
np.save(path + '/example_value_table_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions), example_value_table)
np.save(path + 'acc_table_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions) + '.npy', acc_table)
np.save(path + 'idxs_table_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions) + '.npy', idxs_table)
np.save(path + 'example_value_table_subset_size=' + str(subset_size) + '_num_of_repetitions=' + str(num_of_repetitions) + '.npy', example_value_table)
sys.stdout = orig_stdout
f.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment