open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.59k stars 9.46k forks source link

AttributeError: 'ConfigDict' object has no attribute 'device' #8278

Closed ccsimp1e closed 2 years ago

ccsimp1e commented 2 years ago

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The bug has not been fixed in the latest version.

Describe the bug A clear and concise description of what the bug is.

Reproduction

  1. What command or script did you run?
A placeholder for the command.
  1. Did you make any modifications on the code or config? Did you understand what you have modified?
  2. What dataset did you use?

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.
  2. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)

Error traceback If applicable, paste the error trackback here.

A placeholder for trackback.

Bug fix If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

hhaAndroid commented 2 years ago

@ccsimp1e Please complete the information, thank you.

Hiyao-yy commented 2 years ago

AttributeError: 'ConfigDict' object has no attribute 'device'

ModestYjx commented 2 years ago

image

Hiyao-yy commented 2 years ago

谢谢你,以后要常联系哦

ModestYjx commented 2 years ago

error:

AttributeError: 'ConfigDict' object has no attribute 'device'
Traceback (most recent call last):
  File "./train.py", line 193, in <module>
    main()
  File "./train.py", line 182, in main
    train_detector(
  File "/home/yjxun/code/mmdetection/mmdet/apis/train.py", line 158, in train_detector
    cfg.device,
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/mmcv/utils/config.py", line 519, in __getattr__
    return getattr(self._cfg_dict, name)
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/mmcv/utils/config.py", line 50, in __getattr__
    raise ex
AttributeError: 'ConfigDict' object has no attribute 'device'
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 17762 closing signal SIGTERM
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 17758) of binary: /home/yjxun/anaconda3/envs/Unive
rseNet/bin/python
Traceback (most recent call last):
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/torch/distributed/launch.py", line 193, in <module>
    main()
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/torch/distributed/launch.py", line 189, in main
    launch(args)
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/torch/distributed/launch.py", line 174, in launch
    run(args)
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/torch/distributed/run.py", line 752, in run
    elastic_launch(
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 131, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/home/yjxun/anaconda3/envs/UniverseNet/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 245, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError:
============================================================
./train.py FAILED
-----------------------------------------------------------

repo

https://github.com/hunto/LightViT         (based on mmdetection)

command

bash ./dist_train.sh /home/yjxun/code/LightViT/detection/configs/mask_rcnn_lightvit_b
ase_fpn_3x_ms_coco.py 4

mmdet version:

TorchVision: 0.13.0
OpenCV: 4.6.0
MMCV: 1.6.0
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: 10.2
MMDetection: 2.25.1+e2452a1

other log

optimizer_config = dict(grad_clip=None)
lr_config = dict(
    policy='step',
    warmup='linear',
    warmup_iters=500,
    warmup_ratio=0.001,
    step=[27, 33])
runner = dict(type='EpochBasedRunner', max_epochs=36)
checkpoint_config = dict(interval=1)
log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')])
dist_params = dict(backend='nccl')
log_level = 'INFO'
load_from = None
resume_from = None
workflow = [('train', 1)]
find_unused_parameters = True
total_epochs = 36
work_dir = './work_dirs/mask_rcnn_lightvit_base_fpn_3x_ms_coco'
gpu_ids = range(0, 4)

and I changed codes here compared to LightViT:

        bbox_head=dict(
            type='Shared2FCBBoxHead',
            in_channels=256,
            fc_out_channels=1024,
            roi_feat_size=7,
            num_classes=3,
            bbox_coder=dict(

        mask_head=dict(
            type='FCNMaskHead',
            num_convs=4,
            in_channels=256,
            conv_out_channels=256,
            num_classes=3,
            loss_mask=dict(
                type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))),
class CocoDataset(CustomDataset):

    # CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
    #            'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
    #            'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
    #            'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
    #            'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
    #            'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat',
    #            'baseball glove', 'skateboard', 'surfboard', 'tennis racket',
    #            'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
    #            'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
    #            'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
    #            'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop',
    #            'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
    #            'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock',
    #            'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush')

    # try for pre-trained model
    CLASSES = ('person', 'car', 'motorcycle')
def coco_classes():
    # return [
    #     'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train',
    #     'truck', 'boat', 'traffic_light', 'fire_hydrant', 'stop_sign',
    #     'parking_meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep',
    #     'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella',
    #     'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard',
    #     'sports_ball', 'kite', 'baseball_bat', 'baseball_glove', 'skateboard',
    #     'surfboard', 'tennis_racket', 'bottle', 'wine_glass', 'cup', 'fork',
    #     'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange',
    #     'broccoli', 'carrot', 'hot_dog', 'pizza', 'donut', 'cake', 'chair',
    #     'couch', 'potted_plant', 'bed', 'dining_table', 'toilet', 'tv',
    #     'laptop', 'mouse', 'remote', 'keyboard', 'cell_phone', 'microwave',
    #     'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase',
    #     'scissors', 'teddy_bear', 'hair_drier', 'toothbrush'
    # ]

    # try for pre-trained model
    return [
        'person', 'car', 'motorcycle'
    ]
ModestYjx commented 2 years ago

In short: On the basis of LightViT, I use my 'human vehicle non' data set to reduce the number of categories and category names of the coco data set to its subset 'person', 'car', 'motor cycle'. This problem arises.

BIGWangYuDong commented 2 years ago

this error occurred here https://github.com/open-mmlab/mmdetection/blob/ca11860f4f3c3ca2ce8340e2686eeaec05b29111/tools/train.py#L201 please update your train.py file before running the code

BIGWangYuDong commented 2 years ago

If you still meet the same problem, please feel free to re-open this issue

ding19980201 commented 1 year ago

@BIGWangYuDong dear sir ,what does update your train.py mean i still can not fix even i add cfg.device='cuda'