forked from samet-akcay/skip-ganomaly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
48 lines (41 loc) · 1.11 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
"""
TRAIN SKIP/GANOMALY
. Example: Run the following command from the terminal.
run train.py \
--dataset cifar10 \
--abnormal_class airplane \
--display \
"""
##
# LIBRARIES
import time
from options import Options
from lib.data.dataloader import load_data
from lib.models import load_model
import torch
import numpy as np
from lib.models.skipganomaly import seed
##
def main():
""" Training
"""
opt = Options().parse()
opt.print_freq = opt.batchsize
seed(opt.manualseed)
print("Seed:", str(torch.seed()))
if opt.phase == "inference":
opt.batchsize=1
data = load_data(opt)
model = load_model(opt, data)
if opt.phase == "inference":
model.inference()
else:
if opt.path_to_weights:
model.test()
else:
train_start = time.time()
model.train()
train_time = time.time() - train_start
print (f'Train time: {train_time} secs')
if __name__ == '__main__':
main()