-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
49 lines (34 loc) · 1.42 KB
/
main.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 17 17:08:12 2022
@author: cyrilvallez
"""
# =============================================================================
# Main experiment file
# =============================================================================
import numpy as np
import hashing
from helpers import utils
# Force the use of a user input at run-time to specify the path
# so that we do not mistakenly reuse the path from previous experiments
save_folder = utils.parse_input()
path_database = 'Datasets/BSDS500/Experimental/'
path_experimental = 'Datasets/BSDS500/Experimental_attacks/'
path_control = 'Datasets/BSDS500/Control_attacks/'
algos = [
hashing.ClassicalAlgorithm('Phash', hash_size=8),
hashing.FeatureAlgorithm('ORB', n_features=30),
hashing.NeuralAlgorithm('SimCLR v1 ResNet50 2x', device='cuda',
distance='Jensen-Shannon')
]
thresholds = [
np.linspace(0, 0.4, 20),
np.linspace(0, 0.3, 20),
np.linspace(0.3, 0.8, 20),
]
positive_dataset = hashing.create_dataset(path_experimental, existing_attacks=True)
negative_dataset = hashing.create_dataset(path_control, existing_attacks=True)
digest = hashing.total_hashing(algos, thresholds, path_database, positive_dataset,
negative_dataset, general_batch_size=64)
utils.save_digest(digest, save_folder)