Files
openvino/model-optimizer/mo/utils/guess_framework.py
Michał Karzyński bd5b1bf99f Change the way Model Optimizer loads frontends (#7330)
* Adds two switches `use_new_frontend` and `use_legacy_frontend` to override defaults.
* Rename ONNX frontend from `onnx_experimental` to `onnx`
2021-09-30 12:17:36 +02:00

46 lines
1.7 KiB
Python

# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import re
from argparse import Namespace
from mo.utils.error import Error
from mo.utils.utils import refer_to_faq_msg
def deduce_framework_by_namespace(argv: Namespace):
if not argv.framework:
if getattr(argv, 'saved_model_dir', None) or getattr(argv, 'input_meta_graph', None):
argv.framework = 'tf'
elif getattr(argv, 'input_symbol', None) or getattr(argv, 'pretrained_model_name', None):
argv.framework = 'mxnet'
elif getattr(argv, 'input_proto', None):
argv.framework = 'caffe'
elif argv.input_model is None:
raise Error('Path to input model is required: use --input_model.')
else:
argv.framework = guess_framework_by_ext(argv.input_model)
if not argv.framework:
raise Error('Framework name can not be deduced from the given options: {}={}. Use --framework to choose '
'one of caffe, tf, mxnet, kaldi, onnx', '--input_model', argv.input_model, refer_to_faq_msg(15))
return map(lambda x: argv.framework == x, ['tf', 'caffe', 'mxnet', 'kaldi', 'onnx'])
def guess_framework_by_ext(input_model_path: str) -> int:
if re.match(r'^.*\.caffemodel$', input_model_path):
return 'caffe'
elif re.match(r'^.*\.pb$', input_model_path):
return 'tf'
elif re.match(r'^.*\.pbtxt$', input_model_path):
return 'tf'
elif re.match(r'^.*\.params$', input_model_path):
return 'mxnet'
elif re.match(r'^.*\.nnet$', input_model_path):
return 'kaldi'
elif re.match(r'^.*\.mdl', input_model_path):
return 'kaldi'
elif re.match(r'^.*\.onnx$', input_model_path):
return 'onnx'