open-mmlab / mmrazor

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

TypeError: 'Proxy' object cannot be interpreted as an integer #609

Open chunxt opened 1 year ago

chunxt commented 1 year ago

Checklist

Describe the question you meet

I have retest the detection demo retinaet_prue successfully, But when I try to test the anther mmdetection model 'TOOD', it failed. The information is "'Proxy' object cannot be interpreted as an integer". I have followed this issue "[Bug]torch.fx.proxy.TraceError: Proxy object cannot be iterated. #554", but it does not work.

The detail is below. File "tools/train.py", line 121, in main() File "tools/train.py", line 114, in main runner = Runner.from_cfg(cfg) File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/mmengine/runner/runner.py", line 465, in from_cfg runner = cls( File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/mmengine/runner/runner.py", line 413, in init self.model = self.build_model(model) File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/mmengine/runner/runner.py", line 839, in build_model model = MODELS.build(model) File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/mmengine/registry/registry.py", line 570, in build return self.build_func(cfg, args, kwargs, registry=self) File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg obj = obj_cls(args) # type: ignore File "/home/ry/DLtcx/exp_master/mmrazor/mmrazor/implementations/pruning/group_fisher/algorithm.py", line 57, in init self.mutator.prepare_from_supernet(self.architecture) File "/home/ry/DLtcx/exp_master/mmrazor/mmrazor/models/mutators/channel_mutator/channel_mutator.py", line 113, in prepare_from_supernet units = self._prepare_from_tracer(supernet, self.parse_cfg) File "/home/ry/DLtcx/exp_master/mmrazor/mmrazor/models/mutators/channel_mutator/channel_mutator.py", line 311, in _prepare_from_tracer unit_configs = tracer.analyze(model) File "/home/ry/DLtcx/exp_master/mmrazor/mmrazor/models/task_modules/tracer/channel_analyzer.py", line 107, in analyze fx_graph = self._fx_trace(model) File "/home/ry/DLtcx/exp_master/mmrazor/mmrazor/models/task_modules/tracer/channel_analyzer.py", line 136, in _fx_trace return self.tracer.trace(model, concrete_args=args) File "/home/ry/DLtcx/exp_master/mmrazor/mmrazor/models/task_modules/tracer/fx_tracer.py", line 310, in trace 'output', (self.create_arg(fn(args)), ), {}, File "/home/ry/anaconda3/envs/ry/lib/python3.8/site-packages/torch/fx/_symbolic_trace.py", line 652, in flatten_fn tree_out = root_fn(*tree_args) File "/home/ry/DLtcx/exp_master/mmdetection/mmdet/models/detectors/base.py", line 103, in forward return self._forward(inputs, data_samples) File "/home/ry/DLtcx/exp_master/mmdetection/mmdet/models/detectors/single_stage.py", line 133, in _forward results = self.bbox_head.forward(x) File "/home/ry/DLtcx/exp_master/mmdetection/mmdet/models/dense_heads/toodhead.py", line 252, in forward anchor = torch.cat([anchor for in range(b)]) TypeError: 'Proxy' object cannot be interpreted as an integer.

chunxt commented 1 year ago

I changed the 'b'(bactsize) to 4 in "toodhead.py", line 252, in forward anchor = torch.cat([anchor for in range(b)]) about the above issue. But another problem is occured. I could not find where set the bactsize in "channel_analyzer.py". So "template_output = model(**inputs)" is error, because "Forward failed in loss mode as The size of tensor a (1568) must match the size of tensor b (784) at non-singleton dimension 0".