How to use ViTPose model in mmpose? #2591
-
I saw the previous question for using vitpose, but I didn't understand how to follow the installation guide. The Vitpose config file root is The model setting like this
type='mmpretrain.VisionTransformer' This is the part of error messages. KeyError: 'mmpretrain.VisionTransformer is not in the model registry. Please check whether the value of During handling of the above exception, another exception occurred: KeyError: "class |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Please refer to https://github.com/open-mmlab/mmpose/blob/main/configs/body_2d_keypoint/topdown_heatmap/coco/vitpose_coco.md to install mmpretrain |
Beta Was this translation helpful? Give feedback.
-
I have been stuck for week procrastinating on this and it is really frustrating to find no solution. I am trying to load the pose estimation model in mmpose and trying to perform inference on it without using the torchserve container found in your repo and I ran into some problems. I extracted the .mar model file and got a weights file (best_AP_epoch_72.pth) and a config for the model. channel_cfg = dict(
num_output_channels=17,
dataset_joints=17,
dataset_channel=[[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
]],
inference_channel=[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
])
model = dict(
type='TopDown',
pretrained='torchvision://resnet50',
backbone=dict(type='ResNet', depth=50),
keypoint_head=dict(
type='TopdownHeatmapSimpleHead',
in_channels=2048,
out_channels=17,
loss_keypoint=dict(type='JointsMSELoss', use_target_weight=True)),
train_cfg=dict(),
test_cfg=dict(
flip_test=True,
post_process='default',
shift_heatmap=True,
modulate_kernel=11)) When I load this into mmpose for inference I get the following error:
The Code I am Using is this:import time
import torch
from mmpose.apis import init_model, inference_topdown, MMPoseInferencer, Pose2DInferencer
from mmpose.registry import VISUALIZERS
from mmpose.structures import merge_data_samples
from mmdet.apis import inference_detector, init_detector
model = init_model(CONFIG_PATH, WEIGHTS_PATH) Secondly I tried This:Since, I had the weights I decided to code the model out in pytorch but its complete architecture was unknown to me especially the TopdownHeatmapSimpleHead but while doing so I wrote this code: # Example instantiation of the model with the data configuration parameters
model = KeypointModel(
image_size=(192, 256), # From data_cfg
heatmap_size=(48, 64), # From data_cfg
num_keypoints=17, # From data_cfg
pretrained=True
)
# Path to the weights file
weights_path = 'D:/fyp-codebase/mmpose/weights/best_AP_epoch_72.pth'
# Load the state dictionary from the file
state_dict = torch.load(weights_path, map_location=torch.device('cpu'))
# Load the weights into the model
model.load_state_dict(state_dict)
# Set the model to evaluation mode (if you're using it for inference)
model.eval()
print("Weights loaded successfully!") And I encountered this error:
Thank you, |
Beta Was this translation helpful? Give feedback.
Please refer to https://github.com/open-mmlab/mmpose/blob/main/configs/body_2d_keypoint/topdown_heatmap/coco/vitpose_coco.md to install mmpretrain