pytorch3d代码解释:pytorch3d.structures.meshes之verts_list, verts_packed, verts_padded

pytorch3d定义的mesh结构在pytorch3d.structures.meshes源码中可以看到。

首先,meshes数据可能包含多个 mesh结构,每个mesh可能又不同的顶点数和面数。pytorch3d的meshes结构在load obj 或plt文件中的数据后,给出了三种不同的数据格式,分别是:verts_list, verts_packed, verts_padded。

  • def verts_list(self): 与输入相同,未处理
  • def verts_packed(self): 为方便用于深度学习,pytorch3d有针对mesh结构的batch dimension,为保持每个数据长度一致,它将每个mesh填充找到最多点数的mesh,该点数为max(V_n),并将其它mesh点数填充到max(V_n)
def verts_packed(self):
        """
        Get the packed representation of the vertices.

        Returns:
            tensor of vertices of shape (sum(V_n), 3).
        """
        self._compute_packed()
        return self._verts_packed
  • def verts_padded(self):packed是将点数压缩存储的一种形式,它没有batch dimension,但有额外的信息来存储每个mesh的相应点。
def verts_padded(self):
    """
    Get the padded representation of the vertices.

    Returns:
        tensor of vertices of shape (N, max(V_n), 3).
        """
    self._compute_padded()
    return self._verts_padded

faces与verts情况类似,可查看链接。

def _compute_padded(self, refresh: bool = False):
        """
        Computes the padded version of meshes from verts_list and faces_list.
        """
        if not (
            refresh or any(v is None for v in [self._verts_padded, self._faces_padded])
        ):
            return

        verts_list = self.verts_list()
        faces_list = self.faces_list()
        assert (
            faces_list is not None and verts_list is not None
        ), "faces_list and verts_list arguments are required"

        if self.isempty():
            self._faces_padded = torch.zeros(
                (self._N, 0, 3), dtype=torch.int64, device=self.device
            )
            self._verts_padded = torch.zeros(
                (self._N, 0, 3), dtype=torch.float32, device=self.device
            )
        else:
            self._faces_padded = struct_utils.list_to_padded(
                faces_list, (self._F, 3), pad_value=-1.0, equisized=self.equisized
            )
            self._verts_padded = struct_utils.list_to_padded(
                verts_list, (self._V, 3), pad_value=0.0, equisized=self.equisized
            )

    # TODO(nikhilar) Improve performance of _compute_packed.
    def _compute_packed(self, refresh: bool = False):
        """
        Computes the packed version of the meshes from verts_list and faces_list
        and sets the values of auxiliary tensors.

        Args:
            refresh: Set to True to force recomputation of packed representations.
                Default: False.
        """

        if not (
            refresh
            or any(
                v is None
                for v in [
                    self._verts_packed,
                    self._verts_packed_to_mesh_idx,
                    self._mesh_to_verts_packed_first_idx,
                    self._faces_packed,
                    self._faces_packed_to_mesh_idx,
                    self._mesh_to_faces_packed_first_idx,
                ]
            )
        ):
            return

 官方文档中的解释

 pytorch3d.structures.meshes — PyTorch3D documentationhttps://pytorch3d.readthedocs.io/en/latest/_modules/pytorch3d/structures/meshes.html

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2022年5月23日
下一篇 2022年5月23日

相关推荐

此站出售,如需请站内私信或者邮箱!