diff --git a/images/.DS_Store b/images/.DS_Store index 3abeaa77f0a48e644d7cbb595ac02464f0cd336c..55cd667feb99c29f0e933aa3ddbe4ebbd1497a26 100644 Binary files a/images/.DS_Store and b/images/.DS_Store differ diff --git a/results/mnist/result.png b/results/mnist/result.png index 5daa9a4e93ba06f6900e491b45b285d56a8bebb1..4e7dc261692d494b789d47ac82892ecac86d65c8 100644 Binary files a/results/mnist/result.png and b/results/mnist/result.png differ diff --git a/split_mnist.py b/split_mnist.py index 0e7d1510ac949129a9d7416ad184c82194f904db..cc2ed5d839211a1ce3ce71fd621e4add20c11f85 100644 --- a/split_mnist.py +++ b/split_mnist.py @@ -2,13 +2,19 @@ from keras.models import Model from keras.layers import Dense, Input, Conv2D, Flatten, MaxPooling2D from configuration import conf from utils.dataloader import Sequential_loader -import numpy as np from utils.model_utils import mask_layer_by_task from utils.layers import Probability_CLF_Mul_by_task from utils.train_utils import train_with_task from utils.predict_utils import get_task_likelihood, get_test_acc +from utils.utils import paa, mkdir +import matplotlib.pyplot as plt +import seaborn as sns +import numpy as np + +sns.set() PATH = './results/%s/' % conf.dataset_name +mkdir(PATH) epochs = 10 output_dim = 10 @@ -52,24 +58,9 @@ for task_idx in range(conf.num_tasks): test_acc.append(get_test_acc(model, learned_task=task_idx, data_loader=data_loader, test_on_whole_set=False)) # Print the average test accuracy across all the tasks print('Learned %dth Task, Average test accuracy on all the task : %.3f' % ( - task_idx, get_test_acc(model, learned_task=task_idx, data_loader=data_loader, test_on_whole_set=True))) - - -def paa(sample, w=None): - w = sample.shape[0] // 20 if w is None else w - l = len(sample) - stepfloat = l / w - step = int(np.ceil(stepfloat)) - start = 0 - j = 1 - paa = [] - while start <= (l - step): - section = sample[start:start + step] - paa.append(np.mean(section)) - start = int(j * stepfloat) - j += 1 - return paa + task_idx, get_test_acc(model, learned_task=task_idx, data_loader=data_loader, test_on_whole_set=True))) +# Plot the result tlh_s = [] for i in tlh: @@ -80,14 +71,8 @@ tlh_std_s = [] for i in tlh_std: tlh_std_s += i.tolist() tlh_std_s = np.array(tlh_std_s) - test_acc_s = np.array(test_acc).reshape(-1) -import matplotlib.pyplot as plt -import seaborn as sns - -sns.set() - tlh = np.array(paa(tlh_s)) tlh_std = np.array(paa(tlh_std_s)) test_acc = np.array(paa(test_acc_s, tlh.shape[0])) @@ -100,7 +85,6 @@ for i in a: fig.fill_between(np.arange(i, i + 10 + 1), 0, 0.1, alpha=0.1, color='red') fig.fill_between(np.arange(i - 10, i + 1), 0, 0.1, alpha=0.1, color='green') fig.fill_between(np.arange(90 - 10, 90), 0, 0.1, alpha=0.1, color='green') -# a = fig.get_xticklabels() fig.set_xticklabels(['', 'Task 1', 'Task 2', 'Task 3', 'Task 4', 'Task 5']) plt.legend(loc='center right') plt.savefig(PATH + 'result') diff --git a/utils/__pycache__/predict_utils.cpython-36.pyc b/utils/__pycache__/predict_utils.cpython-36.pyc index ede71aa1a0f772c2a971eb43ca801e7a7a7c968b..0da2764197a979d5da29517e7fd5eb87b7059480 100644 Binary files a/utils/__pycache__/predict_utils.cpython-36.pyc and b/utils/__pycache__/predict_utils.cpython-36.pyc differ diff --git a/utils/__pycache__/utils.cpython-36.pyc b/utils/__pycache__/utils.cpython-36.pyc index 843ccbd9168104d14a45a45054381541af7d8158..83a28e72b471c565dec6e6d33a692164285d3aed 100644 Binary files a/utils/__pycache__/utils.cpython-36.pyc and b/utils/__pycache__/utils.cpython-36.pyc differ diff --git a/utils/utils.py b/utils/utils.py index e83e59a033d6394820a7f0e871ac8325e1af1efc..92d3a0bf5fc70378abfc163bbb5d3520498850c9 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -1,8 +1,24 @@ import os +import numpy as np def mkdir(path): """ Create a directory if there isn't one already. """ try: os.mkdir(path) except OSError: - pass \ No newline at end of file + pass + +def paa(sample, w=None): + w = sample.shape[0] // 20 if w is None else w + l = len(sample) + stepfloat = l / w + step = int(np.ceil(stepfloat)) + start = 0 + j = 1 + paa = [] + while start <= (l - step): + section = sample[start:start + step] + paa.append(np.mean(section)) + start = int(j * stepfloat) + j += 1 + return paa \ No newline at end of file