pytorch_Realtime_Multi-Person_Pose_Estimation icon indicating copy to clipboard operation
pytorch_Realtime_Multi-Person_Pose_Estimation copied to clipboard

error in get_outputs()

Open EasonGZY opened this issue 5 years ago • 3 comments

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 multiplier, oriImg, model, 'rtpose') TypeError: get_outputs() takes 3 positional arguments but 4 were given" I checked the file "coco_eval.py", it actually has only 3 parameters, could you update your repo of web_demo.py or coco_eval.py to make them consistent? thanks! If anybody konws how to change the repo, please tell me and I will be very appreciated!

EasonGZY avatar Sep 08 '19 10:09 EasonGZY

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 avatar Sep 09 '19 05:09 zoezhu

@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?

EasonGZY avatar Sep 10 '19 03:09 EasonGZY

@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 !

jwdwzxd avatar Oct 28 '19 01:10 jwdwzxd