mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
lint things
Summary: Lint related fixes: Improve internal/OSS consistency. Fix the fight between black and certain pyre-ignore markers by moving them to the line before. Use clang-format-8 automatically if present. Small number of pyre fixes. arc doesn't run pyre at the moment, so I put back the explicit call to pyre. I don't know if there's an option somewhere to change this. Reviewed By: nikhilaravi Differential Revision: D19780518 fbshipit-source-id: ef1c243392322fa074130f6cff2dd8a6f7738a7f
This commit is contained in:
parent
9e21659fc5
commit
e491efb81f
@ -42,7 +42,7 @@ conda install jupyter
|
||||
pip install scikit-image matplotlib imageio
|
||||
|
||||
# Tests/Linting
|
||||
pip install black isort flake8
|
||||
pip install black isort flake8 flake8-bugbear flake8-comprehensions
|
||||
```
|
||||
|
||||
## Build/Install Pytorch3d
|
||||
|
@ -13,7 +13,7 @@
|
||||
}
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
DIR="${DIR}/.."
|
||||
DIR=$(dirname "${DIR}")
|
||||
|
||||
echo "Running isort..."
|
||||
isort -y -sp "${DIR}"
|
||||
@ -25,6 +25,15 @@ echo "Running flake..."
|
||||
flake8 "${DIR}"
|
||||
|
||||
echo "Running clang-format ..."
|
||||
find "${DIR}" -regex ".*\.\(cpp\|c\|cc\|cu\|cuh\|cxx\|h\|hh\|hpp\|hxx\|tcc\|mm\|m\)" -print0 | xargs -0 clang-format -i
|
||||
clangformat=$(command -v clang-format-8 || echo clang-format)
|
||||
find "${DIR}" -regex ".*\.\(cpp\|c\|cc\|cu\|cuh\|cxx\|h\|hh\|hpp\|hxx\|tcc\|mm\|m\)" -print0 | xargs -0 "${clangformat}" -i
|
||||
|
||||
(cd "${DIR}"; command -v arc > /dev/null && arc lint) || true
|
||||
# (cd "${DIR}"; command -v arc > /dev/null && arc lint) || true
|
||||
|
||||
# Run pyre internally only.
|
||||
if [[ -f tests/TARGETS ]]
|
||||
then
|
||||
echo "Running pyre..."
|
||||
echo "To restart/kill pyre server, run 'pyre restart' or 'pyre kill' in fbcode/"
|
||||
( cd ~/fbsource/fbcode; pyre -l vision/fair/pytorch3d/ )
|
||||
fi
|
||||
|
@ -8,7 +8,7 @@ import os
|
||||
import pathlib
|
||||
import warnings
|
||||
from collections import namedtuple
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
import torch
|
||||
from fvcore.common.file_io import PathManager
|
||||
from PIL import Image
|
||||
@ -519,7 +519,7 @@ def load_mtl(f_mtl, material_names: List, data_dir: str):
|
||||
return material_properties, texture_images
|
||||
|
||||
|
||||
def save_obj(f, verts, faces, decimal_places: int = None):
|
||||
def save_obj(f, verts, faces, decimal_places: Optional[int] = None):
|
||||
"""
|
||||
Save a mesh to an .obj file.
|
||||
|
||||
@ -544,7 +544,7 @@ def save_obj(f, verts, faces, decimal_places: int = None):
|
||||
|
||||
|
||||
# TODO (nikhilar) Speed up this function.
|
||||
def _save(f, verts, faces, decimal_places: int = None):
|
||||
def _save(f, verts, faces, decimal_places: Optional[int] = None):
|
||||
if verts.dim() != 2 or verts.size(1) != 3:
|
||||
raise ValueError("Argument 'verts' should be of shape (num_verts, 3).")
|
||||
if faces.dim() != 2 or faces.size(1) != 3:
|
||||
|
@ -63,21 +63,22 @@ def packed_to_padded(inputs, first_idxs, max_size):
|
||||
Torch wrapper that handles allowed input shapes. See description below.
|
||||
|
||||
Args:
|
||||
inputs: FloatTensor of shape (F,) or (F, D), representing the packed batch tensor.
|
||||
e.g. areas for faces in a batch of meshes.
|
||||
inputs: FloatTensor of shape (F,) or (F, D), representing the packed
|
||||
batch tensor, e.g. areas for faces in a batch of meshes.
|
||||
first_idxs: LongTensor of shape (N,) where N is the number of
|
||||
elements in the batch and `first_idxs[i] = f`
|
||||
means that the inputs for batch element i begin at `inputs[f]`.
|
||||
max_size: Max length of an element in the batch.
|
||||
|
||||
Returns:
|
||||
inputs_padded: FloatTensor of shape (N, max_size) or (N, max_size, D) where max_size is
|
||||
max of `sizes`. The values for batch element i which start at
|
||||
`inputs[first_idxs[i]]` will be copied to `inputs_padded[i, :]`,
|
||||
with zeros padding out the extra inputs.
|
||||
inputs_padded: FloatTensor of shape (N, max_size) or (N, max_size, D)
|
||||
where max_size is max of `sizes`. The values for batch element i
|
||||
which start at `inputs[first_idxs[i]]` will be copied to
|
||||
`inputs_padded[i, :]`, with zeros padding out the extra inputs.
|
||||
|
||||
To handle the allowed input shapes, we convert the inputs tensor of shape (F,) to (F, 1).
|
||||
We reshape the output back to (N, max_size) from (N, max_size, 1).
|
||||
To handle the allowed input shapes, we convert the inputs tensor of shape
|
||||
(F,) to (F, 1). We reshape the output back to (N, max_size) from
|
||||
(N, max_size, 1).
|
||||
"""
|
||||
# if inputs is of shape (F,), reshape into (F, 1)
|
||||
flat = False
|
||||
@ -101,8 +102,8 @@ class _PaddedToPacked(Function):
|
||||
"""
|
||||
Args:
|
||||
ctx: Context object used to calculate gradients.
|
||||
inputs: FloatTensor of shape (N, max_size, D), representing the padded tensor.
|
||||
e.g. areas for faces in a batch of meshes.
|
||||
inputs: FloatTensor of shape (N, max_size, D), representing
|
||||
the padded tensor, e.g. areas for faces in a batch of meshes.
|
||||
first_idxs: LongTensor of shape (N,) where N is the number of
|
||||
elements in the batch and `first_idxs[i] = f`
|
||||
means that the inputs for batch element i begin at `inputs_packed[f]`.
|
||||
@ -144,8 +145,9 @@ def padded_to_packed(inputs, first_idxs, num_inputs):
|
||||
Torch wrapper that handles allowed input shapes. See description below.
|
||||
|
||||
Args:
|
||||
inputs: FloatTensor of shape (N, max_size) or (N, max_size, D), representing the
|
||||
padded tensor. e.g. areas for faces in a batch of meshes.
|
||||
inputs: FloatTensor of shape (N, max_size) or (N, max_size, D),
|
||||
representing the padded tensor, e.g. areas for faces in a batch of
|
||||
meshes.
|
||||
first_idxs: LongTensor of shape (N,) where N is the number of
|
||||
elements in the batch and `first_idxs[i] = f`
|
||||
means that the inputs for batch element i begin at `inputs_packed[f]`.
|
||||
@ -155,8 +157,9 @@ def padded_to_packed(inputs, first_idxs, num_inputs):
|
||||
inputs_packed: FloatTensor of shape (F,) or (F, D) where
|
||||
`inputs_packed[first_idx[i]:] = inputs[i, :]`.
|
||||
|
||||
To handle the allowed input shapes, we convert the inputs tensor of shape (N, max_size)
|
||||
to (N, max_size, 1). We reshape the output back to (F,) from (F, 1).
|
||||
To handle the allowed input shapes, we convert the inputs tensor of shape
|
||||
(N, max_size) to (N, max_size, 1). We reshape the output back to (F,) from
|
||||
(F, 1).
|
||||
"""
|
||||
# if inputs is of shape (N, max_size), reshape into (N, max_size, 1))
|
||||
flat = False
|
||||
|
@ -103,9 +103,8 @@ class OpenGLPerspectiveCameras(TensorProperties):
|
||||
znear = kwargs.get("znear", self.znear) # pyre-ignore[16]
|
||||
zfar = kwargs.get("zfar", self.zfar) # pyre-ignore[16]
|
||||
fov = kwargs.get("fov", self.fov) # pyre-ignore[16]
|
||||
aspect_ratio = kwargs.get(
|
||||
"aspect_ratio", self.aspect_ratio
|
||||
) # pyre-ignore[16]
|
||||
# pyre-ignore[16]
|
||||
aspect_ratio = kwargs.get("aspect_ratio", self.aspect_ratio)
|
||||
degrees = kwargs.get("degrees", self.degrees)
|
||||
|
||||
P = torch.zeros(
|
||||
@ -529,12 +528,10 @@ class SfMPerspectiveCameras(TensorProperties):
|
||||
[0, 0, 1, 0],
|
||||
]
|
||||
"""
|
||||
principal_point = kwargs.get(
|
||||
"principal_point", self.principal_point
|
||||
) # pyre-ignore[16]
|
||||
focal_length = kwargs.get(
|
||||
"focal_length", self.focal_length
|
||||
) # pyre-ignore[16]
|
||||
# pyre-ignore[16]
|
||||
principal_point = kwargs.get("principal_point", self.principal_point)
|
||||
# pyre-ignore[16]
|
||||
focal_length = kwargs.get("focal_length", self.focal_length)
|
||||
|
||||
P = _get_sfm_calibration_matrix(
|
||||
self._N, self.device, focal_length, principal_point, False
|
||||
@ -699,12 +696,10 @@ class SfMOrthographicCameras(TensorProperties):
|
||||
[0, 0, 0, 1],
|
||||
]
|
||||
"""
|
||||
principal_point = kwargs.get(
|
||||
"principal_point", self.principal_point
|
||||
) # pyre-ignore[16]
|
||||
focal_length = kwargs.get(
|
||||
"focal_length", self.focal_length
|
||||
) # pyre-ignore[16]
|
||||
# pyre-ignore[16]
|
||||
principal_point = kwargs.get("principal_point", self.principal_point)
|
||||
# pyre-ignore[16]
|
||||
focal_length = kwargs.get("focal_length", self.focal_length)
|
||||
|
||||
P = _get_sfm_calibration_matrix(
|
||||
self._N, self.device, focal_length, principal_point, True
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
|
||||
from typing import List, Union
|
||||
from typing import List, Optional, Union
|
||||
import torch
|
||||
import torchvision.transforms as T
|
||||
|
||||
@ -81,10 +81,10 @@ def _extend_tensor(input_tensor: torch.Tensor, N: int) -> torch.Tensor:
|
||||
class Textures(object):
|
||||
def __init__(
|
||||
self,
|
||||
maps: Union[List, torch.Tensor] = None,
|
||||
faces_uvs: torch.Tensor = None,
|
||||
verts_uvs: torch.Tensor = None,
|
||||
verts_rgb: torch.Tensor = None,
|
||||
maps: Union[List, torch.Tensor, None] = None,
|
||||
faces_uvs: Optional[torch.Tensor] = None,
|
||||
verts_uvs: Optional[torch.Tensor] = None,
|
||||
verts_rgb: Optional[torch.Tensor] = None,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
@ -105,7 +105,7 @@ class Textures(object):
|
||||
msg = "Expected verts_rgb to be of shape (N, V, 3); got %r"
|
||||
raise ValueError(msg % verts_rgb.shape)
|
||||
if maps is not None:
|
||||
if torch.is_tensor(map) and map.ndim != 4:
|
||||
if torch.is_tensor(maps) and maps.ndim != 4:
|
||||
msg = "Expected maps to be of shape (N, H, W, 3); got %r"
|
||||
raise ValueError(msg % repr(maps.shape))
|
||||
elif isinstance(maps, list):
|
||||
|
@ -2,6 +2,7 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
|
||||
import functools
|
||||
from typing import Optional
|
||||
import torch
|
||||
|
||||
|
||||
@ -246,7 +247,10 @@ def matrix_to_euler_angles(matrix, convention: str):
|
||||
|
||||
|
||||
def random_quaternions(
|
||||
n: int, dtype: torch.dtype = None, device=None, requires_grad=False
|
||||
n: int,
|
||||
dtype: Optional[torch.dtype] = None,
|
||||
device=None,
|
||||
requires_grad=False,
|
||||
):
|
||||
"""
|
||||
Generate random quaternions representing rotations,
|
||||
@ -272,7 +276,10 @@ def random_quaternions(
|
||||
|
||||
|
||||
def random_rotations(
|
||||
n: int, dtype: torch.dtype = None, device=None, requires_grad=False
|
||||
n: int,
|
||||
dtype: Optional[torch.dtype] = None,
|
||||
device=None,
|
||||
requires_grad=False,
|
||||
):
|
||||
"""
|
||||
Generate random rotations as 3x3 rotation matrices.
|
||||
@ -295,7 +302,7 @@ def random_rotations(
|
||||
|
||||
|
||||
def random_rotation(
|
||||
dtype: torch.dtype = None, device=None, requires_grad=False
|
||||
dtype: Optional[torch.dtype] = None, device=None, requires_grad=False
|
||||
):
|
||||
"""
|
||||
Generate a single random 3x3 rotation matrix.
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
import math
|
||||
import warnings
|
||||
from typing import Optional
|
||||
import torch
|
||||
|
||||
from .rotation_conversions import _axis_angle_rotation
|
||||
@ -250,7 +251,7 @@ class Transform3d:
|
||||
out._matrix = matrix
|
||||
return out
|
||||
|
||||
def transform_points(self, points, eps: float = None):
|
||||
def transform_points(self, points, eps: Optional[float] = None):
|
||||
"""
|
||||
Use this transform to transform a set of 3D points. Assumes row major
|
||||
ordering of the input points.
|
||||
|
@ -4,7 +4,6 @@
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
|
||||
import nbformat
|
||||
from bs4 import BeautifulSoup
|
||||
from nbconvert import HTMLExporter, ScriptExporter
|
||||
|
@ -6,7 +6,8 @@ include_trailing_comma=True
|
||||
multi_line_output=3
|
||||
known_standard_library=numpy,setuptools
|
||||
known_myself=pytorch3d
|
||||
known_third_party=fvcore,torch,torchvision,matplotlib,mpl_toolkits,PIL,yaml,jinja2,requests
|
||||
known_third_party=fvcore,torch,torchvision,matplotlib,mpl_toolkits,PIL,yaml
|
||||
jinja2,requests,nbformat,nbconvert,bs4
|
||||
no_lines_before=STDLIB,THIRDPARTY
|
||||
sections=FUTURE,STDLIB,THIRDPARTY,myself,FIRSTPARTY,LOCALFOLDER
|
||||
default_section=FIRSTPARTY
|
||||
|
@ -8,7 +8,6 @@ import unittest
|
||||
import torch
|
||||
|
||||
from pytorch3d.transforms.rotation_conversions import (
|
||||
_axis_angle_rotation,
|
||||
euler_angles_to_matrix,
|
||||
matrix_to_euler_angles,
|
||||
matrix_to_quaternion,
|
||||
|
Loading…
x
Reference in New Issue
Block a user