mmdetection icon indicating copy to clipboard operation
mmdetection copied to clipboard

TypeError: forward() missing 1 required positional argument: 'img_metas'

Open wxmchgithub opened this issue 11 months ago • 8 comments

I am using mmdetection version 2.28.2. I am currently using the Mask2Former model. When I use the trained model to calculate flops, params (using the thop library), or visualize using gradcam, I get an error. image image I don't know why this error occurs. I also get this error when using tools/get_flops.py. I hope an expert can answer this question.

wxmchgithub avatar Mar 10 '24 10:03 wxmchgithub

I have the same issue. I want to calculate FLOPs for model.

King4819 avatar Mar 12 '24 10:03 King4819

I have the same issue.

AZong76 avatar May 08 '24 12:05 AZong76

I have the same issue,I want to count FLOPs with my own models.

AGreenApple2002 avatar May 16 '24 12:05 AGreenApple2002

I have the same issue,I want to count FLOPs with my own models.

I found that the reason may be that the parameter img_metas is required for forward inference of the model. There are examples of preparing img_metas in mmdet/apis/inference.py in mmdetection framework. It can be analogous to preparing forward inference data according to data preparation in inference.py. image my mmdet version is 2.28.2

wxmchgithub avatar May 17 '24 07:05 wxmchgithub

@wxmchgithub suppose I want to inference an image, how do I prepare data[img_metas] ? Thanks!!!

King4819 avatar May 17 '24 08:05 King4819

suppose I want to inference an image, how do I prepare data[img_metas] ? Thanks!!!

If you only want to perform inference on the image, you don't need to prepare img_metas yourself. demo/image_demo.py demonstrates how to perform inference on images.

wxmchgithub avatar May 17 '24 09:05 wxmchgithub

@wxmchgithub I want to inference an image then calculate the FLOPs of model based on it.

King4819 avatar May 17 '24 09:05 King4819

@wxmchgithub I want to inference an image then calculate the FLOPs of model based on it.

@wxmchgithub I want to inference an image then calculate the FLOPs of model based on it.

You can refer to inference_detector under inference.py. It contains the preparation of img_metas.

wxmchgithub avatar May 17 '24 09:05 wxmchgithub