Skip to content
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

DCFF pruning question #469

Closed
nuonepeaceyy opened this issue Mar 3, 2023 · 2 comments · May be fixed by #473
Closed

DCFF pruning question #469

nuonepeaceyy opened this issue Mar 3, 2023 · 2 comments · May be fixed by #473
Assignees
Labels
bug Something isn't working Pruning

Comments

@nuonepeaceyy
Copy link

Checklist

  • I have searched related issues but cannot get the expected help.
  • I have read related documents and don't know what to do.

Describe the question you meet

when I try to use python python tools/pruning/get_channel_units.py configs/pruning/mmdet/new_dcff/yolov5s_v8head_pruning.py to get the target_pruning_ratio, it comes an AttributeError as follows.

/home/keli/anaconda3/envs/mmrazor/lib/python3.8/site-packages/torch/functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  /opt/conda/conda-bld/pytorch_1659484810403/work/aten/src/ATen/native/TensorShape.cpp:2894.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Traceback (most recent call last):
  File "/home/keli/anaconda3/envs/mmrazor/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
    obj = obj_cls(**args)  # type: ignore
  File "/home/keli/Nuonepeaceyy/MMLAB/mmrazor/mmrazor/models/algorithms/pruning/dcff.py", line 62, in __init__
    super().__init__(architecture, mutator_cfg, data_preprocessor,
  File "/home/keli/Nuonepeaceyy/MMLAB/mmrazor/mmrazor/models/algorithms/pruning/ite_prune_algorithm.py", line 137, in __init__
    self.mutator.prepare_from_supernet(self.architecture)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmrazor/mmrazor/models/mutators/channel_mutator/channel_mutator.py", line 104, in prepare_from_supernet
    units = self._prepare_from_tracer(supernet, self.parse_cfg)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmrazor/mmrazor/models/mutators/channel_mutator/channel_mutator.py", line 300, in _prepare_from_tracer
    unit_configs = tracer.analyze(model)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmrazor/mmrazor/models/task_modules/tracer/channel_analyzer.py", line 127, in analyze
    return self._find_mutable_units(model, unit_configs)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmrazor/mmrazor/models/task_modules/tracer/channel_analyzer.py", line 154, in _find_mutable_units
    template_output = model(**inputs)
  File "/home/keli/anaconda3/envs/mmrazor/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/keli/.local/lib/python3.8/site-packages/mmdet/models/detectors/base.py", line 92, in forward
    return self.loss(inputs, data_samples)
  File "/home/keli/.local/lib/python3.8/site-packages/mmdet/models/detectors/single_stage.py", line 78, in loss
    losses = self.bbox_head.loss(x, batch_data_samples)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmyolo/mmyolo/models/dense_heads/yolov5_head.py", line 459, in loss
    losses = super().loss(x, batch_data_samples)
  File "/home/keli/.local/lib/python3.8/site-packages/mmdet/models/dense_heads/base_dense_head.py", line 123, in loss
    losses = self.loss_by_feat(*loss_inputs)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmyolo/mmyolo/models/dense_heads/yolov8_head.py", line 314, in loss_by_feat
    gt_info = self.gt_instances_preprocess(batch_gt_instances, num_imgs)
  File "/home/keli/Nuonepeaceyy/MMLAB/mmyolo/mmyolo/models/dense_heads/yolov8_head.py", line 424, in gt_instances_preprocess
    bboxes = gt_instance.bboxes
AttributeError: 'dict' object has no attribute 'bboxes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/pruning/get_channel_units.py", line 84, in <module>
    main()
  File "tools/pruning/get_channel_units.py", line 48, in main
    model = MODELS.build(config['model'])
  File "/home/keli/anaconda3/envs/mmrazor/lib/python3.8/site-packages/mmengine/registry/registry.py", line 521, in build
    return self.build_func(cfg, *args, **kwargs, registry=self)
  File "/home/keli/anaconda3/envs/mmrazor/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 "/home/keli/anaconda3/envs/mmrazor/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 135, in build_from_cfg
    raise type(e)(
AttributeError: class `DCFF` in mmrazor/models/algorithms/pruning/dcff.py: 'dict' object has no attribute 'bboxes'

YOLOv8 can be trained in mmyolo.

Post related information

  1. The output of pip list | grep "mmcv\|mmrazor\|^torch"
mmcv                    2.0.0rc4
mmrazor                 1.0.0rc2           /home/keli/Nuonepeaceyy/MMLAB/mmrazor
mmyolo                  0.4.0              /home/keli/Nuonepeaceyy/MMLAB/mmyolo
torch                   1.12.1
torchaudio              0.12.1
torchvision             0.13.1
  1. Your config file if you modified it or created a new one.
_base_ = 'mmyolo::yolov8/yolov8_l_syncbn_fast_8xb16-500e_coco.py'

data_root = 'data/coco/'

architecture = _base_.model

model = dict(
    _delete_=True,
    _scope_='mmrazor',
    type='DCFF',
    architecture=architecture,
    mutator_cfg=dict(
        type='DCFFChannelMutator',
        channel_unit_cfg=dict(
            type='DCFFChannelUnit', default_args=dict(choice_mode='ratio')),
        parse_cfg=dict(
            type='ChannelAnalyzer',
            demo_input=(1, 3, 224, 224),
            tracer_type='FxTracer')),
    # target_pruning_ratio=target_pruning_ratio,
    step_freq=1,
    linear_schedule=False)

# del _base_.train_dataloader.collate_fn
del _base_.custom_hooks

train_dataloader = dict(
    dataset=dict(
        _delete_=True,
        type='mmyolo.YOLOv5CocoDataset',
        data_root=data_root,
        # metainfo=_base_.metainfo,
        data_prefix=dict(img='train/'),
        ann_file='annotations/voc07_train.json',
        filter_cfg=dict(filter_empty_gt=False, min_size=32),
        pipeline=_base_.train_pipeline))
val_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        # metainfo=_base_.metainfo,
        data_prefix=dict(img='val/'),
        ann_file='annotations/voc07_val.json'))
test_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        # metainfo=_base_.metainfo,
        data_prefix=dict(img='test/'),
        ann_file='annotations/voc07_test.json'))
val_evaluator = dict(ann_file=data_root + 'annotations/voc07_val.json')
test_evaluator = dict(ann_file=data_root + 'annotations/voc07_test.json')

model_wrapper = dict(
    type='mmcv.MMDistributedDataParallel', find_unused_parameters=True)

default_hooks = dict(param_scheduler=dict(max_epochs=150))
train_cfg = dict(max_epochs=150, val_interval=5)
val_cfg = dict(_delete_=True, type='mmrazor.ItePruneValLoop')
  1. Your train log file if you meet the problem during training.
    [here]
  2. Other code you modified in the mmrazor folder.
    [here]
@pppppM pppppM added bug Something isn't working Pruning labels Mar 7, 2023
@pppppM pppppM linked a pull request Mar 7, 2023 that will close this issue
6 tasks
@LKJacky
Copy link
Collaborator

LKJacky commented Mar 8, 2023

Duplicate of open-mmlab/mmyolo#622

@LKJacky LKJacky marked this as a duplicate of open-mmlab/mmyolo#622 Mar 8, 2023
@LKJacky
Copy link
Collaborator

LKJacky commented Apr 14, 2023

We closed the issue as there has been no response in a long time. You can reopen it when you need.

@LKJacky LKJacky closed this as completed Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Pruning
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants