Skip to content

Commit 40e53df

Browse files
authored
[Fix] support inferencer in pip install (#1875)
* [Enhance] support image restoration inferencer * [Enhance] support image restoration inferencer * update demo * update demo * update demo * update demo * [Fix] support inferencer in pip install
1 parent f602ed4 commit 40e53df

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

mmagic/apis/mmagic_inferencer.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
2-
import os
32
import os.path as osp
43
import warnings
54
from typing import Dict, List, Optional, Union
@@ -155,8 +154,13 @@ def _get_inferencer_kwargs(self, model_name: Optional[str],
155154
setting_to_use = model_setting
156155
config_dir = cfgs['settings'][setting_to_use]['Config']
157156
config_dir = config_dir[config_dir.find('configs'):]
158-
kwargs['config'] = os.path.join(
159-
osp.dirname(__file__), '..', '..', config_dir)
157+
if osp.exists(
158+
osp.join(osp.dirname(__file__), '..', '..', config_dir)):
159+
kwargs['config'] = osp.join(
160+
osp.dirname(__file__), '..', '..', config_dir)
161+
else:
162+
kwargs['config'] = osp.join(
163+
osp.dirname(__file__), '..', '.mim', config_dir)
160164
if 'Weights' in cfgs['settings'][setting_to_use].keys():
161165
kwargs['ckpt'] = cfgs['settings'][setting_to_use]['Weights']
162166

@@ -233,9 +237,13 @@ def get_model_config(self, model_name: str) -> Dict:
233237
@staticmethod
234238
def init_inference_supported_models_cfg() -> None:
235239
if not MMagicInferencer.inference_supported_models_cfg_inited:
236-
all_cfgs_dir = osp.join(
237-
osp.dirname(__file__), '..', '..', 'configs')
238-
240+
if osp.exists(
241+
osp.join(osp.dirname(__file__), '..', '..', 'configs')):
242+
all_cfgs_dir = osp.join(
243+
osp.dirname(__file__), '..', '..', 'configs')
244+
else:
245+
all_cfgs_dir = osp.join(
246+
osp.dirname(__file__), '..', '.mim', 'configs')
239247
for model_name in MMagicInferencer.inference_supported_models:
240248
meta_file_dir = osp.join(all_cfgs_dir, model_name,
241249
'metafile.yml')

0 commit comments

Comments
 (0)