ViT-Adapter icon indicating copy to clipboard operation
ViT-Adapter copied to clipboard

get_flops.py

Open Minsu-Kim1822 opened this issue 11 months ago • 11 comments

Hi, I'm trying to use get_flops to get params and flops(MACs * 2).

But, when I ran it with just default setup like only

python get_flops.py

. Traceback (most recent call last): File "get_flops.py", line 11, in import mmdet_custom # noqa: F401,F403 ModuleNotFoundError: No module named 'mmdet_custom'

error is occured like above.

I followed all the instructions in segmentation folder, and image_demo.py works well. what is the problem?

Minsu-Kim1822 avatar Mar 24 '24 05:03 Minsu-Kim1822

Hi, I'm trying to use get_flops to get params and flops(MACs * 2).

But, when I ran it with just default setup like only

python get_flops.py

. Traceback (most recent call last): File "get_flops.py", line 11, in import mmdet_custom # noqa: F401,F403 ModuleNotFoundError: No module named 'mmdet_custom'

error is occured like above.

I followed all the instructions in segmentation folder, and image_demo.py works well. what is the problem?

Hi, you can try this command before running the python script: export PYTHONPATH=/path/to/ViT-Adapter/detection Replace the /path/to/ViT-Adapter/detection with the path to the detection folder.

duanduanduanyuchen avatar Mar 24 '24 05:03 duanduanduanyuchen

Hi, I'm trying to use get_flops to get params and flops(MACs * 2). But, when I ran it with just default setup like only python get_flops.py . Traceback (most recent call last): File "get_flops.py", line 11, in import mmdet_custom # noqa: F401,F403 ModuleNotFoundError: No module named 'mmdet_custom' error is occured like above. I followed all the instructions in segmentation folder, and image_demo.py works well. what is the problem?

Hi, you can try this command before running the python script: export PYTHONPATH=/path/to/ViT-Adapter/detection Replace the /path/to/ViT-Adapter/detection with the path to the detection folder.

Hey, I try this but

raise KeyError(f'{name} is already registered '

KeyError: 'SinePositionalEncoding is already registered in position encoding'

error like this

Minsu-Kim1822 avatar Mar 24 '24 05:03 Minsu-Kim1822

Sorry, there seems a bug in the get_flops.py in the segmentation folder. You can replace import mmdet_custom with import mmseg_custom, and add the path to the segmentation folder to PYTHONPATH.

duanduanduanyuchen avatar Mar 24 '24 05:03 duanduanduanyuchen

Sorry, there seems a bug in the get_flops.py in the segmentation folder. You can replace import mmdet_custom with import mmseg_custom, and add the path to the segmentation folder to PYTHONPATH.

Thanks.

Btw, could you give me a example code to run get_flops?

I'm using

mask2former_beit_adapter_large_896_80k_mapillary.pth.tar with 360 x 480 img.

Looks quite different from using image_demo.py

Minsu-Kim1822 avatar Mar 24 '24 05:03 Minsu-Kim1822

I think maybe you can try a command like this: python tools/get_flops.py configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py --shape 360 480

duanduanduanyuchen avatar Mar 24 '24 05:03 duanduanduanyuchen

I think maybe you can try a command like this: python tools/get_flops.py configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py --shape 360 480

python get_flops.py mask2former_beit_adapter_large_896_80k_mapillary.pth.tar --shape 360 480 Traceback (most recent call last): File "get_flops.py", line 94, in cfg = Config.fromfile(args.config) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/config.py", line 334, in fromfile cfg_dict, cfg_text = Config._file2dict(filename, File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/config.py", line 184, in _file2dict raise IOError('Only py/yml/yaml/json type are supported now!') OSError: Only py/yml/yaml/json type are supported now!

I changed ur suggestion little bit cuz previous error is ----ss.py is not a check point. so I replaced it as a .pth.tar.

but error like this

Minsu-Kim1822 avatar Mar 24 '24 06:03 Minsu-Kim1822

The "not a check point" error is caused by the pre-trained checkpoint, not by ".py". When counting flops or parameters, you don't really need a checkpoint file or pretrained file. So you can change pretrained = 'pretrained/beit_large_patch16_224_pt22k_ft22k.pth' in configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py to pretrained = None and run python tools/get_flops.py configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py --shape 360 480 again.

duanduanduanyuchen avatar Mar 24 '24 06:03 duanduanduanyuchen

The "not a check point" error is caused by the pre-trained checkpoint, not by ".py". When counting flops or parameters, you don't really need a checkpoint file or pretrained file. So you can change pretrained = 'pretrained/beit_large_patch16_224_pt22k_ft22k.pth' in configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py to pretrained = None and run python tools/get_flops.py configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py --shape 360 480 again.

Traceback (most recent call last): File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(**args) File "/home/iasl/ViT-Adapter/segmentation/mmseg_custom/models/backbones/beit_adapter.py", line 26, in init super().init(init_values=init_values, with_cp=with_cp, *args, **kwargs) File "/home/iasl/ViT-Adapter/segmentation/mmseg_custom/models/backbones/base/beit.py", line 344, in init self.init_weights(pretrained) File "/home/iasl/ViT-Adapter/segmentation/mmseg_custom/models/backbones/base/beit.py", line 358, in init_weights load_checkpoint(self, pretrained, strict=False, logger=logger) File "/home/iasl/ViT-Adapter/segmentation/mmcv_custom/checkpoint.py", line 338, in load_checkpoint checkpoint = _load_checkpoint(filename, map_location) File "/home/iasl/ViT-Adapter/segmentation/mmcv_custom/checkpoint.py", line 286, in _load_checkpoint raise IOError(f'{filename} is not a checkpoint file') OSError: pretrained/beit_large_patch16_224_pt22k_ft22k.pth is not a checkpoint file

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(**args) File "/home/iasl/ViT-Adapter/segmentation/mmseg_custom/models/segmentors/encoder_decoder_mask2former.py", line 34, in init self.backbone = builder.build_backbone(backbone) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmseg/models/builder.py", line 20, in build_backbone return BACKBONES.build(cfg) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/registry.py", line 212, in build return self.build_func(*args, **kwargs, registry=self) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') OSError: BEiTAdapter: pretrained/beit_large_patch16_224_pt22k_ft22k.pth is not a checkpoint file

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "get_flops.py", line 98, in model = build_segmentor( File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmseg/models/builder.py", line 48, in build_segmentor return SEGMENTORS.build( File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/registry.py", line 212, in build return self.build_func(*args, **kwargs, registry=self) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/home/iasl/ViT-Adapter/lib/python3.8/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') OSError: EncoderDecoderMask2Former: BEiTAdapter: pretrained/beit_large_patch16_224_pt22k_ft22k.pth is not a checkpoint file

Then, error like above, quite difficult to use it XD

anyway, thanks for your rapid reply :)

Minsu-Kim1822 avatar Mar 24 '24 06:03 Minsu-Kim1822

Have you changed the pretrained/beit_large_patch16_224_pt22k_ft22k.pth in configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py to None?

duanduanduanyuchen avatar Mar 24 '24 06:03 duanduanduanyuchen

Have you changed the pretrained/beit_large_patch16_224_pt22k_ft22k.pth in configs/cityscapes/mask2former_beit_adapter_large_896_80k_mapillary_ss.py to None?

Yeah, it doesn't work. idk what is the problem now, but I'll keep try it. Thanks for your help!

Minsu-Kim1822 avatar Mar 25 '24 00:03 Minsu-Kim1822

I had a similar problem, but I wrote a custom model as the author wrote it, and it was registered, but he still got an error: KeyError: "MaskRCNN: 'IMViTAdapter is not in the models registry'".Even if I use "python ViT-Adapter-main/detection/get_flops.py ViT-Adapter-main/detection/mmdet_custom/models/backbones/vit_adapter.py --shape 1024 1024", he will also report an error KeyError: "MaskRCNN: 'ViTBaseline is not in the models registry'"

image

LQchen1 avatar Apr 27 '24 12:04 LQchen1