pytorch_Realtime_Multi-Person_Pose_Estimation
pytorch_Realtime_Multi-Person_Pose_Estimation copied to clipboard
error in get_outputs()
hi, @tensorboy ,when I run the web_demo, I met the following error:
"Bulding VGG19
Traceback (most recent call last):
File "web_demo.py", line 92, in
I met several errors when run "web_demo.py" too, and I change it as following, then I can run it now. Please make sure your weight file is in right path as line 53 shows.
import cv2
import argparse
import numpy as np
import torch
from lib.config import cfg, update_config
import time
from lib.network.rtpose_vgg import get_model
from evaluate.coco_eval import get_outputs
from lib.utils.common import CocoPart, CocoColors, CocoPairsRender
from lib.utils.paf_to_pose import paf_to_pose_cpp
parser = argparse.ArgumentParser()
parser.add_argument('--cfg', help='experiment configure file name',
default='./experiments/vgg19_368x368_sgd.yaml', type=str)
parser.add_argument('--weight', type=str,
default='./network/pose_model.pth')
parser.add_argument('opts',
help="Modify config options using the command-line",
default=None,
nargs=argparse.REMAINDER)
args = parser.parse_args()
# update config file
update_config(cfg, args)
def draw_humans(npimg, humans, imgcopy=False):
if imgcopy:
npimg = np.copy(npimg)
image_h, image_w = npimg.shape[:2]
centers = {}
for human in humans:
# draw point
for i in range(CocoPart.Background.value):
if i not in human.body_parts.keys():
continue
body_part = human.body_parts[i]
center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5))
centers[i] = center
cv2.circle(npimg, center, 3, CocoColors[i], thickness=3, lineType=8, shift=0)
# draw line
for pair_order, pair in enumerate(CocoPairsRender):
if pair[0] not in human.body_parts.keys() or pair[1] not in human.body_parts.keys():
continue
# npimg = cv2.line(npimg, centers[pair[0]], centers[pair[1]], common.CocoColors[pair_order], 3)
cv2.line(npimg, centers[pair[0]], centers[pair[1]], CocoColors[pair_order], 3)
return npimg
weight_name = './network/pose_model.pth'
model = get_model('vgg19')
model.load_state_dict(torch.load(weight_name))
model.cuda()
model.float()
model.eval()
if __name__ == "__main__":
video_capture = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, oriImg = video_capture.read()
tic = time.time()
shape_dst = np.min(oriImg.shape[0:2])
# Get results of original image
# multiplier = get_multiplier(oriImg)
with torch.no_grad():
paf, heatmap, im_scale = get_outputs(oriImg, model, 'rtpose')
humans = paf_to_pose_cpp(heatmap, paf, cfg)
out = draw_humans(oriImg, humans)
# Display the resulting frame
cv2.imshow('Video', out)
print('time: ', time.time() - tic)
if cv2.waitKey(1) & 0xFF == 27:
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
Hope it can help you!
@zoezhu really thankful to you! but when I run your code, the video can be played successfully, but it can't find the keypoints in the person, and it has the following errors:
Traceback (most recent call last):
File "web_demo.py", line 71, in <module>
shape_dst = np.min(oriImg.shape[0:2])
AttributeError: 'NoneType' object has no attribute 'shape'
when I remove the code of this line, it still dosen't work and has error
Traceback (most recent call last):
File "web_demo.py", line 77, in <module>
paf, heatmap, im_scale = get_outputs(oriImg, model, 'rtpose')
File "/home/guanziyi/tensorboy_pytorch_Realtime_Multi-Person_Pose_Estimation-master/evaluate/coco_eval.py", line 97, in get_outputs
img, inp_size, factor=cfg.MODEL.DOWNSAMPLE, is_ceil=True)
File "/home/guanziyi/tensorboy_pytorch_Realtime_Multi-Person_Pose_Estimation-master/lib/network/im_transform.py", line 120, in crop_with_factor
im_shape = im.shape
AttributeError: 'NoneType' object has no attribute 'shape'
so what's the problem of those errors? Was there a problem with the model I had trained?
@zoezhu Thank you very much for your help. Now I can run demo reasonably. Thank you very much!@EasonGZY I think this problem is all because of cv2 haven't contected the camera. ret, oriImg = video_capture.read() You can check the values of the two variables ,I guass the ret's value may is "False", and orilmg is none, so that means you video_capture can't read anything. video_capture = cv2.VideoCapture(0) So, you should find the correct id of the video connected , it's may not "0" all the time . Good Luck !