open-mmlab / mmrazor

OpenMMLab Model Compression Toolbox and Benchmark.
https://mmrazor.readthedocs.io/en/latest/
Apache License 2.0
1.47k stars 227 forks source link

[Bug] when using get_channel_units.py with a resnet50 #464

Closed Jaykob closed 1 year ago

Jaykob commented 1 year ago

Hi! I'm currently trying to prune a resnet50 using the configs/pruning/mmpose/dcff/dcff_topdown_heatmap_resnet50_coco.py config and I get the following error, even after applying the fix mentioned in the following bug report, which it could be related to https://github.com/open-mmlab/mmrazor/issues/431 ?

Traceback (most recent call last):
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
    obj = obj_cls(**args)  # type: ignore
  File "/some_path/mmrazor/mmrazor/models/algorithms/pruning/dcff.py", line 62, in __init__
    super().__init__(architecture, mutator_cfg, data_preprocessor,
  File "/some_path/mmrazor/mmrazor/models/algorithms/pruning/ite_prune_algorithm.py", line 137, in __init__
    self.mutator.prepare_from_supernet(self.architecture)
  File "/some_path/mmrazor/mmrazor/models/mutators/channel_mutator/channel_mutator.py", line 105, in prepare_from_supernet
    units = self._prepare_from_tracer(supernet, self.parse_cfg)
  File "/some_path/mmrazor/mmrazor/models/mutators/channel_mutator/channel_mutator.py", line 301, in _prepare_from_tracer
    unit_configs = tracer.analyze(model)
  File "/some_path/mmrazor/mmrazor/models/task_modules/tracer/channel_analyzer.py", line 106, in analyze
    fx_graph = self._fx_trace(model)
  File "/some_path/mmrazor/mmrazor/models/task_modules/tracer/channel_analyzer.py", line 131, in _fx_trace
    args = self.demo_input.get_data(model)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/demo_inputs.py", line 29, in get_data
    return self._get_data(model, input_shape, training)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/default_demo_inputs.py", line 105, in _get_data
    return defaul_demo_inputs(model, input_shape, training, self.scope)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/default_demo_inputs.py", line 79, in defaul_demo_inputs
    return demo_input().get_data(model, input_shape, training)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/demo_inputs.py", line 29, in get_data
    return self._get_data(model, input_shape, training)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/demo_inputs.py", line 49, in _get_data
    data = self._get_mm_data(model, input_shape, training)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/demo_inputs.py", line 139, in _get_mm_data
    data = demo_mmpose_inputs(model, input_shape)
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/mmpose_demo_input.py", line 35, in demo_mmpose_inputs
    batch_data_samples = [
  File "/some_path/mmrazor/mmrazor/models/task_modules/demo_inputs/mmpose_demo_input.py", line 36, in <listcomp>
    inputs['data_sample'] for inputs in get_packed_inputs(
TypeError: string indices must be integers

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/train.py", line 121, in <module>
    main()
  File "tools/train.py", line 114, in main
    runner = Runner.from_cfg(cfg)
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/runner/runner.py", line 431, in from_cfg
    runner = cls(
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/runner/runner.py", line 398, in __init__
    self.model = self.build_model(model)
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/runner/runner.py", line 800, in build_model
    model = MODELS.build(model)
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/registry/registry.py", line 521, in build
    return self.build_func(cfg, *args, **kwargs, registry=self)
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 240, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/anaconda/envs/openmmlab/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 135, in build_from_cfg
    raise type(e)(
TypeError: class `DCFF` in mmrazor/models/algorithms/pruning/dcff.py: string indices must be integers
LKJacky commented 1 year ago

We are sorry. It's a bug, we will fix it as soon as possible. DCFF is developing. We suggest you use group fisher algorithm that is developed well including export (and deploy is incomming soon).