-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval_cd.py
61 lines (44 loc) · 2.01 KB
/
eval_cd.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
from argparse import ArgumentParser
import torch
import sys
sys.path.append('/home/amarachi/CheXRelFormer/')
from models.evaluator import *
print(torch.cuda.is_available())
"""
evaluate the model
"""
def main():
# ------------
# args
# ------------
parser = ArgumentParser()
parser.add_argument('--gpu_ids', type=str, default='0', help='gpu ids: e.g. 0 0,1,2, 0,2. use -1 for CPU')
parser.add_argument('--project_name', default='test', type=str)
parser.add_argument('--print_models', default=False, type=bool, help='print models')
parser.add_argument('--checkpoints_root', default='checkpoints', type=str)
# data
parser.add_argument('--num_workers', default=8, type=int)
parser.add_argument('--dataset', default='CDDataset', type=str)
parser.add_argument('--data_name', default='CXRData', type=str)
parser.add_argument('--batch_size', default=1, type=int)
parser.add_argument('--split', default="test", type=str)
parser.add_argument('--img_size', default=256, type=int)
# model
parser.add_argument('--n_class', default=3, type=int)
parser.add_argument('--embed_dim', default=256, type=int)
parser.add_argument('--net_G', default='base_transformer_pos_s4_dd8_dedim8', type=str,
help='base_resnet18 | base_transformer_pos_s4_dd8 | base_transformer_pos_s4_dd8_dedim8|')
parser.add_argument('--checkpoint_name', default='best_ckpt.pt', type=str)
args = parser.parse_args()
utils.get_device(args)
print(args.gpu_ids)
# checkpoints dir
args.checkpoint_dir = os.path.join(args.checkpoints_root, args.project_name)
os.makedirs(args.checkpoint_dir, exist_ok=True)
dataloader = utils.get_loader(args.data_name, img_size=args.img_size,
batch_size=args.batch_size, is_train=False,
split=args.split)
model = CDEvaluator(args=args, dataloader=dataloader)
model.eval_models(checkpoint_name=args.checkpoint_name)
if __name__ == '__main__':
main()