forked from Alibaba-MIIL/TResNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infer.py
43 lines (34 loc) · 1.33 KB
/
infer.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
import torch
from src.helper_functions.helper_functions import validate, create_dataloader
from src.models import create_model
import argparse
torch.backends.cudnn.benchmark = True
parser = argparse.ArgumentParser(description='PyTorch TResNet ImageNet Inference')
parser.add_argument('--val_dir')
parser.add_argument('--model_path')
parser.add_argument('--model_name', type=str, default='tresnet_m')
parser.add_argument('--num_classes', type=int, default=1000)
parser.add_argument('--input_size', type=int, default=224)
parser.add_argument('--val_zoom_factor', type=int, default=0.875)
parser.add_argument('--batch_size', type=int, default=48)
parser.add_argument('--num_workers', type=int, default=8)
def main():
# parsing args
args = parser.parse_args()
# setup model
print('creating model...')
model = create_model(args).cuda()
state = torch.load(args.model_path, map_location='cpu')['model']
model.load_state_dict(state, strict=True)
model.eval()
print('done\n')
# setup data loader
print('creating data loader...')
val_loader = create_dataloader(args)
print('done\n')
# actual validation process
print('doing validation...')
prec1_f, prec5_f = validate(model, val_loader)
print("final top-1 validation accuracy: {:.2f}".format(prec1_f.avg))
if __name__ == '__main__':
main()