Skip to content

Commit

Permalink
Fix merge bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
SemyonBevzuk committed Mar 9, 2022
1 parent 0467adb commit 2acb2a0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/en/tutorials/how_to_convert_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ python ./tools/deploy.py \
- `img` : The path of image file that used to convert model.
- `--test-img` : The path of image file that used to test model. If not specified, it will be set to `None`.
- `--work-dir` : The path of work directory that used to save logs and models.
- `--calib-dataset-cfg` : Only valid in int8 mode. Config used for calibration. If not specified, it will be set to `None` and use "val" dataset in model config for calibration.
- `--calib-dataset-cfg` : Config used for calibration. If not specified, it will be set to `None`.
- `--device` : The device used for conversion. If not specified, it will be set to `cpu`.
- `--log-level` : To set log level which in `'CRITICAL', 'FATAL', 'ERROR', 'WARN', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'`. If not specified, it will be set to `INFO`.
- `--show` : Whether to show detection outputs.
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/tutorials/how_to_convert_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ python ./tools/deploy.py \
- `img` : 用于模型转换时使用的图像文件路径。
- `--test-img` : 用于测试模型的图像文件路径。默认设置成`None`
- `--work-dir` : 工作目录,用来保存日志和模型文件。
- `--calib-dataset-cfg` : 此参数只有int8模式下生效,用于校准数据集配置文件。若在int8模式下未传入参数,则会自动使用模型配置文件中的'val'数据集进行校准
- `--calib-dataset-cfg` : 用于校准的配置文件。默认是`None`
- `--device` : 用于模型转换的设备。 默认是`cpu`
- `--log-level` : 设置日记的等级,选项包括`'CRITICAL', 'FATAL', 'ERROR', 'WARN', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'`。 默认是`INFO`
- `--show` : 是否显示检测的结果。
Expand Down
40 changes: 13 additions & 27 deletions mmdeploy/codebase/mmcls/deploy/classification_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import mmcv
import numpy as np
import torch
from mmcls.datasets import DATASETS
from mmcls.models.classifiers.base import BaseClassifier
from mmcv.utils import Registry

from mmdeploy.codebase.base import BaseBackendModel
from mmdeploy.utils import (Backend, get_backend, get_codebase_config,
get_root_logger, load_config)
load_config)


def __build_backend_model(cls_name: str, registry: Registry, *args, **kwargs):
Expand Down Expand Up @@ -150,35 +151,20 @@ def get_classes_from_config(model_cfg: Union[str, mmcv.Config]):
Returns:
list[str]: A list of string specifying names of different class.
"""
from mmcls.datasets import DATASETS

module_dict = DATASETS.module_dict
model_cfg = load_config(model_cfg)[0]
module_dict = DATASETS.module_dict
data_cfg = model_cfg.data

def _get_class_names(dataset_type: str):
dataset = data_cfg.get(dataset_type, None)
if (not dataset) or (dataset.type not in module_dict):
return None

module = module_dict[dataset.type]
if module.CLASSES is not None:
return module.CLASSES
return module.get_classes(dataset.get('classes', None))

class_names = None
for dataset_type in ['val', 'test', 'train']:
class_names = _get_class_names(dataset_type)
if class_names is not None:
break

if class_names is None:
logger = get_root_logger()
logger.warning(f'Use generated class names, because \
it failed to parse CLASSES from config: {data_cfg}')
num_classes = model_cfg.model.head.num_classes
class_names = [str(i) for i in range(num_classes)]
return class_names
if 'train' in data_cfg:
module = module_dict[data_cfg.train.type]
elif 'val' in data_cfg:
module = module_dict[data_cfg.val.type]
elif 'test' in data_cfg:
module = module_dict[data_cfg.test.type]
else:
raise RuntimeError(f'No dataset config found in: {model_cfg}')

return module.CLASSES


def build_classification_model(model_files: Sequence[str],
Expand Down
2 changes: 1 addition & 1 deletion mmdeploy/codebase/mmseg/deploy/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def process_model_config(model_cfg: mmcv.Config,
# for static exporting
if input_shape is not None:
cfg.data.test.pipeline[1]['img_scale'] = tuple(input_shape)
cfg.data.test.pipeline[1]['transforms'][0]['keep_ratio'] = False
cfg.data.test.pipeline[1]['transforms'][0]['keep_ratio'] = False
cfg.data.test.pipeline = [LoadImage()] + cfg.data.test.pipeline[1:]

return cfg
Expand Down
3 changes: 1 addition & 2 deletions tools/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def parse_args():
parser.add_argument('--work-dir', help='the dir to save logs and models')
parser.add_argument(
'--calib-dataset-cfg',
help='dataset config path used to calibrate in int8 mode. If not \
specified,it will use "val" dataset in model config instead.',
help='dataset config path used to calibrate.',
default=None)
parser.add_argument(
'--device', help='device used for conversion', default='cpu')
Expand Down

0 comments on commit 2acb2a0

Please sign in to comment.