open-mmlab / mmrotate

OpenMMLab Rotated Object Detection Toolbox and Benchmark
https://mmrotate.readthedocs.io/en/latest/
Apache License 2.0
1.88k stars 559 forks source link

module 'torch' has no attribute 'pi' #907

Open yangzishy opened 1 year ago

yangzishy commented 1 year ago

Prerequisite

Task

I have modified the scripts/configs, or I'm working on my own tasks/models/datasets.

Branch

1.x branch https://github.com/open-mmlab/mmrotate/tree/1.x

Environment

sys.platform: linux Python: 3.8.16 (default, Mar 2 2023, 03:21:46) [GCC 11.2.0] CUDA available: True numpy_random_seed: 2147483648 GPU 0: NVIDIA GeForce RTX 3090 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.1, V11.1.105 GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.8.0 PyTorch compiling details: PyTorch built with:

TorchVision: 0.9.0 OpenCV: 4.7.0 MMEngine: 0.7.0 MMRotate: 1.0.0rc1+

Reproduces the problem - code sample

07/24 09:27:25 - mmengine - WARNING - The "log_processor" registry in mmrotate did not set import location. Fallback to call mmrotate.utils.register_all_modules instead. 07/24 09:27:26 - mmengine - INFO -

System environment: sys.platform: linux Python: 3.8.16 (default, Mar 2 2023, 03:21:46) [GCC 11.2.0] CUDA available: True numpy_random_seed: 178754422 GPU 0: NVIDIA GeForce RTX 3090 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.1, V11.1.105 GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.8.0 PyTorch compiling details: PyTorch built with:

Runtime environment: cudnn_benchmark: False mp_cfg: {'mp_start_method': 'fork', 'opencv_num_threads': 0} dist_cfg: {'backend': 'nccl'} seed: None Distributed launcher: none Distributed training: False GPU number: 1

07/24 09:27:26 - mmengine - INFO - Config: dataset_type = 'DOTADataset' data_root = 'data/split_ss_dota/' file_client_args = dict(backend='disk') train_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True), dict( type='mmdet.RandomFlip', prob=0.75, direction=['horizontal', 'vertical', 'diagonal']), dict(type='mmdet.PackDetInputs') ] val_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True), dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ] test_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ] train_dataloader = dict( batch_size=2, num_workers=2, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), batch_sampler=None, dataset=dict( type='DOTADataset', data_root='data/split_ss_dota/', ann_file='train/annfiles/', data_prefix=dict(img_path='train/images/'), img_shape=(1024, 1024), filter_cfg=dict(filter_empty_gt=True), pipeline=[ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict( type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict( type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True), dict( type='mmdet.RandomFlip', prob=0.75, direction=['horizontal', 'vertical', 'diagonal']), dict(type='mmdet.PackDetInputs') ])) val_dataloader = dict( batch_size=2, num_workers=2, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='DOTADataset', data_root='data/split_ss_dota/', ann_file='trainval/annfiles/', data_prefix=dict(img_path='trainval/images/'), img_shape=(1024, 1024), test_mode=True, pipeline=[ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True), dict( type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict( type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ])) test_dataloader = dict( batch_size=2, num_workers=2, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='DOTADataset', data_root='data/split_ss_dota/', ann_file='train/annfiles/', data_prefix=dict(img_path='train/images/'), img_shape=(1024, 1024), test_mode=True, pipeline=[ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1024, 1024), keep_ratio=True), dict( type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict( type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ])) val_evaluator = dict(type='DOTAMetric', metric='mAP') test_evaluator = dict(type='DOTAMetric', metric='mAP') train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=1, val_interval=1) val_cfg = dict(type='ValLoop') test_cfg = dict(type='TestLoop') param_scheduler = [ dict( type='LinearLR', start_factor=0.3333333333333333, by_epoch=False, begin=0, end=500), dict( type='MultiStepLR', begin=0, end=12, by_epoch=True, milestones=[8, 11], gamma=0.1) ] optim_wrapper = dict( type='AmpOptimWrapper', optimizer=dict(type='SGD', lr=0.0025, momentum=0.9, weight_decay=0.0001), clip_grad=dict(max_norm=35, norm_type=2)) default_scope = 'mmrotate' default_hooks = dict( timer=dict(type='IterTimerHook'), logger=dict(type='LoggerHook', interval=500), param_scheduler=dict(type='ParamSchedulerHook'), checkpoint=dict(type='CheckpointHook', interval=36), sampler_seed=dict(type='DistSamplerSeedHook'), visualization=dict(type='mmdet.DetVisualizationHook')) env_cfg = dict( cudnn_benchmark=False, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [dict(type='LocalVisBackend')] visualizer = dict( type='RotLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer') log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True) log_level = 'INFO' load_from = None resume = False angle_version = 'le90' model = dict( type='mmdet.RetinaNet', data_preprocessor=dict( type='mmdet.DetDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_size_divisor=32, boxtype2tensor=False), backbone=dict( type='mmdet.ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=1, norm_cfg=dict(type='BN', requires_grad=True), norm_eval=True, style='pytorch', init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')), neck=dict( type='mmdet.FPN', in_channels=[256, 512, 1024, 2048], out_channels=256, start_level=1, add_extra_convs='on_input', num_outs=5), bbox_head=dict( type='AngleBranchRetinaHead', num_classes=1, in_channels=256, stacked_convs=4, feat_channels=256, anchor_generator=dict( type='FakeRotatedAnchorGenerator', angle_version=None, octave_base_scale=4, scales_per_octave=3, ratios=[1.0, 0.5, 2.0], strides=[8, 16, 32, 64, 128]), bbox_coder=dict( type='DeltaXYWHTRBBoxCoder', angle_version='le90', norm_factor=None, edge_swap=True, proj_xy=True, target_means=(0.0, 0.0, 0.0, 0.0, 0.0), target_stds=(1.0, 1.0, 1.0, 1.0, 1.0)), loss_cls=dict( type='mmdet.FocalLoss', use_sigmoid=True, gamma=2.0, alpha=0.25, loss_weight=1.0), loss_bbox=dict(type='mmdet.L1Loss', loss_weight=0.5), use_normalized_angle_feat=True, angle_coder=dict( type='PSCCoder', angle_version='le90', dual_freq=True, num_step=3), loss_angle=dict(type='mmdet.L1Loss', loss_weight=0.2)), train_cfg=dict( assigner=dict( type='mmdet.MaxIoUAssigner', pos_iou_thr=0.5, neg_iou_thr=0.4, min_pos_iou=0, ignore_iof_thr=-1, iou_calculator=dict(type='RBboxOverlaps2D')), sampler=dict(type='mmdet.PseudoSampler'), allowed_border=-1, pos_weight=-1, debug=False), test_cfg=dict( nms_pre=2000, min_bbox_size=0, score_thr=0.05, nms=dict(type='nms_rotated', iou_threshold=0.1), max_per_img=2000)) launcher = 'none' work_dir = 'run_model/rotated_retinanet_r50_psc_1'

07/24 09:27:26 - mmengine - WARNING - The "visualizer" registry in mmrotate did not set import location. Fallback to call mmrotate.utils.register_all_modules instead. 07/24 09:27:26 - mmengine - WARNING - The "vis_backend" registry in mmrotate did not set import location. Fallback to call mmrotate.utils.register_all_modules instead. 07/24 09:27:27 - mmengine - WARNING - The "model" registry in mmrotate did not set import location. Fallback to call mmrotate.utils.register_all_modules instead. 07/24 09:27:27 - mmengine - WARNING - The "model" registry in mmdet did not set import location. Fallback to call mmdet.utils.register_all_modules instead. 07/24 09:27:27 - mmengine - WARNING - The "task util" registry in mmrotate did not set import location. Fallback to call mmrotate.utils.register_all_modules instead. Traceback (most recent call last): File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg obj = obj_cls(*args) # type: ignore File "/root/autodl-fs/mmrotate-1.x/mmrotate/models/task_modules/coders/angle_coder.py", line 160, in init tuple( File "/root/autodl-fs/mmrotate-1.x/mmrotate/models/task_modules/coders/angle_coder.py", line 161, in torch.sin(torch.tensor(2 k * torch.pi / self.num_step)) AttributeError: module 'torch' has no attribute 'pi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg obj = obj_cls(*args) # type: ignore File "/root/autodl-fs/mmrotate-1.x/mmrotate/models/dense_heads/angle_branch_retina_head.py", line 70, in init self.angle_coder = TASK_UTILS.build(angle_coder) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, args, **kwargs, registry=self) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 135, in build_from_cfg raise type(e)( AttributeError: class PSCCoder in mmrotate/models/task_modules/coders/angle_coder.py: module 'torch' has no attribute 'pi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg obj = obj_cls(*args) # type: ignore File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmdet/models/detectors/retinanet.py", line 19, in init super().init( File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmdet/models/detectors/single_stage.py", line 35, in init self.bbox_head = MODELS.build(bbox_head) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, args, **kwargs, registry=self) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 241, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 135, in build_from_cfg raise type(e)( AttributeError: class AngleBranchRetinaHead in mmrotate/models/dense_heads/angle_branch_retina_head.py: class PSCCoder in mmrotate/models/task_modules/coders/angle_coder.py: module 'torch' has no attribute 'pi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "tools/train.py", line 122, in main() File "tools/train.py", line 111, in main runner = Runner.from_cfg(cfg) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/runner/runner.py", line 439, in from_cfg runner = cls( File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/runner/runner.py", line 406, in init self.model = self.build_model(model) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/runner/runner.py", line 808, in build_model model = MODELS.build(model) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 241, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/root/miniconda3/envs/mmrotate1.x/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 135, in build_from_cfg raise type(e)( AttributeError: class RetinaNet in mmdet/models/detectors/retinanet.py: class AngleBranchRetinaHead in mmrotate/models/dense_heads/angle_branch_retina_head.py: class PSCCoder in mmrotate/models/task_modules/coders/angle_coder.py: module 'torch' has no attribute 'pi'

Reproduces the problem - command or script

python tools/train.py --config configs/psc/rotated-retinanet-rbox-le90_r50_fpn_psc-dual_amp-1x_dota.py --work-dir run_model/rotated_retinanet_r50_psc_1

Reproduces the problem - error message

AttributeError: class RetinaNet in mmdet/models/detectors/retinanet.py: class AngleBranchRetinaHead in mmrotate/models/dense_heads/angle_branch_retina_head.py: class PSCCoder in mmrotate/models/task_modules/coders/angle_coder.py: module 'torch' has no attribute 'pi'

Additional information

The psc model can run smoothly.

yangxue0827 commented 1 year ago

Use math.pi instead or update your torch version.