mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-15 12:23:46 +08:00
Run black on ipynb (#80)
This commit is contained in:
1 parent
fb440fedf3
commit
443fdef553
6 files changed
+69
-76
No files matched your search
@@ -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\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user