xingyizhou / pytorch-pose-hg-3d

PyTorch implementation for 3D human pose estimation
GNU General Public License v3.0
613 stars 143 forks source link

RuntimeError: The size of tensor a (27) must match the size of tensor b (26) at non-singleton dimension 3 #14

Closed xyz2357 closed 6 years ago

xyz2357 commented 6 years ago

I put the pretrained model and a test picture in /src/, and run python demo.py -demo test_1.png The std error is

/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/matplotlib/init.py:962: UserWarning: Duplicate key in file "/home/ubuntu/.config/matplotlib/matplotlibrc", line #2 (fname, cnt)) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/matplotlib/init.py:962: UserWarning: Duplicate key in file "/home/ubuntu/.config/matplotlib/matplotlibrc", line #3 (fname, cnt)) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.activation.ReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.MaxPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.upsampling.Upsample' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py:325: SourceChangeWarning: source code of class 'torch.nn.modules.linear.Linear' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File "demo.py", line 31, in main() File "demo.py", line 20, in main output = model(input_var) File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(*input, kwargs) File "/home/ubuntu/pytorch-pose-hg-3d/src/models/hg_3d.py", line 112, in forward hg = self.hourglassi File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(*input, *kwargs) File "/home/ubuntu/pytorch-pose-hg-3d/src/models/hg_3d.py", line 46, in forward low2 = self.low2(low1) File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(input, kwargs) File "/home/ubuntu/pytorch-pose-hg-3d/src/models/hg_3d.py", line 46, in forward low2 = self.low2(low1) File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(*input, *kwargs) File "/home/ubuntu/pytorch-pose-hg-3d/src/models/hg_3d.py", line 46, in forward low2 = self.low2(low1) File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(input, **kwargs) File "/home/ubuntu/pytorch-pose-hg-3d/src/models/hg_3d.py", line 57, in forward return up1 + up2 RuntimeError: The size of tensor a (27) must match the size of tensor b (26) at non-singleton dimension 3

xingyizhou commented 6 years ago

Oh, I haven't added the resize to 256x256 code in demo.py. You can do it yourself when testing your own image. Sorry for that.

xyz2357 commented 6 years ago

Thanks, it solved. BTW, anyway to output the 3D points into files?

xingyizhou commented 6 years ago

print pred and copy it to a file.

xyz2357 commented 6 years ago

pred seems to be a 2d result.

Is that a good idea to uncomment #print 'show3D', c, points in debugger.py, line 12? https://github.com/xingyizhou/pytorch-pose-hg-3d/blob/84ad44e7a8aa15307b9a371ce85b3dee8d5ad2dc/src/utils/debugger.py#L12 Are those the predicted 3d positions of all the key points?

xingyizhou commented 6 years ago

Oh, yes you can. Or just simply print np.concatenate([pred, (reg + 1) / 2. * 256].

xyz2357 commented 6 years ago

OK, thanks!

xyz2357 commented 6 years ago

Sorry, one more thing: I've got the plot result of the reshaped graph. So how can I convert the plot back, so that I can get the plots of the origin picture? Say, I can convert x back by new_x_val = x_val * origin_x_size / 256; similar to y; but how can I convert z-axis back?

xingyizhou commented 6 years ago

There is no absolute z, you can use (reg + 1) / 2. * 256 to convert z with the same aspect ratio as xy in the image coordinate system (with weak-perspective camera model). A very detailed explanation of why/how to use the coordinate system calibration can be found in Section 3.2 of https://arxiv.org/pdf/1803.09331.pdf .

xyz2357 commented 6 years ago

OK, thanks!