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

Error Result when predicting my own image. #22

Open
zyoohv opened this issue Sep 13, 2018 · 1 comment
Open

Error Result when predicting my own image. #22

zyoohv opened this issue Sep 13, 2018 · 1 comment

Comments

@zyoohv
Copy link

zyoohv commented Sep 13, 2018

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>

output_4_2

@zyoohv zyoohv changed the title Error Result in predict my own image. Error Result when predicting my own image. Sep 13, 2018
@leoxiaobin
Copy link
Contributor

Please follow our validation code for prediction.

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

2 participants