-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_attacks.py
51 lines (35 loc) · 1.48 KB
/
create_attacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 17 09:28:50 2022
@author: cyrilvallez
"""
# =============================================================================
# Performs the attacks in both groups (thus after having splitted the data)
# =============================================================================
import os
import generator
import random
# Set the seed
random.seed(254)
params = generator.ATTACK_PARAMETERS
# Number of images on which to perform the attacks in both groups
N = 100
dataset = 'BSDS500'
path1 = f'Datasets/{dataset}/Experimental/'
path2 = f'Datasets/{dataset}/Control/'
destination1 = f'Datasets/{dataset}/Experimental_attacks/'
destination2 = f'Datasets/{dataset}/Control_attacks/'
names_experimental = os.listdir(path1)
names_control = os.listdir(path2)
random.shuffle(names_experimental)
random.shuffle(names_control)
images_experimental = [path1 + name for name in names_experimental[0:N]]
images_control = [path2 + name for name in names_control[0:N]]
save_experimental = [destination1 + name.split('.')[0] for name \
in names_experimental[0:N]]
save_control = [destination2 + name.split('.')[0] for name in names_control[0:N]]
generator.perform_all_and_save_list(images_experimental, save_name_list=save_experimental,
extension='PNG', **params)
generator.perform_all_and_save_list(images_control, save_name_list=save_control,
extension='PNG', **params)