-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Additional arguments support for OpenVINO Model Optimiz…
…er (#178) * Add mo args. * [Docs]: update docs and argument descriptions (#196) * bump version to v0.4.0 * update docs and argument descriptions * revert version change * fix unnecessary change of config for dynamic exportation (#199) * fix mmcls get classes (#215) * fix mmcls get classes * resolve comment * resolve comment * Add ModelOptimizerOptions. * Fix merge bugs. * Update mmpose.md (#224) * [Dostring]add example in apis docstring (#214) * add example in apis docstring * add backend example in docstring * rm blank line * Fixed get_mo_options_from_cfg args * fix l2norm test Co-authored-by: RunningLeon <mnsheng@yeah.net> Co-authored-by: Haofan Wang <frankmiracle@outlook.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: grimoire <yaoqian@sensetime.com>
- Loading branch information
Showing
9 changed files
with
136 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from typing import Dict, List, Optional, Union | ||
|
||
|
||
class ModelOptimizerOptions: | ||
"""A class to make it easier to support additional arguments for the Model | ||
Optimizer that can be passed through the deployment configuration. | ||
Example: | ||
>>> deploy_cfg = load_config(deploy_cfg_path) | ||
>>> mo_options = deploy_cfg.get('mo_options', None) | ||
>>> mo_options = ModelOptimizerOptions(mo_options) | ||
>>> mo_args = mo_options.get_options() | ||
""" | ||
|
||
def __init__(self, | ||
mo_options: Optional[Dict[str, Union[Dict, List]]] = None): | ||
self.args = '' | ||
self.flags = '' | ||
if mo_options is not None: | ||
self.args = self.__parse_args(mo_options) | ||
self.flags = self.__parse_flags(mo_options) | ||
|
||
def __parse_args(self, mo_options: Dict[str, Union[Dict, List]]) -> str: | ||
"""Parses a dictionary with arguments into a string.""" | ||
mo_args_str = '' | ||
if 'args' in mo_options: | ||
for key, value in mo_options['args'].items(): | ||
value_str = f'"{value}"' if isinstance(value, list) else value | ||
mo_args_str += f'{key}={value_str} ' | ||
return mo_args_str | ||
|
||
def __parse_flags(self, mo_options: Dict[str, Union[Dict, List]]) -> str: | ||
"""Parses a list with flags into a string.""" | ||
mo_flags_str = '' | ||
if 'flags' in mo_options: | ||
mo_flags_str += ' '.join(mo_options['flags']) | ||
return mo_flags_str | ||
|
||
def get_options(self) -> str: | ||
"""Returns a string with additional arguments for the Model Optimizer. | ||
If there are no additional arguments, it will return an empty string. | ||
""" | ||
return self.args + self.flags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters