mmpose icon indicating copy to clipboard operation
mmpose copied to clipboard

Accessing Torch Model

Open parthnatekar opened this issue 2 years ago • 4 comments

Hi,

How do I access the base torch model when using the high-level APIs

pose_model = init_pose_model(pose_config, pose_checkpoint)

pose_model is not an instance of torch.nn.Module, is there any way to get this?

Edit: I see that pose_model is indeed an instance of torch.nn.Module. Is there an easy way to get the model summary? I want to check the layer output shapes of the model, but when I try to use torchsummary with an input shape I get TypeError: forward() missing 1 required positional argument: 'img_metas' which I assume is because the forward pass takes some additional metadata.

parthnatekar avatar Jul 06 '22 23:07 parthnatekar

You can use the pose_model.forward_dummy instead of pose_model.forward to perform a simple network forward without the need for extra metadata.

ly015 avatar Jul 07 '22 01:07 ly015

Hi,

Where exactly is model.forward_dummy defined? Does it return the output of each module as an iterator?

I can see that it returns a tuple of tensors, but I'm not sure what these are.

parthnatekar avatar Jul 07 '22 18:07 parthnatekar

Just to clarify, I'm using mmdet for bounding box prediction and then feeding that to a pose model.

When I run forward_dummy on the mmdet model I get an output of shape ((B, N, 2), (B, N, 4)), where B is the batch size. I'm assuming N is the number of object proposals.

However when I run inference_detector(pose_model, image_frame) I get an output of shape ((B, 2), (B, 4)).

I want to access the top 'k' predicted bounding boxes for each image - how can I get these?

parthnatekar avatar Jul 07 '22 20:07 parthnatekar

Sorry for the late reply. forward_dummy simply performs network forward while inference_detector performs the whole inference pipeline including model forward and post-processings, and that is why they give different outputs. An example of forward_dummy in mmpose can be found here. If you are using mmdet models, you can also consider raising an issue in mmdet for expert feedback.

ly015 avatar Sep 06 '22 19:09 ly015