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
+69 -76

No files matched your search

+1 -3
View File
@@ -25,9 +25,7 @@ jobs:
pip install -r environment/requirements.txt
pip install -e .
- name: Run Black
uses: psf/black@stable
with:
options: "--check"
run: black mattport/ notebooks/ --check
- name: Python Pylint
run: |
pylint mattport tests
+1 -1
View File
@@ -1,4 +1,4 @@
black==22.3.0
black[jupyter]==22.3.0
hydra-colorlog
hydra-core
imageio==2.16.1
+24 -24
View File
@@ -16,7 +16,7 @@
"import torch\n",
"from mattport.structures import cameras\n",
"import plotly.graph_objects as go\n",
"import mediapy as media\n"
"import mediapy as media"
]
},
{
@@ -61,7 +61,7 @@
" )\n",
" )\n",
"\n",
" fig.show()\n"
" fig.show()"
]
},
{
@@ -13865,7 +13865,7 @@
"fy = 20\n",
"\n",
"camera = cameras.PinholeCamera(cx, cy, fx, fy)\n",
"vis_camera_rays(camera)\n"
"vis_camera_rays(camera)"
]
},
{
@@ -16933,7 +16933,7 @@
0,
0.03252455219626427,
0,
-6.837967969630654e-9,
-6.837967969630654e-09,
0,
-0.03252456337213516,
0,
@@ -16963,7 +16963,7 @@
0,
-0.03252459317445755,
0,
1.865462451178246e-9,
1.865462451178246e-09,
0,
0.03252459689974785,
0,
@@ -16993,7 +16993,7 @@
0,
0.09438992291688919,
0,
-1.9844557996862022e-8,
-1.9844557996862022e-08,
0,
-0.09438996762037277,
0,
@@ -17023,7 +17023,7 @@
0,
-0.09439004957675934,
0,
5.41378319951491e-9,
5.41378319951491e-09,
0,
0.09439005702733994,
0,
@@ -17053,7 +17053,7 @@
0,
0.1470157355070114,
0,
-3.0908619663705394e-8,
-3.0908619663705394e-08,
0,
-0.1470157951116562,
0,
@@ -17083,7 +17083,7 @@
0,
-0.14701592922210693,
0,
8.432163411953297e-9,
8.432163411953297e-09,
0,
0.14701594412326813,
0,
@@ -17113,7 +17113,7 @@
0,
0.1852506399154663,
0,
-3.894713174190656e-8,
-3.894713174190656e-08,
0,
-0.18525072932243347,
0,
@@ -17143,7 +17143,7 @@
0,
-0.1852508783340454,
0,
1.0625146096288063e-8,
1.0625146096288063e-08,
0,
0.1852508932352066,
0,
@@ -17173,7 +17173,7 @@
0,
0.20535191893577576,
0,
-4.3173230324100587e-8,
-4.3173230324100587e-08,
0,
-0.20535200834274292,
0,
@@ -17203,7 +17203,7 @@
0,
-0.20535218715667725,
0,
1.1778065633905044e-8,
1.1778065633905044e-08,
0,
0.20535220205783844,
0,
@@ -17233,7 +17233,7 @@
0,
0.20535190403461456,
0,
-4.317322677138691e-8,
-4.317322677138691e-08,
0,
-0.20535199344158173,
0,
@@ -17263,7 +17263,7 @@
0,
-0.20535217225551605,
0,
1.1778064745726624e-8,
1.1778064745726624e-08,
0,
0.20535218715667725,
0,
@@ -17293,7 +17293,7 @@
0,
0.1852506548166275,
0,
-3.894713529462024e-8,
-3.894713529462024e-08,
0,
-0.18525072932243347,
0,
@@ -17323,7 +17323,7 @@
0,
-0.1852508932352066,
0,
1.0625146984466483e-8,
1.0625146984466483e-08,
0,
0.1852509081363678,
0,
@@ -17353,7 +17353,7 @@
0,
0.1470157355070114,
0,
-3.0908619663705394e-8,
-3.0908619663705394e-08,
0,
-0.1470157951116562,
0,
@@ -17383,7 +17383,7 @@
0,
-0.14701592922210693,
0,
8.432163411953297e-9,
8.432163411953297e-09,
0,
0.14701594412326813,
0,
@@ -17413,7 +17413,7 @@
0,
0.0943898856639862,
0,
-1.9844549115077825e-8,
-1.9844549115077825e-08,
0,
-0.09438993036746979,
0,
@@ -17443,7 +17443,7 @@
0,
-0.09439001232385635,
0,
5.413780979068861e-9,
5.413780979068861e-09,
0,
0.09439001977443695,
0,
@@ -17473,7 +17473,7 @@
0,
0.03252454474568367,
0,
-6.837966637363024e-9,
-6.837966637363024e-09,
0,
-0.032524559646844864,
0,
@@ -17503,7 +17503,7 @@
0,
-0.03252458572387695,
0,
1.865462007089036e-9,
1.865462007089036e-09,
0,
0.03252458944916725,
0,
@@ -19581,7 +19581,7 @@
"width = 30\n",
"\n",
"camera = cameras.EquirectangularCamera(height=height, width=width)\n",
"vis_camera_rays(camera)\n"
"vis_camera_rays(camera)"
]
},
{
+36 -38
View File
@@ -46,6 +46,7 @@
"outputs": [],
"source": [
"import goat\n",
"\n",
"vis = goat.vis_utils.get_vis()"
]
},
@@ -109,7 +110,7 @@
"# goat.vis_utils.show_box_test(vis)\n",
"num_images_to_show = 200\n",
"for idx in tqdm(list(range(len(dataset_inputs.image_filenames)))[:num_images_to_show]):\n",
" image = imageio.imread(dataset_inputs.image_filenames[idx])[:,:,:3]\n",
" image = imageio.imread(dataset_inputs.image_filenames[idx])[:, :, :3]\n",
"\n",
" num_intrinsics_params = len(dataset_inputs.intrinsics[idx])\n",
" camera_class = get_camera_model(num_intrinsics_params)\n",
@@ -120,16 +121,16 @@
" name = \"train/{:06d}\".format(idx)\n",
" # height = 0.5\n",
" displayed_focal_length = 0.5\n",
" goat.vis_utils.draw_camera_frustum(vis, \n",
" name=name, \n",
" image=image, \n",
" K=K.numpy(), \n",
" goat.vis_utils.draw_camera_frustum(\n",
" vis,\n",
" name=name,\n",
" image=image,\n",
" K=K.numpy(),\n",
" pose=camera_to_world.double().numpy(),\n",
" height=3.0,\n",
" realistic=False,\n",
" displayed_focal_length=0.0\n",
" )\n",
"\n"
" displayed_focal_length=0.0,\n",
" )"
]
},
{
@@ -140,8 +141,8 @@
"outputs": [],
"source": [
"image_dataset = ImageDataset(\n",
" image_filenames=dataset_inputs.image_filenames, downscale_factor=dataset_inputs.downscale_factor\n",
" )\n",
" image_filenames=dataset_inputs.image_filenames, downscale_factor=dataset_inputs.downscale_factor\n",
")\n",
"iter_dataset = CollateIterDataset(\n",
" image_dataset,\n",
" collate_fn=lambda batch_list: collate_batch(\n",
@@ -188,15 +189,16 @@
"def show_batch(batch):\n",
" # set the color of the sampled rays\n",
" c, y, x = [i.flatten() for i in torch.split(batch[\"local_indices\"], 1, dim=-1)]\n",
" batch[\"image\"][c,y,x] = 1.0\n",
" batch[\"image\"][c, y, x] = 1.0\n",
"\n",
" # batch[\"image\"] is num_images, h, w, 3\n",
" images = torch.split(batch[\"image\"], 1, dim=0)\n",
" image_list = [image[0] for image in images]\n",
" image = torch.cat(image_list, dim=1) # cat along the width dimension\n",
" image = torch.cat(image_list, dim=1) # cat along the width dimension\n",
"\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",
"def sample_and_show_batch():\n",
" batch = next(iter(dataloader))\n",
@@ -235,14 +237,16 @@
"skip = 1\n",
"size = 8\n",
"data = []\n",
"data += [go.Scatter3d(\n",
" x=ray_generator.camera_to_world[::skip,0,3],\n",
" y=ray_generator.camera_to_world[::skip,1,3],\n",
" z=ray_generator.camera_to_world[::skip,2,3],\n",
" mode='markers',\n",
" name=\"origins\",\n",
" marker=dict(color='rgba(0, 0, 0, 1)', size=size)\n",
")]"
"data += [\n",
" go.Scatter3d(\n",
" x=ray_generator.camera_to_world[::skip, 0, 3],\n",
" y=ray_generator.camera_to_world[::skip, 1, 3],\n",
" z=ray_generator.camera_to_world[::skip, 2, 3],\n",
" mode=\"markers\",\n",
" name=\"origins\",\n",
" marker=dict(color=\"rgba(0, 0, 0, 1)\", size=size),\n",
" )\n",
"]"
]
},
{
@@ -275,9 +279,13 @@
"source": [
"# near_plane = cfg.graph.network.near_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",
" intersected_ray_bundle.origins + intersected_ray_bundle.directions * intersected_ray_bundle.fars\n",
" ], dim=1).tolist() # (num_rays, 2, 3)\n",
"lines = torch.stack(\n",
" [\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))"
]
},
@@ -302,21 +310,11 @@
" autosize=False,\n",
" width=1000,\n",
" height=1000,\n",
" margin=go.layout.Margin(\n",
" l=50,\n",
" r=50,\n",
" b=100,\n",
" t=100,\n",
" pad=4\n",
" ),\n",
" margin=go.layout.Margin(l=50, r=50, b=100, t=100, pad=4),\n",
" scene=go.layout.Scene(\n",
" aspectmode=\"data\",\n",
" camera=dict(\n",
" up=dict(x=0, y=0, z=1),\n",
" center=dict(x=0, y=0, z=0),\n",
" eye=dict(x=1.25, y=1.25, z=1.25)\n",
" )\n",
" )\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",
" ),\n",
")\n",
"fig = go.Figure(data=data, layout=layout)\n",
"fig.show()"
@@ -338,7 +336,7 @@
"outputs": [],
"source": [
"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": [
"import torch\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",
"media.show_images(torch.moveaxis(grid, 2, 0), cmap=\"plasma\", border=True)\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",
"media.show_images(torch.moveaxis(grid, 2, 0), cmap=\"plasma\", border=True)\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.min(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",
"for level in range(levels):\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)"
]
},
{
+2 -5
View File
@@ -12,11 +12,8 @@ if __name__ == "__main__":
for step in steps:
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("\\", "")
curr_command = f"{compressed}"
compressed = step["run"].replace("\n", ";").replace("\\", "")
curr_command = f"{compressed}"
print("*" * 100)
print(f"Running {curr_command}")