-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.py
More file actions
49 lines (37 loc) · 1.56 KB
/
convert.py
File metadata and controls
49 lines (37 loc) · 1.56 KB
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
import os
import argparse
from converters.master import MasterConverter
def get_args():
args = argparse.ArgumentParser()
args.add_argument('-m', '--model', type=str, required=True, \
help='Path to keras model (.h5)')
args.add_argument('--to-tflite', default=False, action='store_true')
args.add_argument('--to-savedmodel', default=False, action='store_true')
args.add_argument('--to-coreml', default=False, action='store_true')
args.add_argument('--to-tftrt', default=False, action='store_true')
args.add_argument('--all', default=False, action='store_true')
args.add_argument('--fp16', default=False, action='store_true')
args = args.parse_args()
return args
def ensure_args(args):
args_dict = vars(args)
# check if model path valid
model_path = args_dict.get('model')
if not model_path.endswith('.h5'):
raise ValueError('Unfortunately we only support conversion from keras model for now, so only .h5 file will be accepted')
if not os.path.exists(model_path):
raise FileNotFoundError(f'{model_path} not found on your system!')
# check if at least one model selected
passed = False
for key in args_dict.keys():
if key != 'model':
passed = passed or args_dict.get(key)
if passed:
break
if not passed:
raise ValueError(f'Choose at least one target model type!')
if __name__ == '__main__':
args = get_args()
ensure_args(args)
master_converter = MasterConverter(args)
master_converter.process()