-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
173 lines (146 loc) · 6.69 KB
/
run.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
import argparse
import os
from functools import partial
import ray
from ray import tune
from ood_eval import ood_eval
from utils.utils import is_debug_session
def cifar100_vs_cifar10():
config = {
"id_dataset": "cifar100",
"ood_datasets": ["cifar10"],
"model_name": "densenet100",
"train_restore_file": "densenet100_cifar100.pth",
"batch_size": 200,
"scoring_method": "energy",
"method": tune.grid_search(["ash_s@65", "ash_s@80", "ash_s@90", "ash_s@95", "ash_s@99",
"ash_b@65", "ash_b@80", "ash_b@90", "ash_b@95", "ash_b@99",
"ash_p@65", "ash_p@80", "ash_p@90", "ash_p@95", "ash_p@99", "energy"])
}
run(config)
def cifar10_vs_cifar100():
config = {
"id_dataset": "cifar10",
"ood_datasets": ["cifar100"],
"model_name": "densenet100",
"train_restore_file": "densenet100_cifar10.pth",
"batch_size": 200,
"scoring_method": "energy",
"method": tune.grid_search(["ash_s@65", "ash_s@80", "ash_s@90", "ash_s@95", "ash_s@99",
"ash_b@65", "ash_b@80", "ash_b@90", "ash_b@95", "ash_b@99",
"ash_p@65", "ash_p@80", "ash_p@90", "ash_p@95", "ash_p@99", "energy"])
}
run(config)
def vit():
config = {
"id_dataset": "imagenet",
"ood_datasets": ["inaturalist", "sun", "places", "textures"],
"model_name": "vit",
"train_restore_file": "",
"batch_size": 200,
"scoring_method": "energy",
"method": tune.grid_search(["energy", "ash_s@65", "ash_s@90", "ash_s@95", "ash_s@99", "ash_b@65", "ash_b@90", "ash_b@95", "ash_b@99"])
}
run(config)
def densenet_imagenet():
config = {
"id_dataset": "imagenet",
"ood_datasets": ["inaturalist", "sun", "places", "textures"],
"model_name": "densenet_imagenet",
"train_restore_file": "",
"batch_size": 200,
"scoring_method": "energy",
"method": tune.grid_search(["energy", "ash_s@65", "ash_s@90", "ash_s@95", "ash_s@99", "ash_b@65", "ash_b@90", "ash_b@95", "ash_b@99"])
}
run(config)
def convnext():
config = {
"id_dataset": "imagenet",
"ood_datasets": ["inaturalist", "sun", "places", "textures"],
"model_name": "convnext",
"train_restore_file": "",
"batch_size": 200,
"scoring_method": "energy",
"method": tune.grid_search(["energy", "ash_s@65", "ash_s@90", "ash_s@95", "ash_s@99", "ash_b@65", "ash_b@90", "ash_b@95", "ash_b@99"])
}
run(config)
def vgg():
config = {
"id_dataset": "imagenet",
"ood_datasets": ["inaturalist", "sun", "places", "textures"],
"model_name": "vgg16",
"train_restore_file": "vgg16-397923af.pth",
"batch_size": 200,
"scoring_method": "energy",
"method": tune.grid_search(["ash_s@65", "ash_s@95", "ash_b@65", "ash_b@90", "ash_b@95"])
}
run(config)
def imagenet():
config = {
"id_dataset": "imagenet",
"ood_datasets": ["inaturalist", "sun", "places", "textures"],
"model_name": "resnet50",
"train_restore_file": "resnet50-19c8e357.pth",
"batch_size": 200,
"scoring_method": tune.grid_search(["energy", "msp"]),
"method": tune.grid_search(["ash_s@65", "ash_s@70", "ash_s@75", "ash_s@80", "ash_s@85", "ash_s@90", "ash_s@95", "ash_s@99",
"ash_b@65", "ash_b@70", "ash_b@75", "ash_b@80", "ash_b@85", "ash_b@90", "ash_b@95", "ash_b@99",
"ash_p@65", "ash_p@70", "ash_p@75", "ash_p@80", "ash_p@85", "ash_p@90", "ash_p@95", "ash_p@99"])
}
run(config)
config = {
"id_dataset": "imagenet",
"ood_datasets": ["inaturalist", "sun", "places", "textures"],
"model_name": "mobilenetv2",
"train_restore_file": "mobilenet_v2-b0353104.pth",
"batch_size": 200,
"scoring_method": tune.grid_search(["energy", "msp"]),
"method": tune.grid_search(["ash_s@65", "ash_s@70", "ash_s@75", "ash_s@80", "ash_s@85", "ash_s@90", "ash_s@95", "ash_s@99",
"ash_b@65", "ash_b@70", "ash_b@75", "ash_b@80", "ash_b@85", "ash_b@90", "ash_b@95", "ash_b@99",
"ash_p@65", "ash_p@70", "ash_p@75", "ash_p@80", "ash_p@85", "ash_p@90", "ash_p@95", "ash_p@99"])
}
run(config)
def cifar():
config = {
"id_dataset": "cifar10",
"ood_datasets": ["svhn", "lsuncrop", "lsunresize", "isun", "textures", "places365"],
"model_name": "densenet100",
"train_restore_file": "densenet100_cifar10.pth",
"batch_size": 200,
"scoring_method": tune.grid_search(["energy", "msp"]),
# "method": tune.grid_search(["ash_s@65", "ash_s@70"])
"method": tune.grid_search(["ash_s@65", "ash_s@70", "ash_s@75", "ash_s@80", "ash_s@85", "ash_s@90", "ash_s@95", "ash_s@99",
"ash_b@65", "ash_b@70", "ash_b@75", "ash_b@80", "ash_b@85", "ash_b@90", "ash_b@95", "ash_b@99",
"ash_p@65", "ash_p@70", "ash_p@75", "ash_p@80", "ash_p@85", "ash_p@90", "ash_p@95", "ash_p@99"])
}
run(config)
config = {
"id_dataset": "cifar100",
"ood_datasets": ["svhn", "lsuncrop", "lsunresize", "isun", "textures", "places365"],
"model_name": "densenet100",
"train_restore_file": "densenet100_cifar100.pth",
"batch_size": 200,
"scoring_method": tune.grid_search(["energy", "msp"]),
"method": tune.grid_search(["ash_s@65", "ash_s@70", "ash_s@75", "ash_s@80", "ash_s@85", "ash_s@90", "ash_s@95", "ash_s@99",
"ash_b@65", "ash_b@70", "ash_b@75", "ash_b@80", "ash_b@85", "ash_b@90", "ash_b@95", "ash_b@99",
"ash_p@65", "ash_p@70", "ash_p@75", "ash_p@80", "ash_p@85", "ash_p@90", "ash_p@95", "ash_p@99"])
}
run(config)
def run(config):
gpus_per_trial = 1
analysis = tune.run(partial(ood_eval, use_gpu=True, use_tqdm=True),
config=config,
resources_per_trial={"cpu": 2, "gpu": gpus_per_trial},
log_to_file=True)
print(analysis)
def exec(args):
function_name = args.job
eval(function_name)()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--job", type=str, required=True, help="Specify job type [cifar / imagenet]")
parser.add_argument("--address", type=str, help="Ray address to use to connect to a cluster.")
args = parser.parse_args()
ray.init(address=args.address, local_mode=is_debug_session())
exec(args)