diff --git a/docs/en/tutorials/how_to_convert_model.md b/docs/en/tutorials/how_to_convert_model.md index b20257cfc9..c84d24dd2d 100644 --- a/docs/en/tutorials/how_to_convert_model.md +++ b/docs/en/tutorials/how_to_convert_model.md @@ -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. diff --git a/docs/zh_cn/tutorials/how_to_convert_model.md b/docs/zh_cn/tutorials/how_to_convert_model.md index 0a1b1a9f52..65925c22d5 100644 --- a/docs/zh_cn/tutorials/how_to_convert_model.md +++ b/docs/zh_cn/tutorials/how_to_convert_model.md @@ -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` : 是否显示检测的结果。 diff --git a/mmdeploy/codebase/mmcls/deploy/classification_model.py b/mmdeploy/codebase/mmcls/deploy/classification_model.py index bf6dcbca2a..263d097ecd 100644 --- a/mmdeploy/codebase/mmcls/deploy/classification_model.py +++ b/mmdeploy/codebase/mmcls/deploy/classification_model.py @@ -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): @@ -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], diff --git a/mmdeploy/codebase/mmseg/deploy/segmentation.py b/mmdeploy/codebase/mmseg/deploy/segmentation.py index a3f1728ae2..209723cf6f 100644 --- a/mmdeploy/codebase/mmseg/deploy/segmentation.py +++ b/mmdeploy/codebase/mmseg/deploy/segmentation.py @@ -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 diff --git a/tools/deploy.py b/tools/deploy.py index f18c1d7484..63100c757e 100644 --- a/tools/deploy.py +++ b/tools/deploy.py @@ -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')