czczup / ViT-Adapter

[ICLR 2023 Spotlight] Vision Transformer Adapter for Dense Predictions
https://arxiv.org/abs/2205.08534
Apache License 2.0
1.26k stars 139 forks source link

KeyError: 'BEiT is already registered in models' #63

Closed Nationarity closed 1 year ago

Nationarity commented 1 year ago

Hi, I would like to port the "MMsegmentation" video-demo.py to ViT-Adapter and run it, but it stops.

I already have cd segmentation/ ln -s . /detection/ops . / cd ops & sh make.sh has been done. test.py was also processed with no problems. If you have a moment, I would be happy to point this out to you!

<>

from argparse import ArgumentParser

import mmcv

import mmcv_custom   # noqa: F401,F403
import mmseg_custom   # noqa: F401,F403
from mmseg.apis import inference_segmentor, init_segmentor, show_result_pyplot
from mmseg.core.evaluation import get_palette
from mmcv.runner import load_checkpoint
from mmseg.core import get_classes
import cv2
import os.path as osp

def main():
    parser = ArgumentParser()
    parser.add_argument('video', help='Video file or webcam id')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--palette',
        default='cityscapes
...
(mmseg) n@Ubuntu-D2:~/ViT-Adapter/segmentation/demo$ python video_demo.py demo.mp4 configs/ade20k/mask2former_beitv2_adapter_large_896_80k_ade20k_ms.py checkpoints/mask2former_beitv2_adapter_large_896_80k_ade20k.pth --device cuda:0 --palette ade20k --show --output-file demo/demo-R.mp4 WARNING: CPU random generator seem to be failing, disabling hardware random number generation WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff /home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/__init__.py:20: UserWarning: On January 1, 2023, MMCV will release v2.0.0, in which it will remove components related to the training process and add a data transformation module. In addition, it will rename the package names mmcv to mmcv-lite and mmcv-full to mmcv. See https://github.com/open-mmlab/mmcv/blob/master/docs/en/compatibility.md for more details. warnings.warn( Traceback (most recent call last): File "video_demo.py", line 7, in import mmseg_custom # noqa: F401,F403 File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/__init__.py", line 3, in from .models import * # noqa: F401,F403 File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/models/__init__.py", line 2, in from .backbones import * # noqa: F401,F403 File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/models/backbones/__init__.py", line 2, in from .beit_adapter import BEiTAdapter File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/models/backbones/beit_adapter.py", line 14, in from .base.beit import BEiT File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/models/backbones/base/beit.py", line 294, in class BEiT(nn.Module): File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/utils/registry.py", line 337, in _register self._register_module(module=module, module_name=name, force=force) File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/utils/misc.py", line 340, in new_func output = old_func(*args, **kwargs) File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/utils/registry.py", line 272, in _register_module raise KeyError(f'{name} is already registered ' KeyError: 'BEiT is already registered in models'
czczup commented 1 year ago

Hi, may I ask what's your version of mmsegmentation?

In this repository, we use mmsegmentation==0.20.2. If you use a newer version of mmsegmentation, it will cause this error KeyError: 'BEiT is already registered in models, which is because BEiT is already included in official mmsegmentation.

One possible solution is to set force=True in @BACKBONES.register_module(force=True), in this code.

The above is my guess on the possible cause of this error and may require more information from you.

Nationarity commented 1 year ago

I deeply appreciate your prompt response! MMseg is the latest v0.29.1. I did "beit.py line 293 @BACKBONES.register_module(force=True)" as you suggested. but unfortunately it did not work.

(mmseg) n@Ubuntu-D2:~/ViT-Adapter/detection/ops$ python video_demo.py demo/demo.mp4 configs/ade20k/mask2former_beitv2_adapter_large_896_80k_ade20k_ms.py checkpoints/mask2former_beitv2_adapter_large_896_80k_ade20k.pth --device cuda:0 --palette ade20k --show --output-file demo/demo-R.mp4 WARNING: CPU random generator seem to be failing, disabling hardware random number generation WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff /home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/__init__.py:20: UserWarning: On January 1, 2023, MMCV will release v2.0.0, in which it will remove components related to the training process and add a data transformation module. In addition, it will rename the package names mmcv to mmcv-lite and mmcv-full to mmcv. See https://github.com/open-mmlab/mmcv/blob/master/docs/en/compatibility.md for more details. warnings.warn( Traceback (most recent call last): File "video_demo.py", line 117, in <module> main() File "video_demo.py", line 60, in main model = init_segmentor(args.config, args.checkpoint, device=args.device) File "/home/n/SegNeXt-main/mmseg/apis/inference.py", line 26, in init_segmentor config = mmcv.Config.fromfile(config) File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/utils/config.py", line 340, in fromfile cfg_dict, cfg_text = Config._file2dict(filename, File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/utils/config.py", line 183, in _file2dict check_file_exist(filename) File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/utils/path.py", line 23, in check_file_exist raise FileNotFoundError(msg_tmpl.format(filename)) FileNotFoundError: file "/home/n/ViT-Adapter/detection/ops/configs/ade20k/mask2former_beitv2_adapter_large_896_80k_ade20k_ms.py" does not exist

I have made further adjustments such as creating checkpoints and config in ops. It still seems to be an obstacle.

(mmseg) n@Ubuntu-D2:~/ViT-Adapter/segmentation/ops$ python demo/video_demo.py demo/demo.mp4 configs/ade20k/mask2former_beitv2_adapter_large_896_80k_ade20k_ms.py checkpoints/mask2former_beitv2_adapter_large_896_80k_ade20k.pth --device cuda:0 --palette ade20k --show --output-file demo/demo-R.mp4 WARNING: CPU random generator seem to be failing, disabling hardware random number generation WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff /home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmcv/__init__.py:20: UserWarning: On January 1, 2023, MMCV will release v2.0.0, in which it will remove components related to the training process and add a data transformation module. In addition, it will rename the package names mmcv to mmcv-lite and mmcv-full to mmcv. See https://github.com/open-mmlab/mmcv/blob/master/docs/en/compatibility.md for more details. warnings.warn( Traceback (most recent call last): File "demo/video_demo.py", line 7, in <module> import mmseg_custom # noqa: F401,F403 File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/__init__.py", line 1, in <module> from .core import * # noqa: F401,F403 File "/home/n/miniconda3/envs/mmseg/lib/python3.8/site-packages/mmseg_custom/core/__init__.py", line 2, in <module> from mmseg.core.evaluation import * # noqa: F401, F403 ModuleNotFoundError: No module named 'mmseg'

I would like to discuss a better solution. Thank you in advance.

czczup commented 1 year ago

I recommend you downgrade the mmsegmentation version to 0.20.2 or 0.21.0. I just added a video_demo.py for generating video demos. You can use it like this:

python video_demo.py demo.mp4 configs/ade20k/mask2former_beitv2_adapter_large_896_80k_ade20k_ss.py work_dirs/mask2former_beitv2_adapter_large_896_80k_ade20k_ss/mask2former_beitv2_adapter_large_896_80k_ade20k.pth --palette ade20k --output-file results.mp4

https://user-images.githubusercontent.com/23737120/208139858-cbafd719-aab3-43f3-bb10-37e104c90771.mp4

Nationarity commented 1 year ago

I was able to get it to work! Thank you very much. Looks like a 1080ti is not powerful enough.

Shaiken commented 1 year ago

補充: 若是引用Nvidia Container Pytorch 安裝也是都要先下載特定版本 https://github.com/open-mmlab/mmcv/tree/v1.5.0, 下載zip file https://github.com/open-mmlab/mmdetection/tree/v2.22.0, 下載zip file https://github.com/open-mmlab/mmsegmentation/tree/v0.20.2, 下載zip file

另外檢查哪種cuda適用mmcv版本

https://mmcv.readthedocs.io/en/latest/get_started/installation.html