From f468883eb13909014b1698c3961391cc553ca194 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Tue, 17 Jan 2023 15:08:47 +0100 Subject: [PATCH] Update scripts --- src/scripts/benchmark_mul.py | 17 +++++++++++++++-- src/scripts/visualisation.py | 22 ++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/scripts/benchmark_mul.py b/src/scripts/benchmark_mul.py index dc21a70..fae1b19 100644 --- a/src/scripts/benchmark_mul.py +++ b/src/scripts/benchmark_mul.py @@ -70,8 +70,21 @@ def plot_temps_exec(data): GPUtime = [i["GPUtime"] for i in data] CPUtime = [i["CPUtime"] for i in data] - plt.plot(x, GPUtime) - plt.plot(x, CPUtime) + fig, ax = plt.subplots() + + #ax.set_yscale("log") + gputime, = ax.plot(x, GPUtime) + cputime, = ax.plot(x, CPUtime) + + gputime.set_label("Temps GPU") + cputime.set_label("Temps CPU") + + ax.set_ylabel("Temps d'exécution (secondes)") + ax.set_xlabel("Taille de la matrice d'entrée") + + ax.legend() + + plt.grid(True) plt.show() def plot_erreur(data): diff --git a/src/scripts/visualisation.py b/src/scripts/visualisation.py index c3c68d1..2446868 100644 --- a/src/scripts/visualisation.py +++ b/src/scripts/visualisation.py @@ -28,7 +28,7 @@ def image_from_file(filepath, dest="./images/"): png.from_array(data[i], 'L').save(os.path.join(dest, f"{i}.png")) -def image_from_list(filepath, dest="data.png", exp=False): +def image_from_list(filepath, exp=False): """ Enregistre une liste de poids sous forme d'une image exp sert à spécifier si il faut passer à une forme exponentielle @@ -54,13 +54,13 @@ def image_from_list(filepath, dest="data.png", exp=False): for j in range(IMAGE_HEIGHT): new_data[i][j] = data[i*IMAGE_HEIGHT+j] - png.from_array(new_data, 'L').save(dest) + return new_data def graph_from_test_reseau(erreurs, reussites): """ Affiche un graphique à partir d'un fichier contenant les - réussites et d'un autre contenant les erreurs (sortie brutes de out/main) + réussites et d'un autre contenant les erreurs (sortie brutes de out/mnist_main) """ with open(erreurs, "r", encoding="utf8") as f: data = f.read() @@ -113,7 +113,21 @@ def images_neurons(neurons, dest="neurons", exp=False): Afin de créer un ensemble d'image visualisant les poids """ os.makedirs(dest, exist_ok=True) + data = [] for i in neurons: os.system(f"./make.sh utils print-poids-neurone --reseau \ .cache/reseau.bin --neurone {i} > .cache/poids.txt") - image_from_list(".cache/poids.txt", os.path.join(dest, f"{i}.png"), exp=exp) + data.append(image_from_list(".cache/poids.txt", exp=exp)) + + new_data = data.copy() + + for i, _ in enumerate(new_data): + for j, _ in enumerate(new_data[i]): + for k, _ in enumerate(new_data[i][j]): + for l, _ in enumerate(new_data): + if i != l: + new_data[i][j][k] -= data[l][j][k] * 0.11 + new_data[i][j][k] = max(int(new_data[i][j][k]), 0) + + for i in neurons: + png.from_array(data[i], 'L').save(os.path.join(dest, f"{i}.png"))