forked from foamliu/MobileFaceNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.py
28 lines (24 loc) · 938 Bytes
/
export.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
import time
from mobilefacenet import MobileFaceNet
import torch
if __name__ == '__main__':
checkpoint = 'BEST_checkpoint.tar'
print('loading {}...'.format(checkpoint))
start = time.time()
checkpoint = torch.load(checkpoint)
print('elapsed {} sec'.format(time.time() - start))
model = checkpoint['model'].module
print(type(model))
filename = 'mobilefacenet.pt'
print('saving {}...'.format(filename))
start = time.time()
torch.save(model.state_dict(), filename)
print('elapsed {} sec'.format(time.time() - start))
print('loading {}...'.format(filename))
start = time.time()
model = MobileFaceNet()
model.load_state_dict(torch.load(filename))
print('elapsed {} sec'.format(time.time() - start))
scripted_model_file = 'mobilefacenet_scripted.pt'
print('saving {}...'.format(scripted_model_file))
torch.jit.save(torch.jit.script(model), scripted_model_file)