Hzzone / pytorch-openpose

pytorch implementation of openpose including Hand and Body Pose Estimation.
2.03k stars 390 forks source link

run error for body.py #1

Open kekedan opened 5 years ago

kekedan commented 5 years ago

hi, when run the body.py ,meet follow error body.py:121: RuntimeWarning: invalid value encountered in true_divide vec = np.divide(vec, norm) Traceback (most recent call last): File "body.py", line 217, in candidate, subset = body_estimation(oriImg) File "body.py", line 134, in call 0.5 * oriImg.shape[0] / norm - 1, 0) ZeroDivisionError: float division by zero I use python3.6 ,pytorch 0.4 .

also when i use pyton2.7 pytorch 0.40 Traceback (most recent call last): File "body.py", line 218, in candidate, subset = body_estimation(oriImg) File "body.py", line 49, in call Mconv7_stage6_L1, Mconv7_stage6_L2 = self.model(data) File "/root/anaconda3/envs/caffe/lib/python2.7/site-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, kwargs) File "/root/dance/AIdance/pytorch-openpose/python/model.py", line 591, in forward out1 = self.model0(x) File "/root/anaconda3/envs/caffe/lib/python2.7/site-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, *kwargs) File "/root/anaconda3/envs/caffe/lib/python2.7/site-packages/torch/nn/modules/container.py", line 91, in forward input = module(input) File "/root/anaconda3/envs/caffe/lib/python2.7/site-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(input, kwargs) File "/root/anaconda3/envs/caffe/lib/python2.7/site-packages/torch/nn/modules/conv.py", line 301, in forward self.padding, self.dilation, self.groups) RuntimeError: Given groups=1, weight[256, 512, 3, 3], so expected input[1, 3, 46, 50] to have 512 channels, but got 3 channels instead

do you have any advice , thanks!

Hzzone commented 5 years ago

Try below in body.py:

vec = np.subtract(candB[j][:2], candA[i][:2])
norm = math.sqrt(vec[0] * vec[0] + vec[1] * vec[1])

#to solve the DIVISION BY ZERO, I did this trick, but not sure if is correct
if norm == 0:
    norm = 0.1

vec = np.divide(vec, norm)

or add the search scale:

# scale_search = [0.5, 1.0, 1.5, 2.0]
scale_search = [0.5]

Anybody should run demo.py successfully using the demo.jpg.

ehartz01 commented 5 years ago

I added this but nothing changed. Still getting same error

Hzzone commented 5 years ago

@ehartz01 plz give me a test image.

ehartz01 commented 5 years ago

Thanks for your reply @Hzzone Below is the output to terminal:

ny idea what's happening?

SED-ML-0148% python demo1.py Traceback (most recent call last): File "demo1.py", line 17, in candidate, subset = body_estimation(oriImg) File "python/body.py", line 46, in call Mconv7_stage6_L1, Mconv7_stage6_L2 = self.model(data) File "/Users/ehartz01/Desktop/SignPhonologizer/nicey/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, kwargs) File "python/model.py", line 108, in forward out1 = self.model0(x) File "/Users/ehartz01/Desktop/SignPhonologizer/nicey/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, *kwargs) File "/Users/ehartz01/Desktop/SignPhonologizer/nicey/lib/python2.7/site-packages/torch/nn/modules/container.py", line 92, in forward input = module(input) File "/Users/ehartz01/Desktop/SignPhonologizer/nicey/lib/python2.7/site-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(input, kwargs) File "/Users/ehartz01/Desktop/SignPhonologizer/nicey/lib/python2.7/site-packages/torch/nn/modules/conv.py", line 320, in forward self.padding, self.dilation, self.groups) RuntimeError: Given groups=1, weight of size [256, 512, 3, 3], expected input[1, 3, 46, 32] to have 512 channels, but got 3 channels instead

Hzzone commented 5 years ago

@ehartz01 plz use python 3+.

ehartz01 commented 5 years ago

Thank you! This fixed the error. From the demo.py file I'm able to get the hand keypoints, but I'm struggling to understand where to get the body keypoints from -- can you help me out?

Hzzone commented 5 years ago

@ehartz01

Read the code and comments of body.py:

# subset: n*20 array, 0-17 is the index in candidate, 18 is the total score, 19 is the total parts
# candidate: x, y, score, id
return candidate, subset

There are all body keypoints in candidate while subset indicates which part the single keypoint is. You may have a look at body.py and try to run it by yourself.

seojpark91 commented 4 years ago

Hi @Hzzone! Thanks for easy to install openpose pytorch model. Regarding this issue, I also have ZeroDivisionError when I run with demo.py with ski.jpg and some other images that I tested with.

body.py:122: RuntimeWarning: invalid value encountered in true_divide vec = np.divide(vec, norm) Traceback (most recent call last): File "body.py", line 217, in <module> candidate, subset = body_estimation(oriImg) File "body.py", line 134, in __call__ 0.5 * oriImg.shape[0] / norm - 1, 0) ZeroDivisionError: float division by zero

Though, uncommenting scale_search = [0.5, 1.0, 1.5, 2.0] seems to work. Would you consider fixing this part?

Thank you!

lxy1993 commented 4 years ago

1588054908(1) hi, when running the body.py, meet follow error File "body.py", line 134, in call 0.5 * oriImg.shape[0] / norm - 1, 0) ZeroDivisionError: float division by zero

to slove the error ,i adopted your advice vec = np.subtract(candB[j][:2], candA[i][:2]) norm = math.sqrt(vec[0] vec[0] + vec[1] vec[1]) if norm == 0: norm = 0.1 vec = np.divide(vec, norm) but the output canvas image is diffrent from your project's .why?Apart from the above changes, I have never modified the code again 微信截图_20200428142011

GuaiYiHu commented 4 years ago

same error

init-22 commented 3 years ago

@Hzzone I used this trick to add norm = 1.1 if norm ==0, and it worked