Tested performance with varying radii for Gaussian and Mean Kuwahara Filter

This commit is contained in:
Adog64 2024-04-11 16:56:51 -04:00
parent 90915efb7e
commit 26758224b7
6 changed files with 427 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

View File

@ -121,7 +121,7 @@ def test(model, device, test_loader, epsilon):
strength = 2*i + 1 strength = 2*i + 1
# Apply the filter with the specified strength # Apply the filter with the specified strength
filtered_input = defense_filters.gaussian_kuwahara(perturbed_data_normalized, batch_size=len(perturbed_data_normalized), radius=strength) filtered_input = defense_filters.mean_kuwahara(perturbed_data_normalized, batch_size=len(perturbed_data_normalized), radius=strength)
# Evaluate the model on the filtered images # Evaluate the model on the filtered images
filtered_output = model(filtered_input) filtered_output = model(filtered_input)
# Get the predicted classification # Get the predicted classification
@ -158,7 +158,7 @@ def test(model, device, test_loader, epsilon):
print(f"Unfiltered Accuracy = {unfiltered_correct} / {len(test_loader)} = {unfiltered_acc}") print(f"Unfiltered Accuracy = {unfiltered_correct} / {len(test_loader)} = {unfiltered_acc}")
for i in range(TESTED_STRENGTH_COUNT): for i in range(TESTED_STRENGTH_COUNT):
strength = 2*i + 1 strength = 2*i + 1
print(f"Gaussian Kuwahara (strength = {strength}) = {filtered_correct_counts[i]} / {len(test_loader)} = {filtered_accuracies[i]}") print(f"Mean Kuwahara (strength = {strength}) = {filtered_correct_counts[i]} / {len(test_loader)} = {filtered_accuracies[i]}")
return unfiltered_acc, filtered_accuracies return unfiltered_acc, filtered_accuracies
@ -174,7 +174,8 @@ for eps in epsilons:
# Plot the results # Plot the results
plt.plot(epsilons, unfiltered_accuracies, label="Attacked Accuracy") plt.plot(epsilons, unfiltered_accuracies, label="Attacked Accuracy")
for i in range(TESTED_STRENGTH_COUNT): for i in range(TESTED_STRENGTH_COUNT):
plt.plot(epsilons, filtered_accuracies[i], label=f"Gaussian Kuwahara (strength = {2*i + 1})") filtered_accuracy = [filter_eps[i] for filter_eps in filtered_accuracies]
plt.plot(epsilons, filtered_accuracy, label=f"Mean Kuwahara (strength = {2*i + 1})")
plt.legend() plt.legend()

View File

@ -319,3 +319,426 @@ Snapped Color Accuracy = 2091 / 10000 = 0.2091
1 Bit Accuracy = 5462 / 10000 = 0.5462 1 Bit Accuracy = 5462 / 10000 = 0.5462
Plurality Vote Accuracy = 3287 / 10000 = 0.3287 Plurality Vote Accuracy = 3287 / 10000 = 0.3287
## Gaussian Kuwahara Filter with Varying Radius
### Raw Program Output
====== EPSILON: 0.0 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9920 / 10000 = 0.992
Gaussian Kuwahara (strength = 1) = 9897 / 10000 = 0.9897
Gaussian Kuwahara (strength = 3) = 9766 / 10000 = 0.9766
Gaussian Kuwahara (strength = 5) = 9066 / 10000 = 0.9066
Gaussian Kuwahara (strength = 7) = 7355 / 10000 = 0.7355
Gaussian Kuwahara (strength = 9) = 5131 / 10000 = 0.5131
====== EPSILON: 0.025 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9796 / 10000 = 0.9796
Gaussian Kuwahara (strength = 1) = 9808 / 10000 = 0.9808
Gaussian Kuwahara (strength = 3) = 9667 / 10000 = 0.9667
Gaussian Kuwahara (strength = 5) = 8909 / 10000 = 0.8909
Gaussian Kuwahara (strength = 7) = 7035 / 10000 = 0.7035
Gaussian Kuwahara (strength = 9) = 4824 / 10000 = 0.4824
====== EPSILON: 0.05 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9600 / 10000 = 0.96
Gaussian Kuwahara (strength = 1) = 9651 / 10000 = 0.9651
Gaussian Kuwahara (strength = 3) = 9547 / 10000 = 0.9547
Gaussian Kuwahara (strength = 5) = 8700 / 10000 = 0.87
Gaussian Kuwahara (strength = 7) = 6713 / 10000 = 0.6713
Gaussian Kuwahara (strength = 9) = 4538 / 10000 = 0.4538
====== EPSILON: 0.07500000000000001 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9260 / 10000 = 0.926
Gaussian Kuwahara (strength = 1) = 9412 / 10000 = 0.9412
Gaussian Kuwahara (strength = 3) = 9334 / 10000 = 0.9334
Gaussian Kuwahara (strength = 5) = 8447 / 10000 = 0.8447
Gaussian Kuwahara (strength = 7) = 6354 / 10000 = 0.6354
Gaussian Kuwahara (strength = 9) = 4260 / 10000 = 0.426
====== EPSILON: 0.1 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 8753 / 10000 = 0.8753
Gaussian Kuwahara (strength = 1) = 9035 / 10000 = 0.9035
Gaussian Kuwahara (strength = 3) = 9107 / 10000 = 0.9107
Gaussian Kuwahara (strength = 5) = 8123 / 10000 = 0.8123
Gaussian Kuwahara (strength = 7) = 5970 / 10000 = 0.597
Gaussian Kuwahara (strength = 9) = 3915 / 10000 = 0.3915
====== EPSILON: 0.125 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 8104 / 10000 = 0.8104
Gaussian Kuwahara (strength = 1) = 8539 / 10000 = 0.8539
Gaussian Kuwahara (strength = 3) = 8785 / 10000 = 0.8785
Gaussian Kuwahara (strength = 5) = 7751 / 10000 = 0.7751
Gaussian Kuwahara (strength = 7) = 5616 / 10000 = 0.5616
Gaussian Kuwahara (strength = 9) = 3620 / 10000 = 0.362
====== EPSILON: 0.15000000000000002 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 7229 / 10000 = 0.7229
Gaussian Kuwahara (strength = 1) = 7925 / 10000 = 0.7925
Gaussian Kuwahara (strength = 3) = 8328 / 10000 = 0.8328
Gaussian Kuwahara (strength = 5) = 7328 / 10000 = 0.7328
Gaussian Kuwahara (strength = 7) = 5236 / 10000 = 0.5236
Gaussian Kuwahara (strength = 9) = 3344 / 10000 = 0.3344
====== EPSILON: 0.17500000000000002 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 6207 / 10000 = 0.6207
Gaussian Kuwahara (strength = 1) = 7078 / 10000 = 0.7078
Gaussian Kuwahara (strength = 3) = 7808 / 10000 = 0.7808
Gaussian Kuwahara (strength = 5) = 6816 / 10000 = 0.6816
Gaussian Kuwahara (strength = 7) = 4868 / 10000 = 0.4868
Gaussian Kuwahara (strength = 9) = 3090 / 10000 = 0.309
====== EPSILON: 0.2 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 5008 / 10000 = 0.5008
Gaussian Kuwahara (strength = 1) = 6125 / 10000 = 0.6125
Gaussian Kuwahara (strength = 3) = 7179 / 10000 = 0.7179
Gaussian Kuwahara (strength = 5) = 6301 / 10000 = 0.6301
Gaussian Kuwahara (strength = 7) = 4513 / 10000 = 0.4513
Gaussian Kuwahara (strength = 9) = 2865 / 10000 = 0.2865
====== EPSILON: 0.225 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 3894 / 10000 = 0.3894
Gaussian Kuwahara (strength = 1) = 4979 / 10000 = 0.4979
Gaussian Kuwahara (strength = 3) = 6460 / 10000 = 0.646
Gaussian Kuwahara (strength = 5) = 5773 / 10000 = 0.5773
Gaussian Kuwahara (strength = 7) = 4242 / 10000 = 0.4242
Gaussian Kuwahara (strength = 9) = 2702 / 10000 = 0.2702
====== EPSILON: 0.25 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 2922 / 10000 = 0.2922
Gaussian Kuwahara (strength = 1) = 3927 / 10000 = 0.3927
Gaussian Kuwahara (strength = 3) = 5640 / 10000 = 0.564
Gaussian Kuwahara (strength = 5) = 5197 / 10000 = 0.5197
Gaussian Kuwahara (strength = 7) = 3859 / 10000 = 0.3859
Gaussian Kuwahara (strength = 9) = 2493 / 10000 = 0.2493
====== EPSILON: 0.275 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 2149 / 10000 = 0.2149
Gaussian Kuwahara (strength = 1) = 3023 / 10000 = 0.3023
Gaussian Kuwahara (strength = 3) = 4761 / 10000 = 0.4761
Gaussian Kuwahara (strength = 5) = 4594 / 10000 = 0.4594
Gaussian Kuwahara (strength = 7) = 3494 / 10000 = 0.3494
Gaussian Kuwahara (strength = 9) = 2354 / 10000 = 0.2354
====== EPSILON: 0.30000000000000004 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 1599 / 10000 = 0.1599
Gaussian Kuwahara (strength = 1) = 2289 / 10000 = 0.2289
Gaussian Kuwahara (strength = 3) = 3839 / 10000 = 0.3839
Gaussian Kuwahara (strength = 5) = 3981 / 10000 = 0.3981
Gaussian Kuwahara (strength = 7) = 3182 / 10000 = 0.3182
Gaussian Kuwahara (strength = 9) = 2232 / 10000 = 0.2232
## Mean Kuwahara with Varying Radius
### Raw Program Output
====== EPSILON: 0.0 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9920 / 10000 = 0.992
Mean Kuwahara (strength = 1) = 9880 / 10000 = 0.988
Mean Kuwahara (strength = 3) = 7536 / 10000 = 0.7536
Mean Kuwahara (strength = 5) = 3667 / 10000 = 0.3667
Mean Kuwahara (strength = 7) = 1763 / 10000 = 0.1763
Mean Kuwahara (strength = 9) = 1339 / 10000 = 0.1339
====== EPSILON: 0.025 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9796 / 10000 = 0.9796
Mean Kuwahara (strength = 1) = 9795 / 10000 = 0.9795
Mean Kuwahara (strength = 3) = 7359 / 10000 = 0.7359
Mean Kuwahara (strength = 5) = 3496 / 10000 = 0.3496
Mean Kuwahara (strength = 7) = 1710 / 10000 = 0.171
Mean Kuwahara (strength = 9) = 1318 / 10000 = 0.1318
====== EPSILON: 0.05 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9600 / 10000 = 0.96
Mean Kuwahara (strength = 1) = 9650 / 10000 = 0.965
Mean Kuwahara (strength = 3) = 7129 / 10000 = 0.7129
Mean Kuwahara (strength = 5) = 3295 / 10000 = 0.3295
Mean Kuwahara (strength = 7) = 1637 / 10000 = 0.1637
Mean Kuwahara (strength = 9) = 1286 / 10000 = 0.1286
====== EPSILON: 0.07500000000000001 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 9260 / 10000 = 0.926
Mean Kuwahara (strength = 1) = 9460 / 10000 = 0.946
Mean Kuwahara (strength = 3) = 6871 / 10000 = 0.6871
Mean Kuwahara (strength = 5) = 3119 / 10000 = 0.3119
Mean Kuwahara (strength = 7) = 1578 / 10000 = 0.1578
Mean Kuwahara (strength = 9) = 1244 / 10000 = 0.1244
====== EPSILON: 0.1 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 8753 / 10000 = 0.8753
Mean Kuwahara (strength = 1) = 9160 / 10000 = 0.916
Mean Kuwahara (strength = 3) = 6617 / 10000 = 0.6617
Mean Kuwahara (strength = 5) = 2841 / 10000 = 0.2841
Mean Kuwahara (strength = 7) = 1497 / 10000 = 0.1497
Mean Kuwahara (strength = 9) = 1228 / 10000 = 0.1228
====== EPSILON: 0.125 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 8104 / 10000 = 0.8104
Mean Kuwahara (strength = 1) = 8746 / 10000 = 0.8746
Mean Kuwahara (strength = 3) = 6317 / 10000 = 0.6317
Mean Kuwahara (strength = 5) = 2587 / 10000 = 0.2587
Mean Kuwahara (strength = 7) = 1422 / 10000 = 0.1422
Mean Kuwahara (strength = 9) = 1211 / 10000 = 0.1211
====== EPSILON: 0.15000000000000002 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 7229 / 10000 = 0.7229
Mean Kuwahara (strength = 1) = 8235 / 10000 = 0.8235
Mean Kuwahara (strength = 3) = 6019 / 10000 = 0.6019
Mean Kuwahara (strength = 5) = 2395 / 10000 = 0.2395
Mean Kuwahara (strength = 7) = 1360 / 10000 = 0.136
Mean Kuwahara (strength = 9) = 1193 / 10000 = 0.1193
====== EPSILON: 0.17500000000000002 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 6207 / 10000 = 0.6207
Mean Kuwahara (strength = 1) = 7499 / 10000 = 0.7499
Mean Kuwahara (strength = 3) = 5699 / 10000 = 0.5699
Mean Kuwahara (strength = 5) = 2253 / 10000 = 0.2253
Mean Kuwahara (strength = 7) = 1340 / 10000 = 0.134
Mean Kuwahara (strength = 9) = 1164 / 10000 = 0.1164
====== EPSILON: 0.2 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 5008 / 10000 = 0.5008
Mean Kuwahara (strength = 1) = 6650 / 10000 = 0.665
Mean Kuwahara (strength = 3) = 5420 / 10000 = 0.542
Mean Kuwahara (strength = 5) = 2168 / 10000 = 0.2168
Mean Kuwahara (strength = 7) = 1335 / 10000 = 0.1335
Mean Kuwahara (strength = 9) = 1138 / 10000 = 0.1138
====== EPSILON: 0.225 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 3894 / 10000 = 0.3894
Mean Kuwahara (strength = 1) = 5642 / 10000 = 0.5642
Mean Kuwahara (strength = 3) = 5087 / 10000 = 0.5087
Mean Kuwahara (strength = 5) = 2064 / 10000 = 0.2064
Mean Kuwahara (strength = 7) = 1328 / 10000 = 0.1328
Mean Kuwahara (strength = 9) = 1129 / 10000 = 0.1129
====== EPSILON: 0.25 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 2922 / 10000 = 0.2922
Mean Kuwahara (strength = 1) = 4739 / 10000 = 0.4739
Mean Kuwahara (strength = 3) = 4773 / 10000 = 0.4773
Mean Kuwahara (strength = 5) = 1993 / 10000 = 0.1993
Mean Kuwahara (strength = 7) = 1306 / 10000 = 0.1306
Mean Kuwahara (strength = 9) = 1145 / 10000 = 0.1145
====== EPSILON: 0.275 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 2149 / 10000 = 0.2149
Mean Kuwahara (strength = 1) = 3638 / 10000 = 0.3638
Mean Kuwahara (strength = 3) = 4370 / 10000 = 0.437
Mean Kuwahara (strength = 5) = 1921 / 10000 = 0.1921
Mean Kuwahara (strength = 7) = 1309 / 10000 = 0.1309
Mean Kuwahara (strength = 9) = 1159 / 10000 = 0.1159
====== EPSILON: 0.30000000000000004 ======
Clean (No Filter) Accuracy = 9920 / 10000 = 0.992
Unfiltered Accuracy = 1599 / 10000 = 0.1599
Mean Kuwahara (strength = 1) = 2659 / 10000 = 0.2659
Mean Kuwahara (strength = 3) = 3912 / 10000 = 0.3912
Mean Kuwahara (strength = 5) = 1854 / 10000 = 0.1854
Mean Kuwahara (strength = 7) = 1307 / 10000 = 0.1307
Mean Kuwahara (strength = 9) = 1166 / 10000 = 0.1166