question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to predict my own image?

See original GitHub issue

I read your code carefully, and implement with following code. But I still get the wrong result. Could you help me?

# config
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 torchvision.transforms as transforms
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
toTensor = transforms.Compose([transforms.ToTensor(), 
                               transforms.Normalize(mean, std)])

def getpoint(mat):
    height, width = mat.shape
    mat = mat.reshape(-1)
    idx = np.argmax(mat)
    return idx % width, idx // width
# load image and predict
import cv2
import numpy as np
img = cv2.imread('0.png', cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION)
img = cv2.resize(img, (256, 256))
x = toTensor(img).unsqueeze(0)
with torch.no_grad():
    res = model.forward(x)
res = np.array(res.detach().squeeze())
print(img.shape)
print(res.shape)
(256, 256, 3)
(16, 64, 64)
# plot
image = cv2.resize(img, (64, 64))
print(image.shape)
for mat in res:
    x, y = getpoint(mat)
    print(x, y)
    cv2.circle(image, (x, y), 2, (255, 0, 0), 2)
import matplotlib.pyplot as plt
plt.imshow(image)
(64, 64, 3)
10 46
8 37
27 29
13 37
33 7
30 7
25 18
17 31
31 22
29 21
15 32
12 51
23 15
36 18
13 40
12 41
<matplotlib.image.AxesImage at 0x7f14625c1160>

output_2_2

LoadNet.pdf

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:32 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
BadMachinecommented, Jan 10, 2020

Code for visualizing is available in my fork https://github.com/BadMachine/human-pose-estimation.pytorch

1reaction
jiaxue1993commented, Dec 18, 2018

@junjieAI I just filled up the missed part of Qichao, please read the whole discussion. Actually I find the result is not good. So I just followed the author’s implementation, use faster rCNN to detect person from images, then follow their validation code for testing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to predict an image using CNN with Keras?
Load an image. Resize it to a predefined size such as 224 x 224 pixels. Scale the value of the pixels to the...
Read more >
TensorFlow Tutorial 11 - Make Prediction on a Single Image
This is Tutorial 11 of our series of Tensor Flow Tutorials for Machine Learning and Data Science. Tutorial 1 - Setup of Tensorflow...
Read more >
Image Prediction - How to Use Your Own Datasets - AutoGluon
Image Prediction - How to Use Your Own Datasets¶ · Step 1: Organizing the dataset into proper directories¶ · Step 2: Split data...
Read more >
predicting my own image in cnn using keras - Stack Overflow
You should first read in your image by cv2 and resize it to (28,28). Finally add the batch dimension(0th dimension) and channel ...
Read more >
Image Prediction Using a Pre-trained Model - Analytics Vidhya
Therefore, it often makes sense to employ an existing neural network design as a starting point for your own projects rather than having...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found