Run black on ipynb (#80)

This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-05-18 09:36:38 -07:00
1 parent fb440fedf3
commit 443fdef553
6 files changed
+54 -61

No files matched your search

+1 -3
View File
@@ -25,9 +25,7 @@ jobs:
pip install -r environment/requirements.txt pip install -r environment/requirements.txt
pip install -e . pip install -e .
- name: Run Black - name: Run Black
uses: psf/black@stable run: black mattport/ notebooks/ --check
with:
options: "--check"
- name: Python Pylint - name: Python Pylint
run: | run: |
pylint mattport tests pylint mattport tests
+1 -1
View File
@@ -1,4 +1,4 @@
black==22.3.0 black[jupyter]==22.3.0
hydra-colorlog hydra-colorlog
hydra-core hydra-core
imageio==2.16.1 imageio==2.16.1
+24 -24
View File
@@ -16,7 +16,7 @@
"import torch\n", "import torch\n",
"from mattport.structures import cameras\n", "from mattport.structures import cameras\n",
"import plotly.graph_objects as go\n", "import plotly.graph_objects as go\n",
"import mediapy as media\n" "import mediapy as media"
] ]
}, },
{ {
@@ -61,7 +61,7 @@
" )\n", " )\n",
" )\n", " )\n",
"\n", "\n",
" fig.show()\n" " fig.show()"
] ]
}, },
{ {
@@ -13865,7 +13865,7 @@
"fy = 20\n", "fy = 20\n",
"\n", "\n",
"camera = cameras.PinholeCamera(cx, cy, fx, fy)\n", "camera = cameras.PinholeCamera(cx, cy, fx, fy)\n",
"vis_camera_rays(camera)\n" "vis_camera_rays(camera)"
] ]
}, },
{ {
@@ -16933,7 +16933,7 @@
0, 0,
0.03252455219626427, 0.03252455219626427,
0, 0,
-6.837967969630654e-9, -6.837967969630654e-09,
0, 0,
-0.03252456337213516, -0.03252456337213516,
0, 0,
@@ -16963,7 +16963,7 @@
0, 0,
-0.03252459317445755, -0.03252459317445755,
0, 0,
1.865462451178246e-9, 1.865462451178246e-09,
0, 0,
0.03252459689974785, 0.03252459689974785,
0, 0,
@@ -16993,7 +16993,7 @@
0, 0,
0.09438992291688919, 0.09438992291688919,
0, 0,
-1.9844557996862022e-8, -1.9844557996862022e-08,
0, 0,
-0.09438996762037277, -0.09438996762037277,
0, 0,
@@ -17023,7 +17023,7 @@
0, 0,
-0.09439004957675934, -0.09439004957675934,
0, 0,
5.41378319951491e-9, 5.41378319951491e-09,
0, 0,
0.09439005702733994, 0.09439005702733994,
0, 0,
@@ -17053,7 +17053,7 @@
0, 0,
0.1470157355070114, 0.1470157355070114,
0, 0,
-3.0908619663705394e-8, -3.0908619663705394e-08,
0, 0,
-0.1470157951116562, -0.1470157951116562,
0, 0,
@@ -17083,7 +17083,7 @@
0, 0,
-0.14701592922210693, -0.14701592922210693,
0, 0,
8.432163411953297e-9, 8.432163411953297e-09,
0, 0,
0.14701594412326813, 0.14701594412326813,
0, 0,
@@ -17113,7 +17113,7 @@
0, 0,
0.1852506399154663, 0.1852506399154663,
0, 0,
-3.894713174190656e-8, -3.894713174190656e-08,
0, 0,
-0.18525072932243347, -0.18525072932243347,
0, 0,
@@ -17143,7 +17143,7 @@
0, 0,
-0.1852508783340454, -0.1852508783340454,
0, 0,
1.0625146096288063e-8, 1.0625146096288063e-08,
0, 0,
0.1852508932352066, 0.1852508932352066,
0, 0,
@@ -17173,7 +17173,7 @@
0, 0,
0.20535191893577576, 0.20535191893577576,
0, 0,
-4.3173230324100587e-8, -4.3173230324100587e-08,
0, 0,
-0.20535200834274292, -0.20535200834274292,
0, 0,
@@ -17203,7 +17203,7 @@
0, 0,
-0.20535218715667725, -0.20535218715667725,
0, 0,
1.1778065633905044e-8, 1.1778065633905044e-08,
0, 0,
0.20535220205783844, 0.20535220205783844,
0, 0,
@@ -17233,7 +17233,7 @@
0, 0,
0.20535190403461456, 0.20535190403461456,
0, 0,
-4.317322677138691e-8, -4.317322677138691e-08,
0, 0,
-0.20535199344158173, -0.20535199344158173,
0, 0,
@@ -17263,7 +17263,7 @@
0, 0,
-0.20535217225551605, -0.20535217225551605,
0, 0,
1.1778064745726624e-8, 1.1778064745726624e-08,
0, 0,
0.20535218715667725, 0.20535218715667725,
0, 0,
@@ -17293,7 +17293,7 @@
0, 0,
0.1852506548166275, 0.1852506548166275,
0, 0,
-3.894713529462024e-8, -3.894713529462024e-08,
0, 0,
-0.18525072932243347, -0.18525072932243347,
0, 0,
@@ -17323,7 +17323,7 @@
0, 0,
-0.1852508932352066, -0.1852508932352066,
0, 0,
1.0625146984466483e-8, 1.0625146984466483e-08,
0, 0,
0.1852509081363678, 0.1852509081363678,
0, 0,
@@ -17353,7 +17353,7 @@
0, 0,
0.1470157355070114, 0.1470157355070114,
0, 0,
-3.0908619663705394e-8, -3.0908619663705394e-08,
0, 0,
-0.1470157951116562, -0.1470157951116562,
0, 0,
@@ -17383,7 +17383,7 @@
0, 0,
-0.14701592922210693, -0.14701592922210693,
0, 0,
8.432163411953297e-9, 8.432163411953297e-09,
0, 0,
0.14701594412326813, 0.14701594412326813,
0, 0,
@@ -17413,7 +17413,7 @@
0, 0,
0.0943898856639862, 0.0943898856639862,
0, 0,
-1.9844549115077825e-8, -1.9844549115077825e-08,
0, 0,
-0.09438993036746979, -0.09438993036746979,
0, 0,
@@ -17443,7 +17443,7 @@
0, 0,
-0.09439001232385635, -0.09439001232385635,
0, 0,
5.413780979068861e-9, 5.413780979068861e-09,
0, 0,
0.09439001977443695, 0.09439001977443695,
0, 0,
@@ -17473,7 +17473,7 @@
0, 0,
0.03252454474568367, 0.03252454474568367,
0, 0,
-6.837966637363024e-9, -6.837966637363024e-09,
0, 0,
-0.032524559646844864, -0.032524559646844864,
0, 0,
@@ -17503,7 +17503,7 @@
0, 0,
-0.03252458572387695, -0.03252458572387695,
0, 0,
1.865462007089036e-9, 1.865462007089036e-09,
0, 0,
0.03252458944916725, 0.03252458944916725,
0, 0,
@@ -19581,7 +19581,7 @@
"width = 30\n", "width = 30\n",
"\n", "\n",
"camera = cameras.EquirectangularCamera(height=height, width=width)\n", "camera = cameras.EquirectangularCamera(height=height, width=width)\n",
"vis_camera_rays(camera)\n" "vis_camera_rays(camera)"
] ]
}, },
{ {
+23 -25
View File
@@ -46,6 +46,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"import goat\n", "import goat\n",
"\n",
"vis = goat.vis_utils.get_vis()" "vis = goat.vis_utils.get_vis()"
] ]
}, },
@@ -120,16 +121,16 @@
" name = \"train/{:06d}\".format(idx)\n", " name = \"train/{:06d}\".format(idx)\n",
" # height = 0.5\n", " # height = 0.5\n",
" displayed_focal_length = 0.5\n", " displayed_focal_length = 0.5\n",
" goat.vis_utils.draw_camera_frustum(vis, \n", " goat.vis_utils.draw_camera_frustum(\n",
" vis,\n",
" name=name,\n", " name=name,\n",
" image=image,\n", " image=image,\n",
" K=K.numpy(),\n", " K=K.numpy(),\n",
" pose=camera_to_world.double().numpy(),\n", " pose=camera_to_world.double().numpy(),\n",
" height=3.0,\n", " height=3.0,\n",
" realistic=False,\n", " realistic=False,\n",
" displayed_focal_length=0.0\n", " displayed_focal_length=0.0,\n",
" )\n", " )"
"\n"
] ]
}, },
{ {
@@ -198,6 +199,7 @@
" # the white pixels are rays\n", " # the white pixels are rays\n",
" media.show_image((image * 255).to(torch.uint8))\n", " media.show_image((image * 255).to(torch.uint8))\n",
"\n", "\n",
"\n",
"def sample_and_show_batch():\n", "def sample_and_show_batch():\n",
" batch = next(iter(dataloader))\n", " batch = next(iter(dataloader))\n",
" show_batch(batch)\n", " show_batch(batch)\n",
@@ -235,14 +237,16 @@
"skip = 1\n", "skip = 1\n",
"size = 8\n", "size = 8\n",
"data = []\n", "data = []\n",
"data += [go.Scatter3d(\n", "data += [\n",
" go.Scatter3d(\n",
" x=ray_generator.camera_to_world[::skip, 0, 3],\n", " x=ray_generator.camera_to_world[::skip, 0, 3],\n",
" y=ray_generator.camera_to_world[::skip, 1, 3],\n", " y=ray_generator.camera_to_world[::skip, 1, 3],\n",
" z=ray_generator.camera_to_world[::skip, 2, 3],\n", " z=ray_generator.camera_to_world[::skip, 2, 3],\n",
" mode='markers',\n", " mode=\"markers\",\n",
" name=\"origins\",\n", " name=\"origins\",\n",
" marker=dict(color='rgba(0, 0, 0, 1)', size=size)\n", " marker=dict(color=\"rgba(0, 0, 0, 1)\", size=size),\n",
")]" " )\n",
"]"
] ]
}, },
{ {
@@ -275,9 +279,13 @@
"source": [ "source": [
"# near_plane = cfg.graph.network.near_plane\n", "# near_plane = cfg.graph.network.near_plane\n",
"# far_plane = cfg.graph.network.far_plane\n", "# far_plane = cfg.graph.network.far_plane\n",
"lines = torch.stack([intersected_ray_bundle.origins + intersected_ray_bundle.directions * intersected_ray_bundle.nears,\n", "lines = torch.stack(\n",
" intersected_ray_bundle.origins + intersected_ray_bundle.directions * intersected_ray_bundle.fars\n", " [\n",
" ], dim=1).tolist() # (num_rays, 2, 3)\n", " intersected_ray_bundle.origins + intersected_ray_bundle.directions * intersected_ray_bundle.nears,\n",
" intersected_ray_bundle.origins + intersected_ray_bundle.directions * intersected_ray_bundle.fars,\n",
" ],\n",
" dim=1,\n",
").tolist() # (num_rays, 2, 3)\n",
"lines = torch.tensor(random.sample(lines, k=100))" "lines = torch.tensor(random.sample(lines, k=100))"
] ]
}, },
@@ -302,21 +310,11 @@
" autosize=False,\n", " autosize=False,\n",
" width=1000,\n", " width=1000,\n",
" height=1000,\n", " height=1000,\n",
" margin=go.layout.Margin(\n", " margin=go.layout.Margin(l=50, r=50, b=100, t=100, pad=4),\n",
" l=50,\n",
" r=50,\n",
" b=100,\n",
" t=100,\n",
" pad=4\n",
" ),\n",
" scene=go.layout.Scene(\n", " scene=go.layout.Scene(\n",
" aspectmode=\"data\",\n", " aspectmode=\"data\",\n",
" camera=dict(\n", " camera=dict(up=dict(x=0, y=0, z=1), center=dict(x=0, y=0, z=0), eye=dict(x=1.25, y=1.25, z=1.25)),\n",
" up=dict(x=0, y=0, z=1),\n", " ),\n",
" center=dict(x=0, y=0, z=0),\n",
" eye=dict(x=1.25, y=1.25, z=1.25)\n",
" )\n",
" )\n",
")\n", ")\n",
"fig = go.Figure(data=data, layout=layout)\n", "fig = go.Figure(data=data, layout=layout)\n",
"fig.show()" "fig.show()"
@@ -338,7 +336,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"fig.write_image(\"temp.png\")\n", "fig.write_image(\"temp.png\")\n",
"plotly_image = imageio.imread(\"temp.png\")\n" "plotly_image = imageio.imread(\"temp.png\")"
] ]
}, },
{ {
+5 -5
View File
@@ -26,7 +26,7 @@
"source": [ "source": [
"import torch\n", "import torch\n",
"import mediapy as media\n", "import mediapy as media\n",
"from mattport.nerf.field_modules import encoding\n" "from mattport.nerf.field_modules import encoding"
] ]
}, },
{ {
@@ -114,7 +114,7 @@
"print(\"Input Values:\")\n", "print(\"Input Values:\")\n",
"media.show_images(torch.moveaxis(grid, 2, 0), cmap=\"plasma\", border=True)\n", "media.show_images(torch.moveaxis(grid, 2, 0), cmap=\"plasma\", border=True)\n",
"print(\"Encoded Values:\")\n", "print(\"Encoded Values:\")\n",
"media.show_images(torch.moveaxis(encoded_values, 2, 0), cmap=\"plasma\", border=True)\n" "media.show_images(torch.moveaxis(encoded_values, 2, 0), cmap=\"plasma\", border=True)"
] ]
}, },
{ {
@@ -194,7 +194,7 @@
"print(\"Input Values:\")\n", "print(\"Input Values:\")\n",
"media.show_images(torch.moveaxis(grid, 2, 0), cmap=\"plasma\", border=True)\n", "media.show_images(torch.moveaxis(grid, 2, 0), cmap=\"plasma\", border=True)\n",
"print(\"Encoded Values:\")\n", "print(\"Encoded Values:\")\n",
"media.show_images(torch.moveaxis(encoded_values, 2, 0), cmap=\"plasma\", border=True)\n" "media.show_images(torch.moveaxis(encoded_values, 2, 0), cmap=\"plasma\", border=True)"
] ]
}, },
{ {
@@ -296,7 +296,7 @@
"encoded_images = torch.moveaxis(encoded_images, 2, 0)\n", "encoded_images = torch.moveaxis(encoded_images, 2, 0)\n",
"encoded_images -= torch.min(encoded_images)\n", "encoded_images -= torch.min(encoded_images)\n",
"encoded_images /= torch.max(encoded_images)\n", "encoded_images /= torch.max(encoded_images)\n",
"media.show_images(encoded_images.detach().numpy(), cmap=\"plasma\", border=True)\n" "media.show_images(encoded_images.detach().numpy(), cmap=\"plasma\", border=True)"
] ]
}, },
{ {
@@ -418,7 +418,7 @@
"\n", "\n",
"for level in range(levels):\n", "for level in range(levels):\n",
" print(f\"Level: {level+1}\")\n", " print(f\"Level: {level+1}\")\n",
" media.show_images(encoded_values[level**2 : (level + 1) ** 2, ...], cmap=\"plasma\", border=True)\n" " media.show_images(encoded_values[level**2 : (level + 1) ** 2, ...], cmap=\"plasma\", border=True)"
] ]
}, },
{ {
-3
View File
@@ -12,9 +12,6 @@ if __name__ == "__main__":
for step in steps: for step in steps:
if "name" in step and step["name"] in LOCAL_TESTS: if "name" in step and step["name"] in LOCAL_TESTS:
if step["name"] == "Run Black":
curr_command = f"black mattport/ {step['with']['options']};"
else:
compressed = step["run"].replace("\n", ";").replace("\\", "") compressed = step["run"].replace("\n", ";").replace("\\", "")
curr_command = f"{compressed}" curr_command = f"{compressed}"