Datasets:
Venkata Pydipalli
commited on
Commit
·
fb24ec6
1
Parent(s):
9404685
README fixes tags.
Browse files
README.md
CHANGED
@@ -96,13 +96,15 @@ These attacks require access to model gradients:
|
|
96 |
## Usage
|
97 |
|
98 |
```python
|
99 |
-
|
100 |
import torch
|
101 |
from torchvision import transforms
|
102 |
from PIL import Image
|
|
|
103 |
|
104 |
-
# Load the dataset
|
105 |
-
|
|
|
106 |
|
107 |
# Define transformation
|
108 |
transform = transforms.Compose([
|
@@ -110,20 +112,35 @@ transform = transforms.Compose([
|
|
110 |
transforms.ToTensor()
|
111 |
])
|
112 |
|
113 |
-
#
|
114 |
-
def
|
115 |
-
img = Image.open(
|
116 |
-
return
|
117 |
-
|
118 |
-
#
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
```
|
128 |
|
129 |
## **📊 Attack Success Rates**
|
|
|
96 |
## Usage
|
97 |
|
98 |
```python
|
99 |
+
import json
|
100 |
import torch
|
101 |
from torchvision import transforms
|
102 |
from PIL import Image
|
103 |
+
from pathlib import Path
|
104 |
|
105 |
+
# Load the dataset information
|
106 |
+
with open('organized_dataset/dataset.json', 'r') as f:
|
107 |
+
dataset_info = json.load(f)
|
108 |
|
109 |
# Define transformation
|
110 |
transform = transforms.Compose([
|
|
|
112 |
transforms.ToTensor()
|
113 |
])
|
114 |
|
115 |
+
# Function to load and process images
|
116 |
+
def load_image(image_path):
|
117 |
+
img = Image.open(image_path).convert("RGB")
|
118 |
+
return transform(img)
|
119 |
+
|
120 |
+
# Example: Loading a set of related images (original, adversarial, and perturbation)
|
121 |
+
for entry in dataset_info:
|
122 |
+
# Load adversarial image
|
123 |
+
adv_path = Path('organized_dataset') / entry['adversarial']
|
124 |
+
adv_image = load_image(adv_path)
|
125 |
+
|
126 |
+
# Load original image
|
127 |
+
orig_path = Path('organized_dataset') / entry['original'][0]
|
128 |
+
orig_image = load_image(orig_path)
|
129 |
+
|
130 |
+
# Load perturbation if available
|
131 |
+
if entry['perturbation']:
|
132 |
+
pert_path = Path('organized_dataset') / entry['perturbation']
|
133 |
+
pert_image = load_image(pert_path)
|
134 |
+
|
135 |
+
# Access metadata
|
136 |
+
attack_type = entry['attack']
|
137 |
+
label = entry['label']
|
138 |
+
prediction = entry['prediction']
|
139 |
+
|
140 |
+
print(f"Attack: {attack_type}")
|
141 |
+
print(f"True Label: {label}")
|
142 |
+
print(f"Model Prediction: {prediction}")
|
143 |
+
print(f"Image shapes: {adv_image.shape}") # Should be (3, 224, 224)
|
144 |
```
|
145 |
|
146 |
## **📊 Attack Success Rates**
|