pytorch-openpose icon indicating copy to clipboard operation
pytorch-openpose copied to clipboard

run error for body.py

Open kekedan opened this issue 6 years ago • 11 comments

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!

kekedan avatar Jan 07 '19 09:01 kekedan

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.

Hzzone avatar Jan 17 '19 13:01 Hzzone

I added this but nothing changed. Still getting same error

ehartz01 avatar Jan 22 '19 18:01 ehartz01

@ehartz01 plz give me a test image.

Hzzone avatar Jan 24 '19 08:01 Hzzone

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

ehartz01 avatar Jan 24 '19 15:01 ehartz01

@ehartz01 plz use python 3+.

Hzzone avatar Jan 24 '19 15:01 Hzzone

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?

ehartz01 avatar Jan 24 '19 17:01 ehartz01

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

Hzzone avatar Jan 25 '19 08:01 Hzzone

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!

seojpark91 avatar Apr 18 '20 23:04 seojpark91

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

lxy1993 avatar Apr 28 '20 06:04 lxy1993

same error

GuaiYiHu avatar Jul 08 '20 02:07 GuaiYiHu

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

init-22 avatar Sep 08 '20 05:09 init-22