Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_flops.py #168

Open
Minsu-Kim1822 opened this issue Mar 24, 2024 · 11 comments
Open

get_flops.py #168

Minsu-Kim1822 opened this issue Mar 24, 2024 · 11 comments

Comments

@Minsu-Kim1822
Copy link

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?

@duanduanduanyuchen
Copy link
Collaborator

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.

@Minsu-Kim1822
Copy link
Author

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

@duanduanduanyuchen
Copy link
Collaborator

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.

@Minsu-Kim1822
Copy link
Author

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

@duanduanduanyuchen
Copy link
Collaborator

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

@Minsu-Kim1822
Copy link
Author

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

@duanduanduanyuchen
Copy link
Collaborator

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.

@Minsu-Kim1822
Copy link
Author

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 :)

@duanduanduanyuchen
Copy link
Collaborator

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?

@Minsu-Kim1822
Copy link
Author

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!

@LQchen1
Copy link

LQchen1 commented Apr 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants