muelea / selfcontact

CVPR 2021 - Official code repository for the paper: On Self-Contact and Human Pose.
https://tuch.is.tue.mpg.de
Other
86 stars 6 forks source link

SelfContact - tensor issue (running on GPU) #5

Closed GuyTevet closed 3 years ago

GuyTevet commented 3 years ago

Hi Lea!

Running:

self_contact_module = SelfContact(essentials_folder=essentials)
self_contact_loss = SelfContactLoss(self_contact_module, device='cuda')
self_contact_loss(vertices.to(self_contact_loss.device))

Fails with:

Traceback (most recent call last):
  File "/disk2/guytevet/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/disk2/guytevet/venvs/py3.7_vibe/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/disk2/guytevet/selfcontact/selfcontact/losses/general_selfcontact_loss.py", line 80, in forward
    test_segments=self.test_segments
  File "/disk2/guytevet/selfcontact/selfcontact/selfcontact.py", line 214, in segment_vertices
    vertices, v2v_min, incontact, exterior, test_segments)
  File "/disk2/guytevet/selfcontact/selfcontact/selfcontact.py", line 242, in segment_hd_points
    nzv = (exp1 == exp2).any(1).reshape(-1, 3).any(1)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

From my understanding, this happens since the essentials are not loaded to self_contact_loss.device.

Many Thanks,

muelea commented 3 years ago

Thanks for the pointer. You must still transfer the loss to your GPU via .to(device):

self_contact_module = SelfContact(essentials_folder=essentials)
self_contact_loss = SelfContactLoss(self_contact_module, use_hd=False, align_faces=False).to('cuda')
self_contact_loss(vertices.to(self_contact_loss.device))
GuyTevet commented 3 years ago

It works! many thanks:) btw, is it possible to run with use_hd=True (currently fails with the error below)

Traceback (most recent call last):
  File "/disk2/guytevet/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/disk2/guytevet/venvs/py3.7_vibe/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/disk2/guytevet/selfcontact/selfcontact/losses/general_selfcontact_loss.py", line 80, in forward
    test_segments=self.test_segments
  File "/disk2/guytevet/selfcontact/selfcontact/selfcontact.py", line 214, in segment_vertices
    vertices, v2v_min, incontact, exterior, test_segments)
  File "/disk2/guytevet/selfcontact/selfcontact/selfcontact.py", line 244, in segment_hd_points
    hd_verts_ioc_idx = (self.geovec.unsqueeze(-1) == \
  File "/disk2/guytevet/venvs/py3.7_vibe/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1131, in __getattr__
    type(self).__name__, name))
AttributeError: 'SelfContact' object has no attribute 'geovec'
muelea commented 3 years ago

If you want to use hd, you also need to initialise the self-contact module with hd. You can do that by running: self_contact_module = SelfContact(essentials_folder=essentials, compute_hd=True)

GuyTevet commented 3 years ago

Thanks! closing.