From 4485a00e2a7597d457e627071377b94f4b071815 Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Mon, 11 Apr 2022 16:35:50 -0700 Subject: [PATCH 1/6] Update github action --- .github/workflows/pytest.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index d86209067..59c83faa8 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,4 +1,4 @@ -name: Python application +name: Format Lint and Test on: push: @@ -25,6 +25,14 @@ jobs: python -m pip install --upgrade pip pip install -r environment/requirements.txt python setup.py develop + - name: Run Black + uses: psf/black@stable + with: + options: "--check --verbose --line-length=120" + - name: Python Pylint GitHub Action + uses: vcoder4c/git_pylint@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test with pytest run: | pytest tests From 0061b59b791e78fb5251407285bda628611906b6 Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Mon, 11 Apr 2022 16:44:24 -0700 Subject: [PATCH 2/6] Reformat missing files --- .../workflows/{pytest.yml => code_checks.yml} | 2 +- .github/workflows/lint.yml | 29 ------------------- mattport/nerf/dataset/dataset.py | 8 +---- tests/nerf/test_graph.py | 14 +++++---- 4 files changed, 11 insertions(+), 42 deletions(-) rename .github/workflows/{pytest.yml => code_checks.yml} (94%) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/code_checks.yml similarity index 94% rename from .github/workflows/pytest.yml rename to .github/workflows/code_checks.yml index 59c83faa8..1dce516f0 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/code_checks.yml @@ -1,4 +1,4 @@ -name: Format Lint and Test +name: Check code for formating and run tests. on: push: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 087929806..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Lint - -on: - push: - paths: - - '*.py' - pull_request: - paths: - - '*.py' - -jobs: - format_and_lint: - runs-on: ubuntu-latest - steps: - - name: Setup Python - uses: actions/setup-python@v1 - with: - python-version: 3.8.12 - architecture: x64 - - name: Checkout PyTorch - uses: actions/checkout@master - - name: Run Black - uses: psf/black@stable - with: - options: "--check --verbose --line-length=120" - - name: Python Pylint GitHub Action - uses: vcoder4c/git_pylint@v3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/mattport/nerf/dataset/dataset.py b/mattport/nerf/dataset/dataset.py index 2c48232fa..99c8c546b 100644 --- a/mattport/nerf/dataset/dataset.py +++ b/mattport/nerf/dataset/dataset.py @@ -15,12 +15,7 @@ class Dataset(torch.utils.data.Dataset): torch (_type_): _description_ """ - def __init__( - self, - data_directory: str, - dataset_type: str, - scene: str - ): + def __init__(self, data_directory: str, dataset_type: str, scene: str): """_summary_ Args: @@ -33,7 +28,6 @@ class Dataset(torch.utils.data.Dataset): self.dataset_type = dataset_type self.scene = scene - def __len__(self): pass diff --git a/tests/nerf/test_graph.py b/tests/nerf/test_graph.py index bdeefde58..e73de2873 100644 --- a/tests/nerf/test_graph.py +++ b/tests/nerf/test_graph.py @@ -173,13 +173,17 @@ def test_ordering(): assert np.array_equal(target, order) test_repeated_graph.modules_config["mlp_0"]["inputs"][1] = "encoder_1" - test_repeated_graph.modules_config["encoder_1"] = {"class_name": "Encoding", "inputs": ["x"], "meta_data": {"out_dim": 8}} + test_repeated_graph.modules_config["encoder_1"] = { + "class_name": "Encoding", + "inputs": ["x"], + "meta_data": {"out_dim": 8}, + } order = test_repeated_graph.get_module_order() - assert order.index('mlp_0') > order.index('encoder_0') and order.index('mlp_0') > order.index('encoder_1') + assert order.index("mlp_0") > order.index("encoder_0") and order.index("mlp_0") > order.index("encoder_1") test_complex_graph = Graph(create_complex_graph()) _ = test_complex_graph.construct_graph() order = test_complex_graph.get_module_order() - assert order.index('mlp_2') > order.index('mlp_0') - assert order.index('mlp_2') > order.index('encoder_0') - assert order.index('mlp_3') > order.index('encoder_0') + assert order.index("mlp_2") > order.index("mlp_0") + assert order.index("mlp_2") > order.index("encoder_0") + assert order.index("mlp_3") > order.index("encoder_0") From c2a851ed92ba4495d218898a86edf4605db6048d Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Mon, 11 Apr 2022 17:04:08 -0700 Subject: [PATCH 3/6] Fix linting errors throughout repo --- .github/workflows/code_checks.yml | 2 ++ .vscode/settings.json | 6 ++++-- mattport/nerf/modules/__init__.py | 1 + mattport/nerf/modules/encoding.py | 4 ++-- mattport/nerf/modules/mlp.py | 3 +++ mattport/nerf/optimizer.py | 4 ++++ mattport/nerf/sampler.py | 9 +++++---- mattport/nerf/trainer.py | 6 +++--- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index 1dce516f0..2c6f844a6 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -31,6 +31,8 @@ jobs: options: "--check --verbose --line-length=120" - name: Python Pylint GitHub Action uses: vcoder4c/git_pylint@v3 + with: + options: "--max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test with pytest diff --git a/.vscode/settings.json b/.vscode/settings.json index 2f20bab22..3f8af487b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,7 +19,9 @@ "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "python.linting.pylintArgs": [ - "--generated-members=numpy.* ,torch.* ,cv2.* , cv.*", - "--max-line-length=120" + "--generated-members=numpy.*,torch.*,cv2.*,cv.*", + "--max-line-length=120", + "--good-names=i,j,x,y,lr", + "--disable=too-many-arguments" ], } \ No newline at end of file diff --git a/mattport/nerf/modules/__init__.py b/mattport/nerf/modules/__init__.py index 39b25225c..f76543920 100644 --- a/mattport/nerf/modules/__init__.py +++ b/mattport/nerf/modules/__init__.py @@ -1,2 +1,3 @@ +"""init modules""" from .encoding import Encoding from .mlp import MLP diff --git a/mattport/nerf/modules/encoding.py b/mattport/nerf/modules/encoding.py index 53ce14854..2e82ec92a 100644 --- a/mattport/nerf/modules/encoding.py +++ b/mattport/nerf/modules/encoding.py @@ -131,8 +131,8 @@ class RFFEncoding(Encoding): Returns: TensorType[..., "output_dim"]: Output values will be between -1 and 1 """ - B = torch.normal(mean=0, std=self.scale, size=(self.in_dim, self.num_frequencies)) - scaled_inputs = in_tensor @ B # [..., "num_frequencies"] + b_matrix = torch.normal(mean=0, std=self.scale, size=(self.in_dim, self.num_frequencies)) + scaled_inputs = in_tensor @ b_matrix # [..., "num_frequencies"] encoded_inputs = torch.cat([torch.sin(scaled_inputs), torch.cos(scaled_inputs)], axis=-1) return encoded_inputs diff --git a/mattport/nerf/modules/mlp.py b/mattport/nerf/modules/mlp.py index 6c47264da..f278e88b9 100644 --- a/mattport/nerf/modules/mlp.py +++ b/mattport/nerf/modules/mlp.py @@ -1,3 +1,6 @@ +""" +Multi Layer Perceptron +""" from typing import Optional from torch import nn diff --git a/mattport/nerf/optimizer.py b/mattport/nerf/optimizer.py index e6c6581cf..6afefcb05 100644 --- a/mattport/nerf/optimizer.py +++ b/mattport/nerf/optimizer.py @@ -24,3 +24,7 @@ class Optimizer: NotImplementedError: _description_ """ raise NotImplementedError + + def test2(self): + """Summary""" + raise NotImplementedError diff --git a/mattport/nerf/sampler.py b/mattport/nerf/sampler.py index 90428f872..340447432 100644 --- a/mattport/nerf/sampler.py +++ b/mattport/nerf/sampler.py @@ -2,11 +2,12 @@ Collection of sampling strategies """ from typing import NamedTuple -from torchtyping import TensorType -from torch import nn -import torch -import nerf.cameras as cameras +import torch +from torch import nn +from torchtyping import TensorType + +from mattport.nerf import cameras RaySamples = NamedTuple( "RaySamples", [("locations", TensorType[..., "num_samples", 3]), ("deltas", TensorType[..., "num_samples"])] diff --git a/mattport/nerf/trainer.py b/mattport/nerf/trainer.py index 13e58d663..f0a3ca04d 100644 --- a/mattport/nerf/trainer.py +++ b/mattport/nerf/trainer.py @@ -3,10 +3,9 @@ Code to train model. """ from mattport.nerf.dataset.build import build_dataset from mattport.nerf.optimizer import Optimizer -from mattport.nerf.graph import Graph -class Trainer(object): +class Trainer: """Training class""" def __init__(self, config: dict): @@ -23,7 +22,8 @@ class Trainer(object): def setup_graph(self): """_summary_""" - self.graph = Graph() + # self.graph = Graph() + raise NotImplementedError def setup_optimizer(self): """_summary_""" From caa7ced3f0ded07d821a716d607f8780ab082bea Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Mon, 11 Apr 2022 17:06:14 -0700 Subject: [PATCH 4/6] Fix code checks workflow --- .github/workflows/code_checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index 2c6f844a6..bf9e86b45 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -32,7 +32,7 @@ jobs: - name: Python Pylint GitHub Action uses: vcoder4c/git_pylint@v3 with: - options: "--max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments + options: "--max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test with pytest From 6d496a51e7378cf8474e2986759a90bd41b9db49 Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Mon, 11 Apr 2022 17:08:43 -0700 Subject: [PATCH 5/6] Fix action --- .github/workflows/code_checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index bf9e86b45..5919b1ef4 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -32,7 +32,7 @@ jobs: - name: Python Pylint GitHub Action uses: vcoder4c/git_pylint@v3 with: - options: "--max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments" + args: "--max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test with pytest From 50dab7868bc47083a99da72d50cbea95c52731aa Mon Sep 17 00:00:00 2001 From: Matt Tancik Date: Mon, 11 Apr 2022 17:12:16 -0700 Subject: [PATCH 6/6] maybe fix action --- .github/workflows/code_checks.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index 5919b1ef4..bbaeb9129 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -29,12 +29,9 @@ jobs: uses: psf/black@stable with: options: "--check --verbose --line-length=120" - - name: Python Pylint GitHub Action - uses: vcoder4c/git_pylint@v3 - with: - args: "--max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Python Pylint + run: | + pylint mattport --max-line-length=120 --generated-members=numpy.*,torch.*,cv2.*,cv.* --good-names=i,j,x,y,lr --disable=too-many-arguments - name: Test with pytest run: | pytest tests