-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
70 lines (58 loc) · 2.2 KB
/
test.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
import os
import hydra
import torch
import utils.setup as setup
def _main(args):
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
global __file__
__file__ = hydra.utils.to_absolute_path(__file__)
dirname = os.path.dirname(__file__)
args.model_dir = os.path.join(dirname, str(args.model_dir))
if not os.path.exists(args.model_dir):
#try to create the directory
try:
os.makedirs(args.model_dir)
except:
raise Exception(f"Model directory {args.model_dir} does not exist. I did try to create it but failed. Please create it manually or check that the path is correct.")
args.exp.model_dir=args.model_dir
diff_params=setup.setup_diff_parameters(args)
network=setup.setup_network(args, device)
try:
test_set=setup.setup_dataset_test(args)
except:
test_set=None
tester=setup.setup_tester(args, network=network, diff_params=diff_params, device=device) #this will be used for making demos during training
# Print options.
print()
print('Training options:')
print()
print(f'Output directory: {args.model_dir}')
print(f'Network architecture: {args.network.callable}')
print(f'Diffusion parameterization: {args.diff_params.callable}')
print(f'Tester: {args.tester.callable}')
print(f'Experiment: {args.exp.exp_name}')
print()
if args.tester.checkpoint != 'None':
ckpt_path= args.tester.checkpoint
print("Loading checkpoint:",ckpt_path)
try:
tester.load_checkpoint(ckpt_path)
except:
#maybe it is a relative path
#find my path
path=os.path.dirname(__file__)
print(path)
tester.load_checkpoint(os.path.join(path,ckpt_path))
tester.setup_sampler()
else:
print("trying to load latest checkpoint")
tester.load_latest_checkpoint()
tester.test()
@hydra.main(config_path="conf", config_name="conf")
def main(args):
#set device to gpu 2
torch.cuda.set_device(2)
_main(args)
if __name__ == "__main__":
main()
#----------------------------------------------------------------------------