-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'dict' object has no attribute 'bboxes' #622
Comments
We are sorry for your inconvenience. We have improved the ChannelAnayler to adaptive yolov8. You can directly cherry-pick this pr or wait util it is merged. |
Thank you very much for your previous response, and I have successfully run the train.py. And may I ask how to export the pruned compact model after finishing the pruning training? |
DCFF is developing, so there is no existing export method. We suggest you use group fisher algorithm that is developed well including export (and deploy is incomming soon). |
Thanks for your reply, I'll try it out. |
When I try to use group fisher, it cames: Traceback (most recent call last):
File "tools/train.py", line 121, in <module>
main()
File "tools/train.py", line 117, in main
runner.train()
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1673, in train
self.call_hook('before_run')
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1748, in call_hook
getattr(hook, fn_name)(self, **kwargs)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/implementations/pruning/group_fisher/hook.py", line 128, in before_run
original_resource = self._evaluate(model)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/implementations/pruning/group_fisher/hook.py", line 170, in _evaluate
res = self.estimator.estimate(model)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/models/task_modules/estimators/resource_estimator.py", line 136, in estimate
flops, params = get_model_flops_params(model, **flops_params_cfg)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/models/task_modules/estimators/counters/flops_params_counter.py", line 98, in get_model_flops_params
_ = flops_params_model(batch)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1148, in _call_impl
result = forward_call(*input, **kwargs)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/models/algorithms/base.py", line 144, in forward
return self._forward(inputs, data_samples)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/models/algorithms/base.py", line 165, in _forward
return self.architecture(inputs, data_samples, mode='tensor')
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmdet/models/detectors/base.py", line 96, in forward
return self._forward(inputs, data_samples)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmdet/models/detectors/single_stage.py", line 132, in _forward
x = self.extract_feat(batch_inputs)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmdet/models/detectors/single_stage.py", line 146, in extract_feat
x = self.backbone(batch_inputs)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmyolo/mmyolo/models/backbones/base_backbone.py", line 221, in forward
x = layer(x)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/container.py", line 139, in forward
input = module(input)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/mmcv/cnn/bricks/conv_module.py", line 207, in forward
x = self.conv(x)
File "/home/keli/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1151, in _call_impl
hook_result = hook(self, input, result)
File "/home/keli/Nuonepeaceyy/MMLAB/plus/mmrazor/mmrazor/models/task_modules/estimators/counters/op_counters/conv_layer_counter.py", line 82, in add_count_hook
if hasattr(mutable_channel[0], 'activated_tensor_channels'):
IndexError: list index out of range and here is my config file: #############################################################################
"""You have to fill these args.
_base_ (str): The path to your pretrained model checkpoint.
pretrained_path (str): The path to your pretrained model checkpoint.
interval (int): Interval between pruning two channels. You should ensure you
can reach your target pruning ratio when the training ends.
normalization_type (str): GroupFisher uses two methods to normlized the channel
importance, including ['flops','act']. The former uses flops, while the
latter uses the memory occupation of activation feature maps.
lr_ratio (float): Ratio to decrease lr rate. As pruning progress is unstable,
you need to decrease the original lr rate until the pruning training work
steadly without getting nan.
target_flop_ratio (float): The target flop ratio to prune your model.
input_shape (Tuple): input shape to measure the flops.
"""
_base_ = 'mmyolo::yolov8/yolov8_s_syncbn_fast_8xb16-500e_coco.py'
pretrained_path = '../mmyolo/checkpoints/yolov8_s_mask-refine_syncbn_fast_8xb16-500e_coco_20230216_095938-ce3c1b3f.pth'
interval = 10
normalization_type = 'act'
lr_ratio = 0.1 / 4
target_flop_ratio = 0.5
input_shape = (1, 3, 640, 640)
##############################################################################
architecture = _base_.model
if hasattr(_base_, 'data_preprocessor'):
architecture.update({'data_preprocessor': _base_.data_preprocessor})
data_preprocessor = None
architecture.init_cfg = dict(type='Pretrained', checkpoint=pretrained_path)
architecture['_scope_'] = _base_.default_scope
model = dict(
_delete_=True,
_scope_='mmrazor',
type='GroupFisherAlgorithm',
architecture=architecture,
interval=interval,
mutator=dict(
type='GroupFisherChannelMutator',
parse_cfg=dict(type='ChannelAnalyzer', tracer_type='FxTracer'),
channel_unit_cfg=dict(
type='GroupFisherChannelUnit',
default_args=dict(normalization_type=normalization_type, ),
),
),
)
model_wrapper_cfg = dict(
type='mmrazor.GroupFisherDDP',
broadcast_buffers=False,
)
optim_wrapper = dict(
optimizer=dict(lr=_base_.optim_wrapper.optimizer.lr * lr_ratio))
custom_hooks = getattr(_base_, 'custom_hooks', []) + [
dict(type='mmrazor.PruningStructureHook'),
dict(
type='mmrazor.ResourceInfoHook',
interval=interval,
demo_input=dict(
type='mmrazor.DefaultDemoInput',
input_shape=input_shape,
),
save_ckpt_thr=[target_flop_ratio],
),
] |
@nuonepeaceyy We have fix the bug, please pull the latest code from dev-1.x branch of mmrazor. |
Prerequisite
💬 Describe the reimplementation questions
When I try to use DCFF in mmrazor to prune the yolov8 model, I first try to get the target_pruning_ratio by
python tools/pruning/get_channel_units.py configs/pruning/mmdet/new_dcff/yolov8_pruning.py
, but getAttributeError: class
DCFFin mmrazor/models/algorithms/pruning/dcff.py: 'dict' object has no attribute 'bboxes'
; then I try to runpython tools/train.py configs/pruning/mmdet/new_dcff/yolov8_pruning.py
to train it directly, it still comes to the same error. The detail of this error as follows.and here is my prune config, and I don't change the yolov8 config file in mmyolo.
Environment
Expected results
No response
Additional information
This yolov8 model can be trained normally in mmyolo;
I print the
gt_instance
inmmyolo/mmyolo/models/dense_heads/yolov8_head.py line 423
as follows:there is no attribute like
bboxes
andlabels
which they should be in there, but I have no idea about this. This may be because it is not correctly read in the label, but I can train this model in mmyolo...The text was updated successfully, but these errors were encountered: