栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytorch3d代码解释:pytorch3d.structures.meshes之verts

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pytorch3d代码解释:pytorch3d.structures.meshes之verts

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/923229.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号