-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpatch_config.py
151 lines (109 loc) · 3.72 KB
/
patch_config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from torch import optim
class BaseConfig(object):
"""
Default parameters for all config files.
"""
def __init__(self):
"""
Set the defaults.
"""
self.img_dir = "../inria/INRIAPerson/Train/pos" # train images location
self.lab_dir = "../inria/INRIAPerson/Train/pos/inria_anno_darknet_format" # train labels location
self.cfgfile_yolov2 = "./cfg/yolo.cfg"
self.cfgfile_yolov3 = "./cfg/yolov3.cfg"
self.cfgfile_yolov4 = "./cfg/yolov4.cfg"
self.weightfile_yolov2 = "./weights/yolov2.weights"
self.weightfile_yolov3 = "./weights/yolov3.weights"
self.weightfile_yolov3pt_ultra = "./weights/yolov3_ultralytics.pt"
self.weightfile_yolov4 = "./weights/yolov4.weights"
#self.cfgfile_ssds = "C:/Users/Alessandro/PycharmProjects/YOLOv2_d2p_adv_COCO_thys2019/networks_cfgs/cfgs/ssd_lite_mobilenetv2_train_coco.yml"
self.ssdmbntv1_model_path = "./mbntv1_ssd_voc.pth"
self.ssdlitembntv2_model_path = "./mbnt2_ssd_lite_voc.pth"
self.ssdvgg_model_path = "./vgg16_ssd_voc.pth"
self.printfile = "./non_printability/30values.txt"
self.patch_size = 300
self.start_learning_rate = 0.03
self.patch_name = 'base'
self.scheduler_factory = lambda x: optim.lr_scheduler.ReduceLROnPlateau(x, 'min', patience=50)
# reduce learning rate when a metric has stopped learning (keras??)
# In min mode, lr will be reduced when the quantity monitored has stopped decreasing;
# in max mode it will be reduced when the quantity monitored has stopped increasing. Default: ‘min’.
self.max_tv = 0
self.batch_size = 8
self.loss_target = lambda obj, cls: obj*cls #for yolo only
class Experiment1(BaseConfig):
"""
Model that uses a maximum total variation, tv cannot go below this point.
"""
def __init__(self):
"""
Change stuff...
"""
super().__init__()
self.patch_name = 'Experiment1'
self.max_tv = 0.165
class Experiment2HighRes(Experiment1):
"""
Higher res
"""
def __init__(self):
"""
Change stuff...
"""
super().__init__()
self.max_tv = 0.165
self.patch_size = 400
self.patch_name = 'Exp2HighRes'
class Experiment3LowRes(Experiment1):
"""
Lower res
"""
def __init__(self):
"""
Change stuff...
"""
super().__init__()
self.max_tv = 0.165
self.patch_size = 100
self.patch_name = "Exp3LowRes"
class Experiment4ClassOnly(Experiment1):
"""
Only minimise class score.
"""
def __init__(self):
"""
Change stuff...
"""
super().__init__()
self.patch_name = 'Experiment4ClassOnly'
self.loss_target = lambda obj, cls: cls
class Experiment1Desktop(Experiment1):
"""
"""
def __init__(self):
"""
Change batch size.
"""
super().__init__()
self.batch_size = 8
self.patch_size = 400
class ReproducePaperObj(BaseConfig):
"""
Reproduce the results from the paper: Generate a patch that minimises object score.
"""
def __init__(self):
super().__init__()
self.batch_size = 8
self.patch_size = 300
self.patch_name = 'ObjectOnlyPaper'
self.max_tv = 0.165
self.loss_target = lambda obj, cls: obj #for yolo only
patch_configs = {
"base": BaseConfig,
"exp1": Experiment1,
"exp1_des": Experiment1Desktop,
"exp2_high_res": Experiment2HighRes,
"exp3_low_res": Experiment3LowRes,
"exp4_class_only": Experiment4ClassOnly,
"paper_obj": ReproducePaperObj
}