human-pose-estimation.pytorch
human-pose-estimation.pytorch copied to clipboard
Error Result when predicting my own image.
This is my code about using your model to predict pose of my image. Is there any wrong with it ? Can you provide me a right one ?
from lib.models.pose_resnet import get_pose_net
from lib.core.config import config
from lib.core.config import update_config
config.TEST.FLIP_TEST = True
config.TEST.MODEL_FILE = 'pose_resnet_50_256x256.pth.tar'
update_config('experiments/mpii/resnet50/256x256_d256x3_adam_lr1e-3.yaml')
model = get_pose_net(config, is_train=False)
import torch
import cv2
import numpy as np
img = cv2.imread('0.png')
img = cv2.resize(img, (256, 256))
img = np.transpose(img, (2, 0, 1)).astype(np.float32)
img = (img / 255 - 0.5) * 2
img = torch.tensor(img).unsqueeze(0)
with torch.no_grad():
res = model.forward(img)
print(img.shape)
print(res.shape)
torch.Size([1, 3, 256, 256])
torch.Size([1, 16, 64, 64])
def getpoint(mat):
height, width = mat.shape
mat = mat.reshape(-1)
idx = np.argmax(mat)
return idx // height, idx % width
raw = ((np.array(img.squeeze()) / 2 + 0.5) * 255).astype(np.uint8)
raw = cv2.resize(np.transpose(raw, (1, 2, 0)), (64, 64))
poi = np.array(res.detach().squeeze())
print(raw.shape)
print(poi.shape)
(64, 64, 3)
(16, 64, 64)
image = raw
for mat in poi:
x, y = getpoint(mat)
print(x, y)
cv2.circle(image, (x, y), 1, (255, 0, 0))
import matplotlib.pyplot as plt
plt.imshow(image)
19 30
12 37
22 28
13 37
18 30
13 36
7 32
8 31
18 28
8 34
12 36
7 22
12 38
11 40
18 27
15 30
<matplotlib.image.AxesImage at 0x7fa42088ab00>

Please follow our validation code for prediction.