Trained VGG16 on CIFAR-10, displayed results

This commit is contained in:
Adog64 2024-04-28 11:19:06 -04:00
parent 2f0a6fc919
commit 54ed4466bc
9 changed files with 747 additions and 59 deletions

View File

@ -1 +0,0 @@
,sharpe,dhcp-150-250-221-61,25.04.2024 11:36,file:///home/sharpe/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;

1
.~lock.Poster.pptx# Normal file
View File

@ -0,0 +1 @@
,sharpe,dhcp-150-250-90-28,28.04.2024 00:39,file:///home/sharpe/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;

Binary file not shown.

Binary file not shown.

View File

@ -6,31 +6,32 @@ import copy
def main():
results = {}
data = {}
with open("results/mnist_fgsm.json", "r") as infile:
results = json.load(infile)
data = json.load(infile)
attack = data["attack"]
epsilons = data["epsilons"]
filters = data["filters"]
dataset = data["dataset"]
strength_count = len(filters[list(filters.keys())[0]][0])
filters = list(results.keys())[1:]
#epsilons = np.
for filter in filters:
filter_performance = copy.deepcopy(results[filter])
for i in range(len(results["unfiltered"])):
filter_performance[i].insert(0, results["unfiltered"][i])
plt.figure(figsize=(16,9))
plt.plot(epsilons, unfiltered_accuracies, label="Attacked Accuracy")
plt.figure(figsize=(16,9))
for i in range(strength_count):
filter_accuracy = [filters[filter][eps][i] for eps in range(len(epsilons))]
plt.plot(epsilons, filter_accuracy, label=f"Strength = {i}")
for i in range(TESTED_STRENGTH_COUNT):
filtered_accuracy = [filter_eps[i] for filter_eps in filter_performance]
plt.plot(epsilons, filtered_accuracy, label=f"Strength = {i}")
# Plot horizontal line at random guessing level
plt.hlines(0.1, epsilons[0], epsilons[-1], label="Random Guessing Threshold", colors="black", linestyles="dashed")
plt.legend(loc="upper right")
plt.title(f"{filter} Performance")
plt.xlabel("Attack Strength ($\\epsilon$)")
plt.ylabel("Accuracy")
plt.xlabel(f"{attack} Attack Strength ($\\epsilon$)")
plt.ylabel(f"{dataset} Classification Accuracy")
plt.show()
if __name__ == "__main__":
main()

View File

@ -19,60 +19,744 @@
"filters": {
"gaussian_blur": [
[
0.5442,
0.5442,
0.3986,
0.3178,
0.2561,
0.2342
0.7831,
0.7831,
0.6307,
0.4858,
0.3495,
0.2917
],
[
0.0575,
0.0575,
0.1289,
0.1818,
0.1955,
0.1889
0.0878,
0.0878,
0.2366,
0.2755,
0.253,
0.2351
],
[
0.0308,
0.0308,
0.0516,
0.1029,
0.1501,
0.1572
0.0444,
0.0444,
0.0937,
0.1522,
0.1768,
0.1856
],
[
0.0298,
0.0298,
0.0349,
0.0655,
0.1144,
0.1306
0.0424,
0.0424,
0.0442,
0.0853,
0.1286,
0.147
],
[
0.0327,
0.0327,
0.0294,
0.0497,
0.0576,
0.0576,
0.0295,
0.0522,
0.093,
0.1166
],
[
0.0673,
0.0673,
0.0224,
0.04,
0.0705,
0.0943
],
[
0.0781,
0.0781,
0.0204,
0.0333,
0.0569,
0.0798
],
[
0.0824,
0.0824,
0.0192,
0.0306,
0.0498,
0.0667
],
[
0.0851,
0.0851,
0.0189,
0.0279,
0.0447,
0.06
],
[
0.0885,
0.0885,
0.019,
0.0259,
0.0408,
0.0541
],
[
0.091,
0.091,
0.0196,
0.026,
0.0361,
0.049
],
[
0.0921,
0.0921,
0.02,
0.0252,
0.035,
0.0456
],
[
0.0929,
0.0929,
0.0211,
0.0245,
0.033,
0.043
]
],
"gaussian_kuwahara": [
[
0.7831,
0.6793,
0.3977,
0.2908,
0.2426,
0.2151
],
[
0.0878,
0.181,
0.2543,
0.2294,
0.2081,
0.1957
],
[
0.0444,
0.07,
0.1498,
0.1741,
0.1735,
0.1658
],
[
0.0424,
0.0413,
0.0976,
0.132,
0.1508,
0.1464
],
[
0.0576,
0.0345,
0.0724,
0.102,
0.1225,
0.1281
],
[
0.0673,
0.0321,
0.057,
0.0801,
0.0995,
0.1144
],
[
0.0781,
0.0345,
0.052,
0.0656,
0.0854,
0.0983
],
[
0.0824,
0.0367,
0.0433,
0.0608,
0.0776,
0.0931
],
[
0.0851,
0.0403,
0.0401,
0.0542,
0.0699,
0.077
],
[
0.0885,
0.0435,
0.0392,
0.051,
0.0628,
0.0731
],
[
0.091,
0.0495,
0.0369,
0.0491,
0.0579,
0.0689
],
[
0.0921,
0.0514,
0.0377,
0.0455,
0.0578,
0.0664
],
[
0.0929,
0.0552,
0.0364,
0.0469,
0.0574,
0.0688
]
],
"mean_kuwahara": [
[
0.7831,
0.5565,
0.2659,
0.1965,
0.1729,
0.1537
],
[
0.0878,
0.2454,
0.2261,
0.1866,
0.1639,
0.1498
],
[
0.0444,
0.115,
0.1851,
0.1754,
0.1569,
0.1462
],
[
0.0424,
0.0663,
0.1496,
0.1515,
0.1477,
0.1408
],
[
0.0576,
0.0491,
0.1245,
0.1354,
0.1415,
0.1386
],
[
0.0673,
0.0388,
0.1032,
0.1239,
0.1261,
0.1297
],
[
0.0781,
0.038,
0.0885,
0.1118,
0.1227,
0.1296
],
[
0.0824,
0.0381,
0.0724,
0.103,
0.1165,
0.1197
],
[
0.0851,
0.0345,
0.0661,
0.0947,
0.1046,
0.114
],
[
0.0885,
0.0404,
0.0647,
0.0854,
0.1027,
0.1122
],
[
0.091,
0.0418,
0.0572,
0.0813,
0.1002,
0.1095
],
[
0.0921,
0.0465,
0.0524,
0.0778,
0.0906,
0.1075
],
[
0.0929,
0.0488,
0.0565,
0.0738,
0.0931,
0.1053
]
],
"random_noise": [
[
0.7831,
0.748,
0.4956,
0.2392,
0.137,
0.1147
],
[
0.0878,
0.0902,
0.1256,
0.1294,
0.1139,
0.1087
],
[
0.0444,
0.0474,
0.0656,
0.09,
0.1024,
0.1023
],
[
0.0424,
0.0466,
0.0632,
0.0877,
0.0969,
0.1003
],
[
0.0576,
0.0574,
0.0687,
0.0887,
0.0945,
0.099
],
[
0.0673,
0.0688,
0.0779,
0.0915,
0.0963,
0.0997
],
[
0.0781,
0.0796,
0.0845,
0.0923,
0.0973,
0.0992
],
[
0.0824,
0.0839,
0.0877,
0.0933,
0.1081
0.0972,
0.0978
],
[
0.0364,
0.0364,
0.031,
0.046,
0.0817,
0.0851,
0.0854,
0.0896,
0.0955,
0.0972,
0.0986
],
[
0.0885,
0.0885,
0.0927,
0.0953,
0.0964,
0.0983
],
[
0.091,
0.091,
0.094,
0.0952,
0.0972,
0.0981
],
[
0.0921,
0.0928,
0.0942,
0.0955,
0.0983,
0.0983
],
[
0.0929,
0.0936,
0.0948,
0.0958,
0.0973,
0.0981
]
],
"bilateral_filter": [
[
0.7831,
0.6698,
0.6698,
0.4637,
0.3068,
0.2546
],
[
0.0878,
0.2254,
0.2254,
0.2572,
0.2318,
0.2258
],
[
0.0444,
0.0828,
0.0828,
0.1386,
0.1789,
0.1976
],
[
0.0424,
0.0423,
0.0423,
0.0827,
0.1336,
0.1692
],
[
0.0576,
0.0296,
0.0296,
0.0573,
0.1029,
0.1431
],
[
0.0673,
0.0258,
0.0258,
0.0448,
0.083,
0.1192
],
[
0.0781,
0.0228,
0.0228,
0.0389,
0.0708,
0.1046
],
[
0.0824,
0.0225,
0.0225,
0.035,
0.0649,
0.0922
],
[
0.0851,
0.0226,
0.0226,
0.0321,
0.0607,
0.0831
],
[
0.0885,
0.0225,
0.0225,
0.0322,
0.0573,
0.0783
],
[
0.091,
0.024,
0.024,
0.0311,
0.0548,
0.0741
],
[
0.0921,
0.0256,
0.0256,
0.0304,
0.0536,
0.0711
],
[
0.0929,
0.0278,
0.0278,
0.0292,
0.0513,
0.0671
]
],
"bit_depth": [
[
0.7831,
0.2441,
0.6564,
0.773,
0.7822,
0.7831
],
[
0.0878,
0.1367,
0.1143,
0.0895,
0.0876,
0.0878
],
[
0.0444,
0.1018,
0.0567,
0.0448,
0.0443,
0.0444
],
[
0.0424,
0.0936,
0.0493,
0.0426,
0.0422,
0.0424
],
[
0.0576,
0.0887,
0.0558,
0.0552,
0.0573,
0.0576
],
[
0.0673,
0.0907,
0.0624,
0.0661,
0.0673,
0.0673
],
[
0.0781,
0.0841,
0.0687,
0.0757,
0.0783,
0.0781
],
[
0.0824,
0.0853,
0.0747,
0.0811,
0.0825,
0.0824
],
[
0.0851,
0.0836,
0.0787,
0.0844,
0.085,
0.0851
],
[
0.0885,
0.0854,
0.0823,
0.0866,
0.0885,
0.0885
],
[
0.091,
0.0833,
0.0849,
0.0885,
0.0908,
0.091
],
[
0.0921,
0.0841,
0.0869,
0.0909,
0.092,
0.0921
],
[
0.0929,
0.0826,
0.0879,
0.0922,
0.0928,
0.0929
]
],
"threshold_filter": [
[
0.7831,
0.2138,
0.1522,
0.1163,
0.0998,
0.0999
],
[
0.0878,
0.1474,
0.121,
0.0971,
0.0997,
0.1
],
[
0.0444,
0.1137,
0.1019,
0.0947,
0.0993,
0.1
],
[
0.0424,
0.097,
0.0883,
0.0937,
0.0976,
0.1
],
[
0.0576,
0.088,
0.0806,
0.0895,
0.094,
0.0978
],
[
0.0673,
0.0853,
0.0792,
0.0845,
0.0957,
0.1
],
[
0.0781,
0.079,
0.0779,
0.0841,
0.0937,
0.1011
],
[
0.0824,
0.0825,
0.0793,
0.0792,
0.0919,
0.0994
],
[
0.0851,
0.0842,
0.083,
0.0806,
0.0921,
0.0986
],
[
0.0885,
0.0858,
0.0825,
0.0793,
0.0896,
0.0984
],
[
0.091,
0.0911,
0.083,
0.0797,
0.0869,
0.0978
],
[
0.0921,
0.0916,
0.0872,
0.0824,
0.083,
0.0967
],
[
0.0449,
0.0449,
0.0319,
0.0439,
0.0733,
0.0885
0.0929,
0.0952,
0.0891,
0.0823,
0.0847,
0.0954
]
]
}

View File

@ -3,11 +3,14 @@ import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import mnist
import cifar10
import vgg
import json
import sys
@ -28,7 +31,7 @@ EPSILON_STEP = 0.025
TESTED_STRENGTH_COUNT = 5
epsilons = np.arange(0.0, MAX_EPSILON+EPSILON_STEP, EPSILON_STEP)
pretrained_model = "cifar_net.pth"
pretrained_model = "cifar_vgg.pth"
use_cuda=False
torch.manual_seed(69)
@ -49,7 +52,7 @@ test_loader = torch.utils.data.DataLoader(testset, batch_size=batch_size, shuffl
print("CUDA Available: ", torch.cuda.is_available())
device = torch.device("cuda" if use_cuda and torch.cuda.is_available() else "cpu")
model = cifar10.Net().to(device)
model = vgg.VGG("VGG16").to(device)
model.load_state_dict(torch.load(pretrained_model, map_location=device))

BIN
Poster.pptx Normal file

Binary file not shown.