-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_model.py
57 lines (43 loc) · 1.37 KB
/
export_model.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
import os
import argparse
import paddle
from network import get_networks
from utils.utils import get_config, load_pretrained_model
def parse_args():
parser = argparse.ArgumentParser(description='Model export.')
parser.add_argument(
'--config',
type=str,
default='configs/config.yaml',
help="training configuration")
parser.add_argument(
'--save_dir',
dest='save_dir',
help='The directory for saving the exported model',
type=str,
default='./output')
parser.add_argument(
'--model_path',
dest='model_path',
help='The path of model for export',
type=str,
default=None)
return parser.parse_args()
def main(args, config):
_, net = get_networks(config)
if args.model_path is not None:
load_pretrained_model(net, args.model_path)
print('Loaded trained params of model successfully.')
shape = [-1, 3, 128, 128]
new_net = net
new_net.eval()
new_net = paddle.jit.to_static(
new_net,
input_spec=[paddle.static.InputSpec(shape=shape, dtype='float32'), 11, True])
save_path = os.path.join(args.save_dir, 'model')
paddle.jit.save(new_net, save_path)
print(f'Model is saved in {args.save_dir}.')
if __name__ == '__main__':
args = parse_args()
config = get_config(args.config)
main(args, config)