AttributeError: 'RetinaNetBackbone' object has no attribute 'alpha_head_index'
yitang-hnu opened this issue · 3 comments
Thanks for your great work of parameter remapping to avoid huge computational cost in ImageNet pre-training.
I met a little bug when I run your code. The main reason is that the 'alpha_head_index' is not the attribution of 'RetinaNetBackbone' and I find there is no 'alpha_head_index' in the 'RetinaNetBackbone' from the fna_base_backbone.py, but the 'alpha_head_index' appear in optimizer.py line 45 . So I can not run this code after 8 epoch.
I hope you can help me clarify this. Thanks a lot.
The error reporter is as follow:
12/16 05:14:55 PM - Distributed training: False
12/16 05:14:55 PM - Search args:
Namespace(data_path=None, gpus=1, job_name='', launcher='none', local_rank=0, port=23333, seed=None, validate=False, work_dir=None)
12/16 05:14:55 PM - Search configs:
Config (path: /home/ty/ty/nas_mmdet/mmdetection/baseline/fna_retinanet_fpn_search.py): {'type': 'Retinanet', 'model': {'type': 'NASRetinaNet', 'pretrained': {'use_load': True, 'load_path': '/home/ty/ty/nas_mmdet/mmdetection/seed_mbv2.pt', 'seed_num_layers': [1, 1, 2, 3, 4, 3, 3, 1, 1]}, 'backbone': {'type': 'RetinaNetBackbone', 'search_params': {'sample_policy': 'prob', 'weight_sample_num': 1, 'affine': False, 'track': False, 'net_scale': {'chs': [32, 16, 24, 32, 64, 96, 160, 320], 'num_layers': [4, 4, 4, 4, 4, 1], 'strides': [2, 1, 2, 2, 2, 1, 2, 1, 1]}, 'primitives_normal': ['k3_e3', 'k3_e6', 'k5_e3', 'k5_e6', 'k7_e3', 'k7_e6', 'skip'], 'primitives_reduce': ['k3_e3', 'k3_e6', 'k5_e3', 'k5_e6', 'k7_e3', 'k7_e6']}, 'output_indices': [2, 3, 5, 7]}, 'neck': {'type': 'FPN', 'in_channels': [24, 32, 96, 320], 'out_channels': 256, 'start_level': 1, 'add_extra_convs': True, 'num_outs': 5}, 'bbox_head': {'type': 'RetinaHead', 'num_classes': 1, 'in_channels': 256, 'stacked_convs': 4, 'feat_channels': 256, 'anchor_generator': {'type': 'AnchorGenerator', 'octave_base_scale': 4, 'scales_per_octave': 3, 'ratios': [0.5, 1.0, 2.0], 'strides': [8, 16, 32, 64, 128]}, 'bbox_coder': {'type': 'DeltaXYWHBBoxCoder', 'target_means': [0.0, 0.0, 0.0, 0.0], 'target_stds': [1.0, 1.0, 1.0, 1.0]}, 'loss_cls': {'type': 'FocalLoss', 'use_sigmoid': True, 'gamma': 2.0, 'alpha': 0.25, 'loss_weight': 1.0}, 'loss_bbox': {'type': 'L1Loss', 'loss_weight': 1.0}, 'final_crop': False}}, 'train_cfg': {'assigner': {'type': 'MaxIoUAssigner', 'pos_iou_thr': 0.5, 'neg_iou_thr': 0.4, 'min_pos_iou': 0, 'ignore_iof_thr': -1}, 'smoothl1_beta': 0.11, 'gamma': 2.0, 'alpha': 0.25, 'allowed_border': -1, 'pos_weight': -1, 'debug': False}, 'test_cfg': {'nms_pre': 2000, 'min_bbox_size': 0, 'score_thr': 0.1, 'nms': {'type': 'nms', 'iou_thr': 0.4}, 'max_per_img': 1000}, 'dataset_type': 'CrowdHumanDataset', 'data_root': '/home/ty/ty/data/crowd_human/', 'img_norm_cfg': {'mean': [123.675, 116.28, 103.53], 'std': [58.395, 57.12, 57.375], 'to_rgb': True}, 'train_pipeline': [{'type': 'LoadImageFromFile'}, {'type': 'LoadAnnotations', 'with_bbox': True}, {'type': 'Resize', 'img_scale': (1400, 800), 'keep_ratio': True, 'final_crop': False}, {'type': 'RandomFlip', 'flip_ratio': 0.5}, {'type': 'Normalize', 'mean': [123.675, 116.28, 103.53], 'std': [58.395, 57.12, 57.375], 'to_rgb': True}, {'type': 'Pad', 'size_divisor': 32}, {'type': 'DefaultFormatBundle'}, {'type': 'Collect', 'keys': ['img', 'gt_bboxes', 'gt_labels', 'gt_bboxes_ignore']}], 'test_pipeline': [{'type': 'LoadImageFromFile'}, {'type': 'MultiScaleFlipAug', 'img_scale': (1400, 800), 'flip': False, 'transforms': [{'type': 'Resize', 'keep_ratio': True}, {'type': 'RandomFlip'}, {'type': 'Normalize', 'mean': [123.675, 116.28, 103.53], 'std': [58.395, 57.12, 57.375], 'to_rgb': True}, {'type': 'Pad', 'size_divisor': 32}, {'type': 'ImageToTensor', 'keys': ['img']}, {'type': 'Collect', 'keys': ['img']}]}], 'data': {'samples_per_gpu': 1, 'workers_per_gpu': 2, 'train': {'type': 'CrowdHumanDataset', 'ann_file': '/home/ty/ty/data/crowd_human/annotation_full_train.json', 'img_prefix': '/home/ty/ty/data/crowd_human/Images/', 'pipeline': [{'type': 'LoadImageFromFile'}, {'type': 'LoadAnnotations', 'with_bbox': True}, {'type': 'Resize', 'img_scale': (1400, 800), 'keep_ratio': True, 'final_crop': False}, {'type': 'RandomFlip', 'flip_ratio': 0.5}, {'type': 'Normalize', 'mean': [123.675, 116.28, 103.53], 'std': [58.395, 57.12, 57.375], 'to_rgb': True}, {'type': 'Pad', 'size_divisor': 32}, {'type': 'DefaultFormatBundle'}, {'type': 'Collect', 'keys': ['img', 'gt_bboxes', 'gt_labels', 'gt_bboxes_ignore']}]}, 'val': {'type': 'CrowdHumanDataset', 'ann_file': '/home/ty/ty/data/crowd_human/annotation_full_val.json', 'img_prefix': '/home/ty/ty/data/crowd_human/Images/', 'pipeline': [{'type': 'LoadImageFromFile'}, {'type': 'LoadAnnotations', 'with_bbox': True}, {'type': 'Resize', 'img_scale': (1400, 800), 'keep_ratio': True, 'final_crop': False}, {'type': 'RandomFlip', 'flip_ratio': 0.5}, {'type': 'Normalize', 'mean': [123.675, 116.28, 103.53], 'std': [58.395, 57.12, 57.375], 'to_rgb': True}, {'type': 'Pad', 'size_divisor': 32}, {'type': 'DefaultFormatBundle'}, {'type': 'Collect', 'keys': ['img', 'gt_bboxes', 'gt_labels', 'gt_bboxes_ignore']}]}, 'test': {'type': 'CrowdHumanDataset', 'ann_file': '/home/ty/ty/data/crowd_human/annotation_full_val.json', 'img_prefix': '/home/ty/ty/data/crowd_human/Images/', 'pipeline': [{'type': 'LoadImageFromFile'}, {'type': 'MultiScaleFlipAug', 'img_scale': (1400, 800), 'flip': False, 'transforms': [{'type': 'Resize', 'keep_ratio': True}, {'type': 'RandomFlip'}, {'type': 'Normalize', 'mean': [123.675, 116.28, 103.53], 'std': [58.395, 57.12, 57.375], 'to_rgb': True}, {'type': 'Pad', 'size_divisor': 32}, {'type': 'ImageToTensor', 'keys': ['img']}, {'type': 'Collect', 'keys': ['img']}]}]}}, 'optimizer': {'weight_optim': {'optimizer': {'type': 'SGD', 'lr': 0.005, 'momentum': 0.9, 'weight_decay': 0.0001}, 'optimizer_config': {'grad_clip': {'max_norm': 35, 'norm_type': 2}}}, 'arch_optim': {'optimizer': {'type': 'Adam', 'lr': 0.0003, 'weight_decay': 0.001, 'betas': (0.5, 0.999)}, 'optimizer_config': {'grad_clip': {'max_norm': 35, 'norm_type': 2}}}}, 'lr_config': {'policy': 'step', 'warmup': 'linear', 'warmup_iters': 500, 'warmup_ratio': 0.3333333333333333, 'step': [8, 11, 14]}, 'checkpoint_config': {'interval': 1}, 'log_config': {'interval': 500, 'hooks': [{'type': 'TextLoggerHook'}]}, 'sub_obj': {'if_sub_obj': True, 'type': 'flops', 'log_base': 100.0, 'sub_loss_factor': 0.02}, 'total_epochs': 14, 'use_syncbn': False, 'arch_update_epoch': 8, 'alter_type': 'step', 'train_data_ratio': 0.5, 'image_size_madds': (800, 1088), 'model_info_interval': 1000, 'device_ids': range(0, 4), 'dist_params': {'backend': 'nccl'}, 'log_level': 'INFO', 'work_dir': './work_dirs/', 'load_from': None, 'resume_from': '/home/ty/ty/nas_mmdet/mmdetection/tools/work_dirs/epoch_8.pth', 'workflow': [('arch', 1), ('train', 1)], 'gpus': 1}
2020-12-16 17:15:00,951 - mmdet - INFO - load model from: {'use_load': True, 'load_path': '/home/ty/ty/nas_mmdet/mmdetection/seed_mbv2.pt', 'seed_num_layers': [1, 1, 2, 3, 4, 3, 3, 1, 1]}
12/16 05:15:00 PM - load model from: {'use_load': True, 'load_path': '/home/ty/ty/nas_mmdet/mmdetection/seed_mbv2.pt', 'seed_num_layers': [1, 1, 2, 3, 4, 3, 3, 1, 1]}
12/16 05:15:01 PM - Start loading the model from /home/ty/ty/nas_mmdet/mmdetection/seed_mbv2.pt
12/16 05:15:01 PM - Remapping for architecture adaptation starts!
12/16 05:15:01 PM - Remapping for architecture adaptation finished!
12/16 05:15:10 PM - load checkpoint from /home/ty/ty/nas_mmdet/mmdetection/tools/work_dirs/epoch_8.pth
12/16 05:15:10 PM - resumed epoch 8, iter 30008
12/16 05:15:10 PM - Start running, host: ty@admin.cluster.local, work_dir: /amax/data/ty/nas_mmdet/mmdetection/tools/work_dirs
12/16 05:15:10 PM - workflow: [('arch', 1), ('train', 1)], max: 14 epochs
Traceback (most recent call last):
File "/home/ty/ty/nas_mmdet/mmdetection/tools/search_test.py", line 127, in
main()
File "/home/ty/ty/nas_mmdet/mmdetection/tools/search_test.py", line 123, in main
logger=logger)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/apis/fna_search_apis.py", line 91, in search_detector
_non_dist_train(model, datasets, cfg, validate=validate, logger=logger)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/apis/fna_search_apis.py", line 167, in _non_dist_train
runner.run(data_loaders, cfg.workflow, cfg.total_epochs, cfg.arch_update_epoch)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/apis/fna_search_runner.py", line 80, in run
self.run_step_alter(data_loaders, workflow, max_epochs, arch_update_epoch, **kwargs)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/apis/fna_search_runner.py", line 187, in run_step_alter
self.train_step_alter(data_loaders)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/apis/fna_search_runner.py", line 244, in train_step_alter
self.call_hook('after_train_iter', mode)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/apis/fna_search_runner.py", line 392, in call_hook
getattr(hook, fn_name)(self)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/hooks/optimizer.py", line 23, in after_train_iter
self.rescale_arch_params(runner.super_backbone)
File "/amax/data/ty/nas_mmdet/mmdetection/tools/hooks/optimizer.py", line 45, in rescale_arch_params
alpha_head_index = model.alpha_head_index
File "/home/ty/ty/anaconda3/envs/mmdet_nas/lib/python3.7/site-packages/torch/nn/modules/module.py", line 576, in getattr
type(self).name, name))
AttributeError: 'RetinaNetBackbone' object has no attribute 'alpha_head_index'
Process finished with exit code 1
Hi, ArchOptimizerHook
as shown below is deprecated.
FNA/fna_det/tools/hooks/optimizer.py
Line 11 in 898ec5d
Please use
ArchDistOptimizerHook
instead as the original code.FNA/fna_det/tools/hooks/optimizer.py
Line 73 in 898ec5d
I’ve changed it and it really work. Thanks!