"tutorials/vscode:/vscode.git/clone" did not exist on "09642d7c21c5930ae678d8b7c348be2302225a2a"
Commit 64289a49 authored by Patrick Labatut's avatar Patrick Labatut Committed by Facebook GitHub Bot
Browse files

Annotate dunder functions

Summary: Annotate the (return type of the) following dunder functions across the codebase: `__init__()`, `__len__()`, `__getitem__()`

Reviewed By: nikhilaravi

Differential Revision: D29001801

fbshipit-source-id: 928d9e1c417ffe01ab8c0445311287786e997c7c
parent 35855bf8
...@@ -84,7 +84,7 @@ class ClippedFaces: ...@@ -84,7 +84,7 @@ class ClippedFaces:
barycentric_conversion: Optional[torch.Tensor] = None, barycentric_conversion: Optional[torch.Tensor] = None,
faces_clipped_to_conversion_idx: Optional[torch.Tensor] = None, faces_clipped_to_conversion_idx: Optional[torch.Tensor] = None,
clipped_faces_neighbor_idx: Optional[torch.Tensor] = None, clipped_faces_neighbor_idx: Optional[torch.Tensor] = None,
): ) -> None:
self.face_verts = face_verts self.face_verts = face_verts
self.mesh_to_face_first_idx = mesh_to_face_first_idx self.mesh_to_face_first_idx = mesh_to_face_first_idx
self.num_faces_per_mesh = num_faces_per_mesh self.num_faces_per_mesh = num_faces_per_mesh
...@@ -139,7 +139,7 @@ class ClipFrustum: ...@@ -139,7 +139,7 @@ class ClipFrustum:
perspective_correct: bool = False, perspective_correct: bool = False,
cull: bool = True, cull: bool = True,
z_clip_value: Optional[float] = None, z_clip_value: Optional[float] = None,
): ) -> None:
self.left = left self.left = left
self.right = right self.right = right
self.top = top self.top = top
......
...@@ -49,7 +49,7 @@ class RasterizationSettings: ...@@ -49,7 +49,7 @@ class RasterizationSettings:
cull_backfaces: bool = False, cull_backfaces: bool = False,
z_clip_value: Optional[float] = None, z_clip_value: Optional[float] = None,
cull_to_frustum: bool = False, cull_to_frustum: bool = False,
): ) -> None:
self.image_size = image_size self.image_size = image_size
self.blur_radius = blur_radius self.blur_radius = blur_radius
self.faces_per_pixel = faces_per_pixel self.faces_per_pixel = faces_per_pixel
...@@ -68,7 +68,7 @@ class MeshRasterizer(nn.Module): ...@@ -68,7 +68,7 @@ class MeshRasterizer(nn.Module):
Meshes. Meshes.
""" """
def __init__(self, cameras=None, raster_settings=None): def __init__(self, cameras=None, raster_settings=None) -> None:
""" """
Args: Args:
cameras: A cameras object which has a `transform_points` method cameras: A cameras object which has a `transform_points` method
......
...@@ -32,7 +32,7 @@ class MeshRenderer(nn.Module): ...@@ -32,7 +32,7 @@ class MeshRenderer(nn.Module):
function. function.
""" """
def __init__(self, rasterizer, shader): def __init__(self, rasterizer, shader) -> None:
super().__init__() super().__init__()
self.rasterizer = rasterizer self.rasterizer = rasterizer
self.shader = shader self.shader = shader
...@@ -76,7 +76,7 @@ class MeshRendererWithFragments(nn.Module): ...@@ -76,7 +76,7 @@ class MeshRendererWithFragments(nn.Module):
depth = fragments.zbuf depth = fragments.zbuf
""" """
def __init__(self, rasterizer, shader): def __init__(self, rasterizer, shader) -> None:
super().__init__() super().__init__()
self.rasterizer = rasterizer self.rasterizer = rasterizer
self.shader = shader self.shader = shader
......
...@@ -51,7 +51,7 @@ class HardPhongShader(nn.Module): ...@@ -51,7 +51,7 @@ class HardPhongShader(nn.Module):
lights=None, lights=None,
materials=None, materials=None,
blend_params=None, blend_params=None,
): ) -> None:
super().__init__() super().__init__()
self.lights = lights if lights is not None else PointLights(device=device) self.lights = lights if lights is not None else PointLights(device=device)
self.materials = ( self.materials = (
...@@ -112,7 +112,7 @@ class SoftPhongShader(nn.Module): ...@@ -112,7 +112,7 @@ class SoftPhongShader(nn.Module):
lights=None, lights=None,
materials=None, materials=None,
blend_params=None, blend_params=None,
): ) -> None:
super().__init__() super().__init__()
self.lights = lights if lights is not None else PointLights(device=device) self.lights = lights if lights is not None else PointLights(device=device)
self.materials = ( self.materials = (
...@@ -178,7 +178,7 @@ class HardGouraudShader(nn.Module): ...@@ -178,7 +178,7 @@ class HardGouraudShader(nn.Module):
lights=None, lights=None,
materials=None, materials=None,
blend_params=None, blend_params=None,
): ) -> None:
super().__init__() super().__init__()
self.lights = lights if lights is not None else PointLights(device=device) self.lights = lights if lights is not None else PointLights(device=device)
self.materials = ( self.materials = (
...@@ -243,7 +243,7 @@ class SoftGouraudShader(nn.Module): ...@@ -243,7 +243,7 @@ class SoftGouraudShader(nn.Module):
lights=None, lights=None,
materials=None, materials=None,
blend_params=None, blend_params=None,
): ) -> None:
super().__init__() super().__init__()
self.lights = lights if lights is not None else PointLights(device=device) self.lights = lights if lights is not None else PointLights(device=device)
self.materials = ( self.materials = (
...@@ -325,7 +325,7 @@ class HardFlatShader(nn.Module): ...@@ -325,7 +325,7 @@ class HardFlatShader(nn.Module):
lights=None, lights=None,
materials=None, materials=None,
blend_params=None, blend_params=None,
): ) -> None:
super().__init__() super().__init__()
self.lights = lights if lights is not None else PointLights(device=device) self.lights = lights if lights is not None else PointLights(device=device)
self.materials = ( self.materials = (
...@@ -381,7 +381,7 @@ class SoftSilhouetteShader(nn.Module): ...@@ -381,7 +381,7 @@ class SoftSilhouetteShader(nn.Module):
3D Reasoning', ICCV 2019 3D Reasoning', ICCV 2019
""" """
def __init__(self, blend_params=None): def __init__(self, blend_params=None) -> None:
super().__init__() super().__init__()
self.blend_params = blend_params if blend_params is not None else BlendParams() self.blend_params = blend_params if blend_params is not None else BlendParams()
......
...@@ -262,7 +262,7 @@ class TexturesBase: ...@@ -262,7 +262,7 @@ class TexturesBase:
""" """
raise NotImplementedError() raise NotImplementedError()
def __getitem__(self, index): def __getitem__(self, index) -> "TexturesBase":
""" """
Each texture class should implement a method Each texture class should implement a method
to get the texture properties for the to get the texture properties for the
...@@ -321,7 +321,7 @@ def Textures( ...@@ -321,7 +321,7 @@ def Textures(
class TexturesAtlas(TexturesBase): class TexturesAtlas(TexturesBase):
def __init__(self, atlas: Union[torch.Tensor, List[torch.Tensor]]): def __init__(self, atlas: Union[torch.Tensor, List[torch.Tensor]]) -> None:
""" """
A texture representation where each face has a square texture map. A texture representation where each face has a square texture map.
This is based on the implementation from SoftRasterizer [1]. This is based on the implementation from SoftRasterizer [1].
...@@ -420,7 +420,7 @@ class TexturesAtlas(TexturesBase): ...@@ -420,7 +420,7 @@ class TexturesAtlas(TexturesBase):
tex._num_faces_per_mesh = num_faces tex._num_faces_per_mesh = num_faces
return tex return tex
def __getitem__(self, index): def __getitem__(self, index) -> "TexturesAtlas":
props = ["atlas_list", "_num_faces_per_mesh"] props = ["atlas_list", "_num_faces_per_mesh"]
new_props = self._getitem(index, props=props) new_props = self._getitem(index, props=props)
atlas = new_props["atlas_list"] atlas = new_props["atlas_list"]
...@@ -596,7 +596,7 @@ class TexturesUV(TexturesBase): ...@@ -596,7 +596,7 @@ class TexturesUV(TexturesBase):
verts_uvs: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]], verts_uvs: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]],
padding_mode: str = "border", padding_mode: str = "border",
align_corners: bool = True, align_corners: bool = True,
): ) -> None:
""" """
Textures are represented as a per mesh texture map and uv coordinates for each Textures are represented as a per mesh texture map and uv coordinates for each
vertex in each face. NOTE: this class only supports one texture map per mesh. vertex in each face. NOTE: this class only supports one texture map per mesh.
...@@ -786,7 +786,7 @@ class TexturesUV(TexturesBase): ...@@ -786,7 +786,7 @@ class TexturesUV(TexturesBase):
tex.valid = self.valid.detach() tex.valid = self.valid.detach()
return tex return tex
def __getitem__(self, index): def __getitem__(self, index) -> "TexturesUV":
props = ["verts_uvs_list", "faces_uvs_list", "maps_list", "_num_faces_per_mesh"] props = ["verts_uvs_list", "faces_uvs_list", "maps_list", "_num_faces_per_mesh"]
new_props = self._getitem(index, props) new_props = self._getitem(index, props)
faces_uvs = new_props["faces_uvs_list"] faces_uvs = new_props["faces_uvs_list"]
...@@ -1257,7 +1257,7 @@ class TexturesVertex(TexturesBase): ...@@ -1257,7 +1257,7 @@ class TexturesVertex(TexturesBase):
def __init__( def __init__(
self, self,
verts_features: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]], verts_features: Union[torch.Tensor, List[torch.Tensor], Tuple[torch.Tensor]],
): ) -> None:
""" """
Batched texture representation where each vertex in a mesh Batched texture representation where each vertex in a mesh
has a C dimensional feature vector. has a C dimensional feature vector.
......
...@@ -25,7 +25,7 @@ class AlphaCompositor(nn.Module): ...@@ -25,7 +25,7 @@ class AlphaCompositor(nn.Module):
def __init__( def __init__(
self, background_color: Optional[Union[Tuple, List, torch.Tensor]] = None self, background_color: Optional[Union[Tuple, List, torch.Tensor]] = None
): ) -> None:
super().__init__() super().__init__()
self.background_color = background_color self.background_color = background_color
...@@ -47,7 +47,7 @@ class NormWeightedCompositor(nn.Module): ...@@ -47,7 +47,7 @@ class NormWeightedCompositor(nn.Module):
def __init__( def __init__(
self, background_color: Optional[Union[Tuple, List, torch.Tensor]] = None self, background_color: Optional[Union[Tuple, List, torch.Tensor]] = None
): ) -> None:
super().__init__() super().__init__()
self.background_color = background_color self.background_color = background_color
......
...@@ -326,7 +326,7 @@ class Renderer(torch.nn.Module): ...@@ -326,7 +326,7 @@ class Renderer(torch.nn.Module):
background_normalized_depth: float = _C.EPS, background_normalized_depth: float = _C.EPS,
n_channels: int = 3, n_channels: int = 3,
n_track: int = 5, n_track: int = 5,
): ) -> None:
super(Renderer, self).__init__() super(Renderer, self).__init__()
# pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`. # pyre-fixme[16]: Module `pytorch3d` has no attribute `_C`.
self._renderer = _C.PulsarRenderer( self._renderer = _C.PulsarRenderer(
......
...@@ -51,7 +51,7 @@ class PulsarPointsRenderer(nn.Module): ...@@ -51,7 +51,7 @@ class PulsarPointsRenderer(nn.Module):
n_channels: int = 3, n_channels: int = 3,
max_num_spheres: int = int(1e6), # noqa: B008 max_num_spheres: int = int(1e6), # noqa: B008
**kwargs, **kwargs,
): ) -> None:
""" """
rasterizer (PointsRasterizer): An object encapsulating rasterization parameters. rasterizer (PointsRasterizer): An object encapsulating rasterization parameters.
compositor (ignored): Only keeping this for interface consistency. Default: None. compositor (ignored): Only keeping this for interface consistency. Default: None.
......
...@@ -38,7 +38,7 @@ class PointsRasterizationSettings: ...@@ -38,7 +38,7 @@ class PointsRasterizationSettings:
points_per_pixel: int = 8, points_per_pixel: int = 8,
bin_size: Optional[int] = None, bin_size: Optional[int] = None,
max_points_per_bin: Optional[int] = None, max_points_per_bin: Optional[int] = None,
): ) -> None:
self.image_size = image_size self.image_size = image_size
self.radius = radius self.radius = radius
self.points_per_pixel = points_per_pixel self.points_per_pixel = points_per_pixel
...@@ -51,7 +51,7 @@ class PointsRasterizer(nn.Module): ...@@ -51,7 +51,7 @@ class PointsRasterizer(nn.Module):
This class implements methods for rasterizing a batch of pointclouds. This class implements methods for rasterizing a batch of pointclouds.
""" """
def __init__(self, cameras=None, raster_settings=None): def __init__(self, cameras=None, raster_settings=None) -> None:
""" """
cameras: A cameras object which has a `transform_points` method cameras: A cameras object which has a `transform_points` method
which returns the transformed points after applying the which returns the transformed points after applying the
......
...@@ -32,7 +32,7 @@ class PointsRenderer(nn.Module): ...@@ -32,7 +32,7 @@ class PointsRenderer(nn.Module):
function. function.
""" """
def __init__(self, rasterizer, compositor): def __init__(self, rasterizer, compositor) -> None:
super().__init__() super().__init__()
self.rasterizer = rasterizer self.rasterizer = rasterizer
self.compositor = compositor self.compositor = compositor
......
...@@ -25,7 +25,7 @@ class TensorAccessor(nn.Module): ...@@ -25,7 +25,7 @@ class TensorAccessor(nn.Module):
and one element in the batch needs to be modified. and one element in the batch needs to be modified.
""" """
def __init__(self, class_object, index: Union[int, slice]): def __init__(self, class_object, index: Union[int, slice]) -> None:
""" """
Args: Args:
class_object: this should be an instance of a class which has class_object: this should be an instance of a class which has
...@@ -96,7 +96,7 @@ class TensorProperties(nn.Module): ...@@ -96,7 +96,7 @@ class TensorProperties(nn.Module):
def __init__( def __init__(
self, dtype: torch.dtype = torch.float32, device: Device = "cpu", **kwargs self, dtype: torch.dtype = torch.float32, device: Device = "cpu", **kwargs
): ) -> None:
""" """
Args: Args:
dtype: data type to set for the inputs dtype: data type to set for the inputs
...@@ -143,7 +143,7 @@ class TensorProperties(nn.Module): ...@@ -143,7 +143,7 @@ class TensorProperties(nn.Module):
def isempty(self) -> bool: def isempty(self) -> bool:
return self._N == 0 return self._N == 0
def __getitem__(self, index: Union[int, slice]): def __getitem__(self, index: Union[int, slice]) -> TensorAccessor:
""" """
Args: Args:
......
...@@ -219,7 +219,7 @@ class Meshes: ...@@ -219,7 +219,7 @@ class Meshes:
textures=None, textures=None,
*, *,
verts_normals=None, verts_normals=None,
): ) -> None:
""" """
Args: Args:
verts: verts:
...@@ -469,10 +469,10 @@ class Meshes: ...@@ -469,10 +469,10 @@ class Meshes:
else: else:
raise ValueError("verts_normals must be a list or tensor") raise ValueError("verts_normals must be a list or tensor")
def __len__(self): def __len__(self) -> int:
return self._N return self._N
def __getitem__(self, index): def __getitem__(self, index) -> "Meshes":
""" """
Args: Args:
index: Specifying the index of the mesh to retrieve. index: Specifying the index of the mesh to retrieve.
...@@ -493,7 +493,7 @@ class Meshes: ...@@ -493,7 +493,7 @@ class Meshes:
# NOTE consider converting index to cpu for efficiency # NOTE consider converting index to cpu for efficiency
if index.dtype == torch.bool: if index.dtype == torch.bool:
# advanced indexing on a single dimension # advanced indexing on a single dimension
index = index.nonzero() index = index.nonzero() # pyre-ignore
index = index.squeeze(1) if index.numel() > 0 else index index = index.squeeze(1) if index.numel() > 0 else index
index = index.tolist() index = index.tolist()
verts = [self.verts_list()[i] for i in index] verts = [self.verts_list()[i] for i in index]
......
...@@ -108,7 +108,7 @@ class Pointclouds: ...@@ -108,7 +108,7 @@ class Pointclouds:
"equisized", "equisized",
] ]
def __init__(self, points, normals=None, features=None): def __init__(self, points, normals=None, features=None) -> None:
""" """
Args: Args:
points: points:
...@@ -306,10 +306,10 @@ class Pointclouds: ...@@ -306,10 +306,10 @@ class Pointclouds:
points in a cloud." points in a cloud."
) )
def __len__(self): def __len__(self) -> int:
return self._N return self._N
def __getitem__(self, index): def __getitem__(self, index) -> "Pointclouds":
""" """
Args: Args:
index: Specifying the index of the cloud to retrieve. index: Specifying the index of the cloud to retrieve.
...@@ -343,7 +343,7 @@ class Pointclouds: ...@@ -343,7 +343,7 @@ class Pointclouds:
# NOTE consider converting index to cpu for efficiency # NOTE consider converting index to cpu for efficiency
if index.dtype == torch.bool: if index.dtype == torch.bool:
# advanced indexing on a single dimension # advanced indexing on a single dimension
index = index.nonzero() index = index.nonzero() # pyre-ignore
index = index.squeeze(1) if index.numel() > 0 else index index = index.squeeze(1) if index.numel() > 0 else index
index = index.tolist() index = index.tolist()
points = [self.points_list()[i] for i in index] points = [self.points_list()[i] for i in index]
......
...@@ -155,7 +155,7 @@ class Volumes: ...@@ -155,7 +155,7 @@ class Volumes:
features: Optional[_TensorBatch] = None, features: Optional[_TensorBatch] = None,
voxel_size: _VoxelSize = 1.0, voxel_size: _VoxelSize = 1.0,
volume_translation: _Translation = (0.0, 0.0, 0.0), volume_translation: _Translation = (0.0, 0.0, 0.0),
): ) -> None:
""" """
Args: Args:
**densities**: Batch of input feature volume occupancies of shape **densities**: Batch of input feature volume occupancies of shape
......
...@@ -144,7 +144,7 @@ class Transform3d: ...@@ -144,7 +144,7 @@ class Transform3d:
dtype: torch.dtype = torch.float32, dtype: torch.dtype = torch.float32,
device: Device = "cpu", device: Device = "cpu",
matrix: Optional[torch.Tensor] = None, matrix: Optional[torch.Tensor] = None,
): ) -> None:
""" """
Args: Args:
dtype: The data type of the transformation matrix. dtype: The data type of the transformation matrix.
...@@ -176,7 +176,7 @@ class Transform3d: ...@@ -176,7 +176,7 @@ class Transform3d:
self.device = make_device(device) self.device = make_device(device)
self.dtype = dtype self.dtype = dtype
def __len__(self): def __len__(self) -> int:
return self.get_matrix().shape[0] return self.get_matrix().shape[0]
def __getitem__( def __getitem__(
...@@ -462,7 +462,7 @@ class Translate(Transform3d): ...@@ -462,7 +462,7 @@ class Translate(Transform3d):
z=None, z=None,
dtype: torch.dtype = torch.float32, dtype: torch.dtype = torch.float32,
device: Optional[Device] = None, device: Optional[Device] = None,
): ) -> None:
""" """
Create a new Transform3d representing 3D translations. Create a new Transform3d representing 3D translations.
...@@ -503,7 +503,7 @@ class Scale(Transform3d): ...@@ -503,7 +503,7 @@ class Scale(Transform3d):
z=None, z=None,
dtype: torch.dtype = torch.float32, dtype: torch.dtype = torch.float32,
device: Optional[Device] = None, device: Optional[Device] = None,
): ) -> None:
""" """
A Transform3d representing a scaling operation, with different scale A Transform3d representing a scaling operation, with different scale
factors along each coordinate axis. factors along each coordinate axis.
...@@ -549,7 +549,7 @@ class Rotate(Transform3d): ...@@ -549,7 +549,7 @@ class Rotate(Transform3d):
dtype: torch.dtype = torch.float32, dtype: torch.dtype = torch.float32,
device: Optional[Device] = None, device: Optional[Device] = None,
orthogonal_tol: float = 1e-5, orthogonal_tol: float = 1e-5,
): ) -> None:
""" """
Create a new Transform3d representing 3D rotation using a rotation Create a new Transform3d representing 3D rotation using a rotation
matrix as the input. matrix as the input.
...@@ -589,7 +589,7 @@ class RotateAxisAngle(Rotate): ...@@ -589,7 +589,7 @@ class RotateAxisAngle(Rotate):
degrees: bool = True, degrees: bool = True,
dtype: torch.dtype = torch.float64, dtype: torch.dtype = torch.float64,
device: Optional[Device] = None, device: Optional[Device] = None,
): ) -> None:
""" """
Create a new Transform3d representing 3D rotation about an axis Create a new Transform3d representing 3D rotation about an axis
by an angle. by an angle.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment