mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2025-06-26 21:24:27 +00:00
[Fix] Consider nested cases when converting AttrDict
to built-in dicts (#15663)
* Fix dict conversion * By default enable mkldnn * By default do not save to file
This commit is contained in:
parent
0d67020a3f
commit
766c4ad2d3
@ -77,7 +77,6 @@ def prepare_common_init_args(model_name, common_args):
|
||||
elif device_type == "cpu":
|
||||
enable_mkldnn = common_args["enable_mkldnn"]
|
||||
if enable_mkldnn:
|
||||
pp_option.run_mode = "mkldnn"
|
||||
pp_option.mkldnn_cache_capacity = common_args["mkldnn_cache_capacity"]
|
||||
else:
|
||||
pp_option.run_mode = "paddle"
|
||||
|
@ -39,12 +39,15 @@ def _merge_dicts(d1, d2):
|
||||
return res
|
||||
|
||||
|
||||
def _to_plain_dict(d):
|
||||
res = d.copy()
|
||||
for k, v in d.items():
|
||||
if isinstance(v, AttrDict):
|
||||
res[k] = _to_plain_dict(v)
|
||||
return res
|
||||
def _to_builtin(obj):
|
||||
if isinstance(obj, AttrDict):
|
||||
return {k: _to_builtin(v) for k, v in obj.items()}
|
||||
elif isinstance(obj, dict):
|
||||
return {k: _to_builtin(v) for k, v in obj.items()}
|
||||
elif isinstance(obj, list):
|
||||
return [_to_builtin(item) for item in obj]
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
class PaddleXPipelineWrapper(metaclass=abc.ABCMeta):
|
||||
@ -69,7 +72,7 @@ class PaddleXPipelineWrapper(metaclass=abc.ABCMeta):
|
||||
|
||||
def export_paddlex_config_to_yaml(self, yaml_path):
|
||||
with open(yaml_path, "w", encoding="utf-8") as f:
|
||||
config = _to_plain_dict(self._merged_paddlex_config)
|
||||
config = _to_builtin(self._merged_paddlex_config)
|
||||
yaml.safe_dump(config, f)
|
||||
|
||||
@classmethod
|
||||
|
@ -41,7 +41,6 @@ def add_simple_inference_args(subparser, *, input_help=None):
|
||||
subparser.add_argument(
|
||||
"--save_path",
|
||||
type=str,
|
||||
default="output",
|
||||
help="Path to the output directory.",
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user