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

AssertionError: "neck" is not in the model. #654

Closed
XiaoSiJi-GCY opened this issue Sep 28, 2024 · 3 comments
Closed

AssertionError: "neck" is not in the model. #654

XiaoSiJi-GCY opened this issue Sep 28, 2024 · 3 comments

Comments

@XiaoSiJi-GCY
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

[After configuring configs/distill/mmdet/cwd/cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco.py to train.py to run and train, and then configure and run feature_virtualization.py but reported error AssertionError: “neck” is not in the model.
which step may be missing, please help me.]

Post related information

  1. The output of pip list | grep "mmcv\|mmrazor\|^torch"
    [here]
  2. Your config file if you modified it or created a new one.
auto_scale_lr = dict(base_batch_size=16, enable=False)
backend_args = None
data_root = 'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\train2017'
dataset_type = 'CocoDataset'

default_hooks = dict(
    checkpoint=dict(_scope_='mmdet', interval=1, type='CheckpointHook'),
    logger=dict(_scope_='mmdet', interval=50, type='LoggerHook'),
    param_scheduler=dict(_scope_='mmdet', type='ParamSchedulerHook'),
    sampler_seed=dict(_scope_='mmdet', type='DistSamplerSeedHook'),
    timer=dict(_scope_='mmdet', type='IterTimerHook'),
    visualization=dict(_scope_='mmdet', draw=True, show=True, type='DetVisualizationHook', wait_time=2))

default_scope = 'mmdet'

env_cfg = dict(
    cudnn_benchmark=False,
    dist_cfg=dict(backend='nccl'),
    mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0))
find_unused_parameters = True
launcher = 'none'

# load_from = 'D:\\\\AcademicResearch\\\\PaperCode\\\\MMCV_tutorials\\\\mmrazor-main\\\\tools\\\\work_dirs\\\\cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco\\\\epoch_10.pth'
load_from ='D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\tools\\work_dirs\\cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco\\gfl_r101_fpn_mstrain_2x_coco_20200629_200126-dd12f847.pth'


log_level = 'INFO'
log_processor = dict(
    _scope_='mmdet', by_epoch=True, type='LogProcessor', window_size=50)

model = dict(
    _scope_='mmrazor',

    architecture=dict(
        # cfg_path='mmdet::gfl/gfl_r50_fpn_1x_coco.py', pretrained=False),
        cfg_path='mmdet::gfl/gfl_r50_fpn_1x_coco.py', pretrained=True),

        ################################

        ##############################

    distiller=dict(
        distill_losses=dict(
            loss_cwd_fpn0=dict(
                loss_weight=10, tau=1, type='ChannelWiseDivergence'),
            loss_cwd_fpn1=dict(
                loss_weight=10, tau=1, type='ChannelWiseDivergence'),
            loss_cwd_fpn2=dict(
                loss_weight=10, tau=1, type='ChannelWiseDivergence'),
            loss_cwd_fpn3=dict(
                loss_weight=10, tau=1, type='ChannelWiseDivergence'),
            loss_cwd_fpn4=dict(
                loss_weight=10, tau=1, type='ChannelWiseDivergence')),
        loss_forward_mappings=dict(
            loss_cwd_fpn0=dict(
                preds_S=dict(data_idx=0, from_student=True, recorder='fpn'),
                preds_T=dict(data_idx=0, from_student=False, recorder='fpn')),
            loss_cwd_fpn1=dict(
                preds_S=dict(data_idx=1, from_student=True, recorder='fpn'),
                preds_T=dict(data_idx=1, from_student=False, recorder='fpn')),
            loss_cwd_fpn2=dict(
                preds_S=dict(data_idx=2, from_student=True, recorder='fpn'),
                preds_T=dict(data_idx=2, from_student=False, recorder='fpn')),
            loss_cwd_fpn3=dict(
                preds_S=dict(data_idx=3, from_student=True, recorder='fpn'),
                preds_T=dict(data_idx=3, from_student=False, recorder='fpn')),
            loss_cwd_fpn4=dict(
                preds_S=dict(data_idx=4, from_student=True, recorder='fpn'),
                preds_T=dict(data_idx=4, from_student=False, recorder='fpn'))),
        student_recorders=dict(fpn=dict(source='neck', type='ModuleOutputs')),
        teacher_recorders=dict(fpn=dict(source='neck', type='ModuleOutputs')),
        type='ConfigurableDistiller'),

    teacher=dict(
        cfg_path='mmdet::gfl/gfl_r101_fpn_ms-2x_coco.py', pretrained=True),
    type='FpnTeacherDistill')

optim_wrapper = dict(
    _scope_='mmdet',
    optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0001),
    type='OptimWrapper')

param_scheduler = [
    dict(
        _scope_='mmdet',
        begin=0,
        by_epoch=False,
        end=500,
        start_factor=0.001,
        type='LinearLR'),
    dict(
        _scope_='mmdet',
        begin=0,
        by_epoch=True,
        end=12,
        gamma=0.1,
        milestones=[
            8,
            11,
        ],
        type='MultiStepLR'),
]
resume = False
test_cfg = dict(_scope_='mmdet', type='TestLoop')
test_dataloader = dict(
    batch_size=1,
    dataset=dict(
        _scope_='mmdet',
        ann_file=
        'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\annotations\\instances_val2017.json',
        backend_args=None,
        data_prefix=dict(
            img=
            'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\val2017'
        ),
        data_root=
        'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\train2017',
        pipeline=[
            dict(backend_args=None, type='LoadImageFromFile'),
            dict(keep_ratio=True, scale=(
                1333,
                800,
            ), type='Resize'),
            dict(type='LoadAnnotations', with_bbox=True),
            dict(
                meta_keys=(
                    'img_id',
                    'img_path',
                    'ori_shape',
                    'img_shape',
                    'scale_factor',
                ),
                type='PackDetInputs'),
        ],
        test_mode=True,
        type='CocoDataset'),
    drop_last=False,
    num_workers=2,
    persistent_workers=True,
    sampler=dict(_scope_='mmdet', shuffle=False, type='DefaultSampler'))
test_evaluator = dict(
    _scope_='mmdet',
    ann_file=
    'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\annotations\\instances_val2017.json',
    backend_args=None,
    format_only=False,
    metric='bbox',
    type='CocoMetric')
test_pipeline = [
    dict(_scope_='mmdet', backend_args=None, type='LoadImageFromFile'),
    dict(_scope_='mmdet', keep_ratio=True, scale=(
        1333,
        800,
    ), type='Resize'),
    dict(_scope_='mmdet', type='LoadAnnotations', with_bbox=True),
    dict(
        _scope_='mmdet',
        meta_keys=(
            'img_id',
            'img_path',
            'ori_shape',
            'img_shape',
            'scale_factor',
        ),
        type='PackDetInputs'),
]
train_cfg = dict(
    _scope_='mmdet',
    max_epochs=20,
    type='EpochBasedTrainLoop',
    val_interval=10)
train_dataloader = dict(
    batch_sampler=dict(_scope_='mmdet', type='AspectRatioBatchSampler'),
    batch_size=2,
    dataset=dict(
        _scope_='mmdet',
        ann_file=
        'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\annotations\\instances_train2017.json',
        backend_args=None,
        data_prefix=dict(
            img=
            'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\train2017'
        ),
        data_root=
        'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\train2017',
        filter_cfg=dict(filter_empty_gt=True, min_size=32),
        pipeline=[
            dict(backend_args=None, type='LoadImageFromFile'),
            dict(type='LoadAnnotations', with_bbox=True),
            dict(keep_ratio=True, scale=(
                1333,
                800,
            ), type='Resize'),
            dict(prob=0.5, type='RandomFlip'),
            dict(type='PackDetInputs'),
        ],
        type='CocoDataset'),
    num_workers=2,
    persistent_workers=True,
    sampler=dict(_scope_='mmdet', shuffle=True, type='DefaultSampler'))
train_pipeline = [
    dict(_scope_='mmdet', backend_args=None, type='LoadImageFromFile'),
    dict(_scope_='mmdet', type='LoadAnnotations', with_bbox=True),
    dict(_scope_='mmdet', keep_ratio=True, scale=(
        1333,
        800,
    ), type='Resize'),
    dict(_scope_='mmdet', prob=0.5, type='RandomFlip'),
    dict(_scope_='mmdet', type='PackDetInputs'),
]
val_cfg = dict(type='mmrazor.SingleTeacherDistillValLoop')
val_dataloader = dict(
    batch_size=1,
    dataset=dict(
        _scope_='mmdet',
        ann_file=
        'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\annotations\\instances_val2017.json',
        backend_args=None,
        data_prefix=dict(
            img=
            'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\val2017'
        ),
        data_root=
        'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\train2017',
        pipeline=[
            dict(backend_args=None, type='LoadImageFromFile'),
            dict(keep_ratio=True, scale=(
                1333,
                800,
            ), type='Resize'),
            dict(type='LoadAnnotations', with_bbox=True),
            dict(
                meta_keys=(
                    'img_id',
                    'img_path',
                    'ori_shape',
                    'img_shape',
                    'scale_factor',
                ),
                type='PackDetInputs'),
        ],
        test_mode=True,
        type='CocoDataset'),
    drop_last=False,
    num_workers=2,
    persistent_workers=True,
    sampler=dict(_scope_='mmdet', shuffle=False, type='DefaultSampler'))
val_evaluator = dict(
    _scope_='mmdet',
    ann_file=
    'D:\\AcademicResearch\\PaperCode\\MMCV_tutorials\\mmrazor-main\\data\\coco\\annotations\\instances_val2017.json',
    backend_args=None,
    format_only=False,
    metric='bbox',
    type='CocoMetric')
vis_backends = [
    dict(_scope_='mmdet', type='LocalVisBackend'),
]
visualizer = dict(
    _scope_='mmdet',
    name='visualizer',
    type='DetLocalVisualizer',
    vis_backends=[
        dict(type='LocalVisBackend'),
    ])
work_dir = './work_dirs\\cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco'
  1. Your train log file if you meet the problem during training.
    C:\ProgramData\anaconda3\envs\MMrazor\python.exe D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\visualizations\feature_visualization.py D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\data\coco\train2017\12.jpg D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\work_dirs\cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco\my20240924_cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco.py D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\visualizations\vis_configs\fpn_feature_visualization.py D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\work_dirs\cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco\epoch_10.pth --device cuda:0 --repo mmdet --use-norm --overlaid --channel-reduction pixel_wise_max
    C:\ProgramData\anaconda3\envs\MMrazor\lib\site-packages\mmdet\models\dense_heads\anchor_head.py:108: UserWarning: DeprecationWarning: num_anchors is deprecated, for consistency or also use num_base_priors instead
    warnings.warn('DeprecationWarning: num_anchors is deprecated, '
    Loads checkpoint by http backend from path: https://download.openmmlab.com/mmdetection/v2.0/gfl/gfl_r50_fpn_1x_coco/gfl_r50_fpn_1x_coco_20200629_121244-25944287.pth
    C:\ProgramData\anaconda3\envs\MMrazor\lib\site-packages\mmdet\models\dense_heads\anchor_head.py:108: UserWarning: DeprecationWarning: num_anchors is deprecated, for consistency or also use num_base_priors instead
    warnings.warn('DeprecationWarning: num_anchors is deprecated, '
    Loads checkpoint by http backend from path: https://download.openmmlab.com/mmdetection/v2.0/gfl/gfl_r101_fpn_mstrain_2x_coco/gfl_r101_fpn_mstrain_2x_coco_20200629_200126-dd12f847.pth
    Loads checkpoint by local backend from path: D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\work_dirs\cwd_cls_head_gfl_r101_fpn_gfl_r50_fpn_1x_coco\epoch_10.pth
    C:\ProgramData\anaconda3\envs\MMrazor\lib\site-packages\mmengine\visualization\visualizer.py:196: UserWarning: Failed to add <class 'mmengine.visualization.vis_backend.LocalVisBackend'>, please provide the save_dir argument.
    warnings.warn(f'Failed to add {vis_backend.class}, '
    Traceback (most recent call last):
    File "D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\visualizations\feature_visualization.py", line 185, in
    main(args)
    File "D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\tools\visualizations\feature_visualization.py", line 143, in main
    recorder_manager.initialize(model)
    File "D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\mmrazor\models\task_modules\recorder\recorder_manager.py", line 106, in initialize
    recorder.initialize(model)
    File "D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\mmrazor\models\task_modules\recorder\base_recorder.py", line 58, in initialize
    self.prepare_from_model(model)
    File "D:\AcademicResearch\PaperCode\MMCV_tutorials\mmrazor-main\mmrazor\models\task_modules\recorder\module_outputs_recorder.py", line 74, in prepare_from_model
    assert founded, f'"{self.source}" is not in the model.'
    AssertionError: "neck" is not in the model.

Process finished with exit code 1
4. Other code you modified in the mmrazor folder.
[here]

@tori-hotaru
Copy link

I also face this question in visualization. After several experiments, I think this is because in distill model, the neck name is differents in vis_config and your true config. For me, after I check my params, the neck name is "architecture.neck" not "neck". Because I use vis_config/fpn_feature_visualization.py as vis_config. So I changerecorders = dict( neck=dict(_scope_='mmrazor', type='ModuleOutputs', source='neck')) to recorders = dict( neck=dict(_scope_='mmrazor', type='ModuleOutputs', source='architecture.neck')). It works. I hope this can help you.

@tori-hotaru
Copy link

Anyway, this repo comparing with other repo from openmmlab is out of date. Maybe is a dead repo. So there are many issues and bugs in this repo.

@XiaoSiJi-GCY
Copy link
Author

Thank you very much, have been able to run feature_visualization.py properly, just following the solution you described.
Thank you again.
@tori-hotaru

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants