def main(argv): # config the CPU/GPU in TF, assume only one GPU is in use. # For multi-gpu setting, please refer to # https://www.tensorflow.org/guide/gpu#using_multiple_gpus gpus = tf.config.experimental.list_physical_devices('GPU') if len(gpus) == 0 or FLAGS.gpu_id is None: device_id = "/device:CPU:0" else: tf.config.experimental.set_visible_devices(gpus[FLAGS.gpu_id], 'GPU') device_id = '/device:GPU:0' A_mat, X_mat, z_vec, train_idx, val_idx, test_idx = load_data_planetoid( FLAGS.dataset) An_mat = preprocess_graph(A_mat) # N = A_mat.shape[0] K = z_vec.max() + 1 with tf.device(device_id): gcn = GCN(An_mat, X_mat, [FLAGS.hidden1, K]) gcn.train(train_idx, z_vec[train_idx], val_idx, z_vec[val_idx]) test_res = gcn.evaluate(test_idx, z_vec[test_idx], training=False) # gcn = GCN(An_mat_diag, X_mat_stack, [FLAGS.hidden1, K]) # gcn.train(train_idx_recal, z_vec[train_idx], val_idx_recal, z_vec[val_idx]) # test_res = gcn.evaluate(test_idx_recal, z_vec[test_idx], training=False) print("Dataset {}".format(FLAGS.dataset), "Test loss {:.4f}".format(test_res[0]), "test acc {:.4f}".format(test_res[1]))
with open("fixed_lapl.pkl", "rb") as pkl: fxd = pickle.load(pkl) plt.figure() smooth_plot(fxd['train_losses'], label='Fixed Train Loss') smooth_plot(lrnd['train_losses'], label='Learned Train Loss') smooth_plot(fxd['val_losses'], fmt="-.", label='Fixed Val Loss') smooth_plot(lrnd['val_losses'], fmt="-.", label='Learned Val Loss') plt.xlabel('Epoch') plt.ylabel('Loss') plt.title('Loss Cora') plt.legend() plt.figure() smooth_plot(fxd['train_accuracies'], label='Fixed Train Accuracy') smooth_plot(lrnd['train_accuracies'], label='Learned Train Accuracy') smooth_plot(fxd['val_accuracies'], fmt="-.", label='Fixed Val Accuracy') smooth_plot(lrnd['val_accuracies'], fmt="-.", label='Learned Val Accuracy') plt.xlabel('Epoch') plt.ylabel('Accuracy') plt.title('Accuracy Cora') plt.legend() test_res = gcn.evaluate(test_idx, z_vec[test_idx], training=False) # gcn = GCN(An_mat_diag, X_mat_stack, [FLAGS.hidden1, K]) # gcn.train(train_idx_recal, z_vec[train_idx], val_idx_recal, z_vec[val_idx]) # test_res = gcn.evaluate(test_idx_recal, z_vec[test_idx], training=False) print("Dataset {}".format(FLAGS.dataset), "Test loss {:.4f}".format(test_res[0]), "test acc {:.4f}".format(test_res[1]))