Added pseudocode to poster, fixed MNIST results not showing 0 strength

This commit is contained in:
Aidan Sharpe 2024-05-01 11:17:42 -04:00
parent ac1272e123
commit 0ba4e489bb
7 changed files with 843 additions and 54 deletions

Binary file not shown.

21
poster/pseudocode.py Normal file
View File

@ -0,0 +1,21 @@
model = Net()
accuracies = {}
for filter in filters:
for epsilon in epsilons:
for strength in range(5):
correct = 0
total = 0
for data, target in dataset:
atk_data = fgsm_attack(data, epsilon)
filt_data = filter(atk_data, filter, strength)
prediction = model(filt_data)
total += 1
if prediction == target:
correct += 1
accuracies[filter][epsilon][strength] = correct/total
save_json("results.json", accuracies)

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

668
results/mnist_fgsm_old.json Normal file
View File

@ -0,0 +1,668 @@
{
"unfiltered": [
0.992,
0.9796,
0.96,
0.926,
0.8753,
0.8104,
0.7229,
0.6207,
0.5008,
0.3894,
0.2922,
0.2149,
0.1599
],
"gaussian_blur": [
[
0.992,
0.9879,
0.9682,
0.7731,
0.525
],
[
0.9796,
0.9801,
0.9512,
0.7381,
0.4862
],
[
0.96,
0.9674,
0.9271,
0.6922,
0.4446
],
[
0.926,
0.946,
0.8939,
0.6427,
0.3989
],
[
0.8753,
0.9133,
0.8516,
0.5881,
0.3603
],
[
0.8104,
0.869,
0.7989,
0.5278,
0.3263
],
[
0.7229,
0.8135,
0.7415,
0.471,
0.2968
],
[
0.6207,
0.7456,
0.6741,
0.4224,
0.2683
],
[
0.5008,
0.6636,
0.5983,
0.3755,
0.2453
],
[
0.3894,
0.5821,
0.5243,
0.3359,
0.2269
],
[
0.2922,
0.505,
0.4591,
0.3034,
0.2112
],
[
0.2149,
0.429,
0.3998,
0.2743,
0.1983
],
[
0.1599,
0.3648,
0.3481,
0.2493,
0.1884
]
],
"gaussian_kuwahara": [
[
0.9897,
0.9766,
0.9066,
0.7355,
0.5131
],
[
0.9808,
0.9667,
0.8909,
0.7035,
0.4824
],
[
0.9651,
0.9547,
0.87,
0.6713,
0.4538
],
[
0.9412,
0.9334,
0.8447,
0.6354,
0.426
],
[
0.9035,
0.9107,
0.8123,
0.597,
0.3915
],
[
0.8539,
0.8785,
0.7751,
0.5616,
0.362
],
[
0.7925,
0.8328,
0.7328,
0.5236,
0.3344
],
[
0.7078,
0.7808,
0.6816,
0.4868,
0.309
],
[
0.6125,
0.7179,
0.6301,
0.4513,
0.2865
],
[
0.4979,
0.646,
0.5773,
0.4242,
0.2702
],
[
0.3927,
0.564,
0.5197,
0.3859,
0.2493
],
[
0.3023,
0.4761,
0.4594,
0.3494,
0.2354
],
[
0.2289,
0.3839,
0.3981,
0.3182,
0.2232
]
],
"mean_kuwahara": [
[
0.988,
0.7536,
0.3667,
0.1763,
0.1339
],
[
0.9795,
0.7359,
0.3496,
0.171,
0.1318
],
[
0.965,
0.7129,
0.3295,
0.1637,
0.1286
],
[
0.946,
0.6871,
0.3119,
0.1578,
0.1244
],
[
0.916,
0.6617,
0.2841,
0.1497,
0.1228
],
[
0.8746,
0.6317,
0.2587,
0.1422,
0.1211
],
[
0.8235,
0.6019,
0.2395,
0.136,
0.1193
],
[
0.7499,
0.5699,
0.2253,
0.134,
0.1164
],
[
0.665,
0.542,
0.2168,
0.1335,
0.1138
],
[
0.5642,
0.5087,
0.2064,
0.1328,
0.1129
],
[
0.4739,
0.4773,
0.1993,
0.1306,
0.1145
],
[
0.3638,
0.437,
0.1921,
0.1309,
0.1159
],
[
0.2659,
0.3912,
0.1854,
0.1307,
0.1166
]
],
"random_noise": [
[
0.9913,
0.9899,
0.9872,
0.9719,
0.9226
],
[
0.9793,
0.9782,
0.9711,
0.9453,
0.8802
],
[
0.9603,
0.9568,
0.9436,
0.9049,
0.8184
],
[
0.9253,
0.9183,
0.895,
0.8392,
0.7432
],
[
0.8743,
0.8653,
0.8309,
0.7656,
0.6606
],
[
0.809,
0.7948,
0.7486,
0.6709,
0.5588
],
[
0.721,
0.6999,
0.6485,
0.5625,
0.4577
],
[
0.6157,
0.5881,
0.5377,
0.4548,
0.3647
],
[
0.5005,
0.4802,
0.4267,
0.3571,
0.2885
],
[
0.385,
0.3668,
0.3295,
0.2696,
0.2223
],
[
0.2918,
0.2758,
0.244,
0.2039,
0.1724
],
[
0.215,
0.2016,
0.1832,
0.1555,
0.1326
],
[
0.1591,
0.154,
0.1371,
0.1163,
0.1021
]
],
"bilateral_filter": [
[
0.9887,
0.9887,
0.9391,
0.5584,
0.2568
],
[
0.9809,
0.9809,
0.9184,
0.5198,
0.241
],
[
0.9695,
0.9695,
0.8902,
0.4831,
0.2245
],
[
0.9482,
0.9482,
0.8533,
0.4436,
0.2079
],
[
0.9142,
0.9142,
0.8133,
0.4019,
0.1915
],
[
0.8714,
0.8714,
0.7656,
0.3641,
0.1792
],
[
0.8169,
0.8169,
0.7098,
0.3299,
0.1681
],
[
0.7477,
0.7477,
0.641,
0.2978,
0.161
],
[
0.6619,
0.6619,
0.5683,
0.2723,
0.1563
],
[
0.5767,
0.5767,
0.5003,
0.2476,
0.1517
],
[
0.4922,
0.4922,
0.4381,
0.2288,
0.1484
],
[
0.4133,
0.4133,
0.3836,
0.2126,
0.146
],
[
0.3468,
0.3468,
0.3364,
0.1999,
0.1444
]
],
"bit_depth": [
[
0.9894,
0.9913,
0.9916,
0.992,
0.992
],
[
0.9862,
0.9823,
0.9807,
0.9796,
0.9796
],
[
0.9808,
0.9781,
0.965,
0.9604,
0.96
],
[
0.9744,
0.9228,
0.9219,
0.926,
0.926
],
[
0.9424,
0.8818,
0.8747,
0.8751,
0.8753
],
[
0.9307,
0.8621,
0.821,
0.8094,
0.8104
],
[
0.9157,
0.8408,
0.7427,
0.7235,
0.7229
],
[
0.8972,
0.7794,
0.6554,
0.6229,
0.6207
],
[
0.8799,
0.7496,
0.559,
0.5046,
0.5008
],
[
0.8581,
0.5289,
0.4547,
0.3914,
0.3894
],
[
0.7603,
0.4301,
0.3113,
0.2927,
0.2922
],
[
0.7227,
0.3992,
0.2414,
0.2168,
0.2149
],
[
0.2624,
0.2091,
0.1874,
0.161,
0.1599
]
],
"threshold_filter": [
[
0.982,
0.9817,
0.9799,
0.9713,
0.9502
],
[
0.978,
0.9755,
0.9751,
0.9655,
0.9334
],
[
0.9728,
0.9713,
0.9696,
0.9578,
0.9077
],
[
0.9678,
0.9668,
0.9645,
0.9508,
0.1837
],
[
0.9644,
0.9604,
0.9583,
0.9407,
0.1818
],
[
0.9586,
0.9537,
0.9477,
0.9238,
0.1817
],
[
0.9522,
0.9458,
0.9343,
0.9032,
0.1845
],
[
0.9418,
0.9387,
0.9236,
0.8766,
0.1849
],
[
0.9331,
0.9297,
0.9108,
0.8358,
0.1869
],
[
0.9215,
0.9188,
0.8927,
0.2164,
0.1904
],
[
0.9079,
0.9053,
0.8758,
0.223,
0.1927
],
[
0.8943,
0.8882,
0.8508,
0.2275,
0.1979
],
[
0.8761,
0.8687,
0.8142,
0.2348,
0.2025
]
]
}

View File

@ -19,6 +19,7 @@
"filters": {
"gaussian_blur": [
[
0.992,
0.992,
0.9879,
0.9682,
@ -26,6 +27,7 @@
0.525
],
[
0.9796,
0.9796,
0.9801,
0.9512,
@ -33,6 +35,7 @@
0.4862
],
[
0.96,
0.96,
0.9674,
0.9271,
@ -40,6 +43,7 @@
0.4446
],
[
0.926,
0.926,
0.946,
0.8939,
@ -47,6 +51,7 @@
0.3989
],
[
0.8753,
0.8753,
0.9133,
0.8516,
@ -54,6 +59,7 @@
0.3603
],
[
0.8104,
0.8104,
0.869,
0.7989,
@ -61,6 +67,7 @@
0.3263
],
[
0.7229,
0.7229,
0.8135,
0.7415,
@ -68,6 +75,7 @@
0.2968
],
[
0.6207,
0.6207,
0.7456,
0.6741,
@ -75,6 +83,7 @@
0.2683
],
[
0.5008,
0.5008,
0.6636,
0.5983,
@ -82,6 +91,7 @@
0.2453
],
[
0.3894,
0.3894,
0.5821,
0.5243,
@ -89,6 +99,7 @@
0.2269
],
[
0.2922,
0.2922,
0.505,
0.4591,
@ -96,6 +107,7 @@
0.2112
],
[
0.2149,
0.2149,
0.429,
0.3998,
@ -103,6 +115,7 @@
0.1983
],
[
0.1599,
0.1599,
0.3648,
0.3481,
@ -112,6 +125,7 @@
],
"gaussian_kuwahara": [
[
0.992,
0.9897,
0.9766,
0.9066,
@ -119,6 +133,7 @@
0.5131
],
[
0.9796,
0.9808,
0.9667,
0.8909,
@ -126,6 +141,7 @@
0.4824
],
[
0.96,
0.9651,
0.9547,
0.87,
@ -133,6 +149,7 @@
0.4538
],
[
0.926,
0.9412,
0.9334,
0.8447,
@ -140,6 +157,7 @@
0.426
],
[
0.8753,
0.9035,
0.9107,
0.8123,
@ -147,6 +165,7 @@
0.3915
],
[
0.8104,
0.8539,
0.8785,
0.7751,
@ -154,6 +173,7 @@
0.362
],
[
0.7229,
0.7925,
0.8328,
0.7328,
@ -161,6 +181,7 @@
0.3344
],
[
0.6207,
0.7078,
0.7808,
0.6816,
@ -168,6 +189,7 @@
0.309
],
[
0.5008,
0.6125,
0.7179,
0.6301,
@ -175,6 +197,7 @@
0.2865
],
[
0.3894,
0.4979,
0.646,
0.5773,
@ -182,6 +205,7 @@
0.2702
],
[
0.2922,
0.3927,
0.564,
0.5197,
@ -189,6 +213,7 @@
0.2493
],
[
0.2149,
0.3023,
0.4761,
0.4594,
@ -196,6 +221,7 @@
0.2354
],
[
0.1599,
0.2289,
0.3839,
0.3981,
@ -205,6 +231,7 @@
],
"mean_kuwahara": [
[
0.992,
0.988,
0.7536,
0.3667,
@ -212,6 +239,7 @@
0.1339
],
[
0.9796,
0.9795,
0.7359,
0.3496,
@ -219,6 +247,7 @@
0.1318
],
[
0.96,
0.965,
0.7129,
0.3295,
@ -226,6 +255,7 @@
0.1286
],
[
0.926,
0.946,
0.6871,
0.3119,
@ -233,6 +263,7 @@
0.1244
],
[
0.8753,
0.916,
0.6617,
0.2841,
@ -240,6 +271,7 @@
0.1228
],
[
0.8104,
0.8746,
0.6317,
0.2587,
@ -247,6 +279,7 @@
0.1211
],
[
0.7229,
0.8235,
0.6019,
0.2395,
@ -254,6 +287,7 @@
0.1193
],
[
0.6207,
0.7499,
0.5699,
0.2253,
@ -261,6 +295,7 @@
0.1164
],
[
0.5008,
0.665,
0.542,
0.2168,
@ -268,6 +303,7 @@
0.1138
],
[
0.3894,
0.5642,
0.5087,
0.2064,
@ -275,6 +311,7 @@
0.1129
],
[
0.2922,
0.4739,
0.4773,
0.1993,
@ -282,6 +319,7 @@
0.1145
],
[
0.2149,
0.3638,
0.437,
0.1921,
@ -289,6 +327,7 @@
0.1159
],
[
0.1599,
0.2659,
0.3912,
0.1854,
@ -298,6 +337,7 @@
],
"random_noise": [
[
0.992,
0.9913,
0.9899,
0.9872,
@ -305,6 +345,7 @@
0.9226
],
[
0.9796,
0.9793,
0.9782,
0.9711,
@ -312,6 +353,7 @@
0.8802
],
[
0.96,
0.9603,
0.9568,
0.9436,
@ -319,6 +361,7 @@
0.8184
],
[
0.926,
0.9253,
0.9183,
0.895,
@ -326,6 +369,7 @@
0.7432
],
[
0.8753,
0.8743,
0.8653,
0.8309,
@ -333,6 +377,7 @@
0.6606
],
[
0.8104,
0.809,
0.7948,
0.7486,
@ -340,6 +385,7 @@
0.5588
],
[
0.7229,
0.721,
0.6999,
0.6485,
@ -347,6 +393,7 @@
0.4577
],
[
0.6207,
0.6157,
0.5881,
0.5377,
@ -354,6 +401,7 @@
0.3647
],
[
0.5008,
0.5005,
0.4802,
0.4267,
@ -361,6 +409,7 @@
0.2885
],
[
0.3894,
0.385,
0.3668,
0.3295,
@ -368,6 +417,7 @@
0.2223
],
[
0.2922,
0.2918,
0.2758,
0.244,
@ -375,6 +425,7 @@
0.1724
],
[
0.2149,
0.215,
0.2016,
0.1832,
@ -382,6 +433,7 @@
0.1326
],
[
0.1599,
0.1591,
0.154,
0.1371,
@ -391,6 +443,7 @@
],
"bilateral_filter": [
[
0.992,
0.9887,
0.9887,
0.9391,
@ -398,6 +451,7 @@
0.2568
],
[
0.9796,
0.9809,
0.9809,
0.9184,
@ -405,6 +459,7 @@
0.241
],
[
0.96,
0.9695,
0.9695,
0.8902,
@ -412,6 +467,7 @@
0.2245
],
[
0.926,
0.9482,
0.9482,
0.8533,
@ -419,6 +475,7 @@
0.2079
],
[
0.8753,
0.9142,
0.9142,
0.8133,
@ -426,6 +483,7 @@
0.1915
],
[
0.8104,
0.8714,
0.8714,
0.7656,
@ -433,6 +491,7 @@
0.1792
],
[
0.7229,
0.8169,
0.8169,
0.7098,
@ -440,6 +499,7 @@
0.1681
],
[
0.6207,
0.7477,
0.7477,
0.641,
@ -447,6 +507,7 @@
0.161
],
[
0.5008,
0.6619,
0.6619,
0.5683,
@ -454,6 +515,7 @@
0.1563
],
[
0.3894,
0.5767,
0.5767,
0.5003,
@ -461,6 +523,7 @@
0.1517
],
[
0.2922,
0.4922,
0.4922,
0.4381,
@ -468,6 +531,7 @@
0.1484
],
[
0.2149,
0.4133,
0.4133,
0.3836,
@ -475,6 +539,7 @@
0.146
],
[
0.1599,
0.3468,
0.3468,
0.3364,
@ -485,98 +550,112 @@
"bit_depth": [
[
0.992,
0.992,
0.9916,
0.9894,
0.9913,
0.9894
0.9916,
0.992,
0.992
],
[
0.9796,
0.9796,
0.9807,
0.9862,
0.9823,
0.9862
0.9807,
0.9796,
0.9796
],
[
0.96,
0.9604,
0.965,
0.9808,
0.9781,
0.9808
0.965,
0.9604,
0.96
],
[
0.926,
0.926,
0.9219,
0.9744,
0.9228,
0.9744
0.9219,
0.926,
0.926
],
[
0.8753,
0.8751,
0.8747,
0.9424,
0.8818,
0.9424
0.8747,
0.8751,
0.8753
],
[
0.8104,
0.8094,
0.821,
0.9307,
0.8621,
0.9307
0.821,
0.8094,
0.8104
],
[
0.7229,
0.7235,
0.7427,
0.9157,
0.8408,
0.9157
0.7427,
0.7235,
0.7229
],
[
0.6207,
0.6229,
0.6554,
0.8972,
0.7794,
0.8972
0.6554,
0.6229,
0.6207
],
[
0.5008,
0.5046,
0.559,
0.8799,
0.7496,
0.8799
0.559,
0.5046,
0.5008
],
[
0.3894,
0.3914,
0.4547,
0.8581,
0.5289,
0.8581
0.4547,
0.3914,
0.3894
],
[
0.2922,
0.2927,
0.3113,
0.7603,
0.4301,
0.7603
0.3113,
0.2927,
0.2922
],
[
0.2149,
0.2168,
0.2414,
0.7227,
0.3992,
0.7227
0.2414,
0.2168,
0.2149
],
[
0.1599,
0.161,
0.1874,
0.2624,
0.2091,
0.2624
0.1874,
0.161,
0.1599
]
],
"threshold_filter": [
[
0.992,
0.982,
0.9817,
0.9799,
@ -584,6 +663,7 @@
0.9502
],
[
0.9796,
0.978,
0.9755,
0.9751,
@ -591,6 +671,7 @@
0.9334
],
[
0.96,
0.9728,
0.9713,
0.9696,
@ -598,6 +679,7 @@
0.9077
],
[
0.926,
0.9678,
0.9668,
0.9645,
@ -605,6 +687,7 @@
0.1837
],
[
0.8753,
0.9644,
0.9604,
0.9583,
@ -612,6 +695,7 @@
0.1818
],
[
0.8104,
0.9586,
0.9537,
0.9477,
@ -619,6 +703,7 @@
0.1817
],
[
0.7229,
0.9522,
0.9458,
0.9343,
@ -626,6 +711,7 @@
0.1845
],
[
0.6207,
0.9418,
0.9387,
0.9236,
@ -633,6 +719,7 @@
0.1849
],
[
0.5008,
0.9331,
0.9297,
0.9108,
@ -640,6 +727,7 @@
0.1869
],
[
0.3894,
0.9215,
0.9188,
0.8927,
@ -647,6 +735,7 @@
0.1904
],
[
0.2922,
0.9079,
0.9053,
0.8758,
@ -654,6 +743,7 @@
0.1927
],
[
0.2149,
0.8943,
0.8882,
0.8508,
@ -661,6 +751,7 @@
0.1979
],
[
0.1599,
0.8761,
0.8687,
0.8142,
@ -669,4 +760,4 @@
]
]
}
}
}

View File

@ -12,7 +12,7 @@ def main():
has_random_guessing_threshold = False
data = {}
with open("results/cifar10_fgsm.json", "r") as infile:
with open("../results/mnist_fgsm_reformatted.json", "r") as infile:
data = json.load(infile)
attack = data["attack"]
@ -110,7 +110,7 @@ def main():
plt.xlabel("Filter Strength", fontsize=18)
ax.set_zlabel(f"{dataset} Classification Accuracy", fontsize=18)
#score_type = "highest_rank" if is_rank else "performance_map"
plt.savefig(f"{dataset}_{attack}_3d.png")
plt.savefig(f"../results/{dataset}_{attack}_3d_new.png")
plt.show()
if __name__ == "__main__":

View File

@ -4,27 +4,36 @@ import copy
def reformat_data():
results = {}
with open("results/mnist_fgsm.json", "r") as infile:
with open("../results/mnist_fgsm_old.json", "r") as infile:
results = json.load(infile)
#reformatted_results = {}
reformatted_results = {}
#reformatted_results["dataset"] = "MNIST"
#reformatted_results["attack"] = "FGSM"
reformatted_results["dataset"] = "MNIST"
reformatted_results["attack"] = "FGSM"
#MAX_EPSILON = 0.3
#EPSILON_STEP = 0.025
#epsilons = np.arange(0.0, MAX_EPSILON+EPSILON_STEP, EPSILON_STEP)
MAX_EPSILON = 0.3
EPSILON_STEP = 0.025
epsilons = np.arange(0.0, MAX_EPSILON+EPSILON_STEP, EPSILON_STEP)
reformatted_results["epsilons"] = list(epsilons)
#reformatted_results["epsilons"] = list(epsilons)
reformatted_results = copy.deepcopy(results)
filters = list(results.keys())[1:]
for i, epsilon in enumerate(results["epsilons"]):
reformatted_results["filters"]["bit_depth"][i] = results["filters"]["bit_depth"][i][::-1]
reformatted_results["filters"] = {}
for filter in filters:
reformatted_results["filters"][filter] = []
for i, epsilon in enumerate(epsilons):
strength_perfs = [results["unfiltered"][i]]
strength_perfs.extend(results[filter][i])
reformatted_results["filters"][filter].append(strength_perfs)
#reformatted_results = copy.deepcopy(results)
#for i, epsilon in enumerate(results["epsilons"]):
# reformatted_results["filters"]["bit_depth"][i] = results["filters"]["bit_depth"][i][::-1]
reformatted_results_json = json.dumps(reformatted_results, indent=4)
with open("results/mnist_fgsm_reformatted.json", "w") as outfile:
with open("../results/mnist_fgsm_reformatted.json", "w") as outfile:
outfile.write(reformatted_results_json)
if __name__ == "__main__":