Directory structure overhaul, poster almost done

This commit is contained in:
Aidan Sharpe
2024-05-01 01:26:25 -04:00
parent bf2440ef86
commit 008ef906d7
106 changed files with 58 additions and 20 deletions

View File

@ -1 +0,0 @@
,sharpe,dhcp-150-250-208-169,30.04.2024 21:44,file:///home/sharpe/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 221 KiB

After

Width:  |  Height:  |  Size: 221 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 115 KiB

View File

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 117 KiB

View File

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 168 KiB

View File

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 115 KiB

View File

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 137 KiB

View File

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 164 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View File

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

View File

Before

Width:  |  Height:  |  Size: 202 B

After

Width:  |  Height:  |  Size: 202 B

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 132 KiB

View File

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View File

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 163 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,4 @@
import matplotlib.pyplot as plt
import cv2 import cv2
from pykuwahara import kuwahara from pykuwahara import kuwahara
import numpy as np import numpy as np
@ -26,6 +27,10 @@ def gaussian_kuwahara(data, dimensions, radius=5):
for i in range(dimensions[0]): for i in range(dimensions[0]):
filtered_images[i] = kuwahara(images[i], method='gaussian', radius=radius, image_2d=images[i]) filtered_images[i] = kuwahara(images[i], method='gaussian', radius=radius, image_2d=images[i])
if i == 0 and radius == 5:
plt.title("Gaussian Kuwahara", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()
@ -37,6 +42,10 @@ def mean_kuwahara(data, dimensions, radius=5):
for i in range(dimensions[0]): for i in range(dimensions[0]):
filtered_images[i] = kuwahara(images[i], method='mean', radius=radius, image_2d=images[i]) filtered_images[i] = kuwahara(images[i], method='mean', radius=radius, image_2d=images[i])
if i == 0 and radius == 5:
plt.title("Mean Kuwahara", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()
@ -52,6 +61,11 @@ def random_noise(data, dimensions, intensity=0.001):
noise = np.zeros(images[i].shape, images[i].dtype) noise = np.zeros(images[i].shape, images[i].dtype)
cv2.randn(noise, mean, stddev) cv2.randn(noise, mean, stddev)
filtered_images[i] = cv2.addWeighted(images[i], 1.0, noise, intensity, 0.0).reshape(filtered_images[i].shape) filtered_images[i] = cv2.addWeighted(images[i], 1.0, noise, intensity, 0.0).reshape(filtered_images[i].shape)
if i == 0 and intensity == 0.0015:
plt.title("Random Noise", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()
@ -63,6 +77,13 @@ def gaussian_blur(data, dimensions, ksize=(5,5)):
for i in range(dimensions[0]): for i in range(dimensions[0]):
filtered_images[i] = cv2.GaussianBlur(images[i], ksize=ksize, sigmaX=0).reshape(filtered_images[i].shape) filtered_images[i] = cv2.GaussianBlur(images[i], ksize=ksize, sigmaX=0).reshape(filtered_images[i].shape)
if i == 0 and ksize[0] == 5:
plt.title("Unfiltered", fontsize=40)
plt.imshow(images[i], cmap='gray')
plt.show()
plt.title("Gaussian Blur", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()
@ -74,6 +95,10 @@ def bilateral_filter(data, dimensions, d=5, sigma=50):
for i in range(dimensions[0]): for i in range(dimensions[0]):
filtered_images[i] = cv2.bilateralFilter(images[i], d, sigma, sigma).reshape(filtered_images[i].shape) filtered_images[i] = cv2.bilateralFilter(images[i], d, sigma, sigma).reshape(filtered_images[i].shape)
if i == 0 and d == 5:
plt.title("Bilateral Filter", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()
@ -100,6 +125,11 @@ def threshold_filter(data, dimensions, threshold=0.5):
if min_value < 0: if min_value < 0:
filtered_images[i] -= min_value filtered_images[i] -= min_value
if i == 0 and threshold == 0.5:
plt.title("Threshold Filter", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()
@ -111,6 +141,12 @@ def bit_depth(data, dimensions, bits=16):
for i in range(dimensions[0]): for i in range(dimensions[0]):
filtered_images[i] = (images[i]*(2**bits)).astype(int).astype(float)/(2**bits) filtered_images[i] = (images[i]*(2**bits)).astype(int).astype(float)/(2**bits)
if i == 0 and bits == 4:
plt.title("Bit-Depth", fontsize=40)
plt.imshow(filtered_images[i], cmap='gray')
plt.show()
filtered_images = filtered_images.transpose(0,3,1,2) filtered_images = filtered_images.transpose(0,3,1,2)
return torch.tensor(filtered_images).float() return torch.tensor(filtered_images).float()

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -20,39 +20,40 @@ import defense_filters
ATTACK = "FGSM" ATTACK = "FGSM"
DATASET = "CIFAR-10" DATASET = "MNIST"
RES_X = 32 RES_X = 28
RES_Y = 32 RES_Y = 28
CHANNELS = 3 CHANNELS = 1
MIN_EPSILON = 0.2
MAX_EPSILON = 0.3 MAX_EPSILON = 0.3
EPSILON_STEP = 0.025 EPSILON_STEP = 0.025
TESTED_STRENGTH_COUNT = 5 TESTED_STRENGTH_COUNT = 5
epsilons = np.arange(0.0, MAX_EPSILON+EPSILON_STEP, EPSILON_STEP) epsilons = np.arange(MIN_EPSILON, MAX_EPSILON+EPSILON_STEP, EPSILON_STEP)
pretrained_model = "cifar_vgg.pth" pretrained_model = "mnist_cnn_unfiltered.pt"
use_cuda=False use_cuda=False
torch.manual_seed(69) torch.manual_seed(69)
#test_loader = torch.utils.data.DataLoader( test_loader = torch.utils.data.DataLoader(
# datasets.MNIST('data/', train=False, download=True, transform=transforms.Compose([ datasets.MNIST('data/', train=False, download=True, transform=transforms.Compose([
# transforms.ToTensor(), transforms.ToTensor(),
# transforms.Normalize((0.1307,), (0.3081,)), transforms.Normalize((0.1307,), (0.3081,)),
# ])), ])),
# batch_size=1, shuffle=True) batch_size=1, shuffle=False)
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) #transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
batch_size = 1 #batch_size = 1
testset = datasets.CIFAR10(root='./data', train=False, download=True, transform=transform) #testset = datasets.CIFAR10(root='./data', train=False, download=True, transform=transform)
test_loader = torch.utils.data.DataLoader(testset, batch_size=batch_size, shuffle=True, num_workers=2) #test_loader = torch.utils.data.DataLoader(testset, batch_size=batch_size, shuffle=True, num_workers=2)
print("CUDA Available: ", torch.cuda.is_available()) print("CUDA Available: ", torch.cuda.is_available())
device = torch.device("cuda" if use_cuda and torch.cuda.is_available() else "cpu") device = torch.device("cuda" if use_cuda and torch.cuda.is_available() else "cpu")
model = vgg.VGG("VGG16").to(device) model = mnist.Net().to(device)
model.load_state_dict(torch.load(pretrained_model, map_location=device)) model.load_state_dict(torch.load(pretrained_model, map_location=device))
@ -150,6 +151,7 @@ def test(model, device, test_loader, epsilon, filter):
while i >= len(filtered_correct_counts): while i >= len(filtered_correct_counts):
filtered_correct_counts.append(0) filtered_correct_counts.append(0)
filtered_correct_counts[i] += 1 filtered_correct_counts[i] += 1
return
# Get the predicted classification # Get the predicted classification
unfiltered_pred = output_unfiltered.max(1, keepdim=True)[1] unfiltered_pred = output_unfiltered.max(1, keepdim=True)[1]
@ -199,8 +201,9 @@ for filter in filters:
results["filters"][filter].append(accuracies) results["filters"][filter].append(accuracies)
results_json = json.dumps(results, indent=4) results_json = json.dumps(results, indent=4)
with open("results/cifar10_fgsm.json", "w") as outfile: break
outfile.write(results_json) #with open("results/cifar10_fgsm.json", "w") as outfile:
# outfile.write(results_json)
# Plot the results # Plot the results
#plt.figure(figsize=(16,9)) #plt.figure(figsize=(16,9))

View File

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

Before

Width:  |  Height:  |  Size: 266 KiB

After

Width:  |  Height:  |  Size: 266 KiB

Some files were not shown because too many files have changed in this diff Show More