mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-25 08:40:35 +08:00
detach for meshes, pointclouds, textures
Summary: Add `detach` for Meshes, Pointclouds, Textures Reviewed By: nikhilaravi Differential Revision: D23070418 fbshipit-source-id: 68671124ce114c4495d7ef3c944c9aac3d0db2d8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5852b74d12
commit
7f2f95f225
@@ -1138,6 +1138,28 @@ class Meshes(object):
|
||||
other.textures = self.textures.clone()
|
||||
return other
|
||||
|
||||
def detach(self):
|
||||
"""
|
||||
Detach Meshes object. All internal tensors are detached individually.
|
||||
|
||||
Returns:
|
||||
new Meshes object.
|
||||
"""
|
||||
verts_list = self.verts_list()
|
||||
faces_list = self.faces_list()
|
||||
new_verts_list = [v.detach() for v in verts_list]
|
||||
new_faces_list = [f.detach() for f in faces_list]
|
||||
other = self.__class__(verts=new_verts_list, faces=new_faces_list)
|
||||
for k in self._INTERNAL_TENSORS:
|
||||
v = getattr(self, k)
|
||||
if torch.is_tensor(v):
|
||||
setattr(other, k, v.detach())
|
||||
|
||||
# Textures is not a tensor but has a detach method
|
||||
if self.textures is not None:
|
||||
other.textures = self.textures.detach()
|
||||
return other
|
||||
|
||||
def to(self, device, copy: bool = False):
|
||||
"""
|
||||
Match functionality of torch.Tensor.to()
|
||||
|
||||
Reference in New Issue
Block a user