From 3d1863ce6f372277f99a42e59c9a9309fd007555 Mon Sep 17 00:00:00 2001 From: Amitav Baruah Date: Tue, 20 Oct 2020 17:14:38 -0700 Subject: [PATCH] Update tutorials to reflect plotly refactor Summary: Change the two affected tutorials to use plot_scene and plot_batch_individually. Reviewed By: nikhilaravi Differential Revision: D24235480 fbshipit-source-id: ca9d73bfb7ccf733efaf16299c15927406d7f2aa --- docs/tutorials/render_colored_points.ipynb | 57 ++++++++--- docs/tutorials/render_textured_meshes.ipynb | 106 +++++++++++++++++--- 2 files changed, 135 insertions(+), 28 deletions(-) diff --git a/docs/tutorials/render_colored_points.ipynb b/docs/tutorials/render_colored_points.ipynb index c6869195..890a0425 100644 --- a/docs/tutorials/render_colored_points.ipynb +++ b/docs/tutorials/render_colored_points.ipynb @@ -67,7 +67,7 @@ "\n", "# Data structures and functions for rendering\n", "from pytorch3d.structures import Pointclouds\n", - "from pytorch3d.vis import AxisArgs, plot_pointclouds\n", + "from pytorch3d.vis import AxisArgs, plot_batch_individually, plot_scene\n", "from pytorch3d.renderer import (\n", " look_at_view_transform,\n", " FoVOrthographicCameras, \n", @@ -294,7 +294,7 @@ "source": [ "### View pointclouds in Plotly figures\n", "\n", - "Here we use the PyTorch3D function `plot_pointclouds` to render the Pointcloud in a Plotly figure. `plot_pointclouds` returns a plotly figure with a trace for each pointcloud." + "Here we use the PyTorch3D function `plot_scene` to render the pointcloud in a Plotly figure. `plot_scene` returns a plotly figure with trace and subplots defined by the input." ] }, { @@ -303,7 +303,11 @@ "metadata": {}, "outputs": [], "source": [ - "plot_pointclouds(point_cloud)" + "plot_scene({\n", + " \"Pointcloud\": {\n", + " \"person\": point_cloud\n", + " }\n", + "})" ] }, { @@ -320,11 +324,38 @@ "outputs": [], "source": [ "point_cloud_batch = Pointclouds(points=[verts, verts + 2], features=[rgb, torch.zeros_like(rgb)])\n", - "# render both in the same plot\n", - "fig = plot_pointclouds(point_cloud_batch)\n", + "# render both in the same plot in different traces\n", + "fig = plot_scene({\n", + " \"Pointcloud\": {\n", + " \"person\": point_cloud_batch[0],\n", + " \"person2\": point_cloud_batch[1]\n", + " }\n", + "})\n", "fig.show()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# render both in the same plot in one trace\n", + "fig = plot_scene({\n", + " \"Pointcloud\": {\n", + " \"2 people\": point_cloud_batch\n", + " }\n", + "})\n", + "fig.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For batches, we can also use `plot_batch_individually` to avoid constructing the scene dictionary ourselves." + ] + }, { "cell_type": "code", "execution_count": null, @@ -332,7 +363,7 @@ "outputs": [], "source": [ "# render both in 1 row in different subplots\n", - "fig2 = plot_pointclouds(point_cloud_batch, in_subplots=True, ncols=2)\n", + "fig2 = plot_batch_individually(point_cloud_batch, ncols=2)\n", "fig2.show()" ] }, @@ -351,7 +382,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can also modify the axis arguments and axis backgrounds, and title our plots." + "We can also modify the axis arguments and axis backgrounds for either function, and title our plots in `plot_batch_individually`." ] }, { @@ -360,11 +391,13 @@ "metadata": {}, "outputs": [], "source": [ - "fig3 = plot_pointclouds(point_cloud_batch, xaxis={\"backgroundcolor\":\"rgb(200, 200, 230)\"},\n", - " yaxis={\"backgroundcolor\":\"rgb(230, 200, 200)\"},\n", - " zaxis={\"backgroundcolor\":\"rgb(200, 230, 200)\"}, \n", - " subplot_titles=[\"2 pointclouds\"], # this should have a title for each subplot, titles can be \"\"\n", - " axis_args=AxisArgs(showgrid=True))\n", + "fig3 = plot_batch_individually(\n", + " point_cloud_batch, \n", + " xaxis={\"backgroundcolor\":\"rgb(200, 200, 230)\"},\n", + " yaxis={\"backgroundcolor\":\"rgb(230, 200, 200)\"},\n", + " zaxis={\"backgroundcolor\":\"rgb(200, 230, 200)\"}, \n", + " subplot_titles=[\"Pointcloud1\", \"Pointcloud2\"], # this should have a title for each subplot, titles can be \"\"\n", + " axis_args=AxisArgs(showgrid=True))\n", "fig3.show()" ] } diff --git a/docs/tutorials/render_textured_meshes.ipynb b/docs/tutorials/render_textured_meshes.ipynb index 01a9433c..0c5426a9 100644 --- a/docs/tutorials/render_textured_meshes.ipynb +++ b/docs/tutorials/render_textured_meshes.ipynb @@ -93,7 +93,7 @@ "\n", "# Data structures and functions for rendering\n", "from pytorch3d.structures import Meshes\n", - "from pytorch3d.vis import AxisArgs, plot_meshes\n", + "from pytorch3d.vis import AxisArgs, plot_batch_individually, plot_scene\n", "from pytorch3d.renderer import (\n", " look_at_view_transform,\n", " FoVPerspectiveCameras, \n", @@ -587,7 +587,11 @@ ")\n", "\n", "# Render the plotly figure\n", - "fig = plot_meshes(mesh)\n", + "fig = plot_scene({\n", + " \"subplot1\": {\n", + " \"cow_mesh\": mesh\n", + " }\n", + "})\n", "fig.show()" ] }, @@ -604,7 +608,12 @@ ")\n", "\n", "# Render the plotly figure\n", - "plot_meshes(mesh)" + "fig = plot_scene({\n", + " \"subplot1\": {\n", + " \"cow_mesh\": mesh\n", + " }\n", + "})\n", + "fig.show()" ] }, { @@ -619,7 +628,54 @@ " faces=[faces.to(device), faces.to(device)]\n", ")\n", "\n", - "plot_meshes(mesh_batch)" + "# plot mesh batch in the same trace\n", + "fig = plot_scene({\n", + " \"subplot1\": {\n", + " \"cow_mesh_batch\": mesh_batch\n", + " }\n", + "})\n", + "fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# plot batch of meshes in different traces\n", + "fig = plot_scene({\n", + " \"subplot1\": {\n", + " \"cow_mesh1\": mesh_batch[0],\n", + " \"cow_mesh2\": mesh_batch[1]\n", + " }\n", + "})\n", + "fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# plot batch of meshes in different subplots\n", + "fig = plot_scene({\n", + " \"subplot1\": {\n", + " \"cow_mesh1\": mesh_batch[0]\n", + " },\n", + " \"subplot2\":{\n", + " \"cow_mesh2\": mesh_batch[1]\n", + " }\n", + "})\n", + "fig.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For batches, we can also use `plot_batch_individually` to avoid constructing the scene dictionary ourselves." ] }, { @@ -629,15 +685,12 @@ "outputs": [], "source": [ "# extend the batch to have 4 meshes\n", - "mesh = mesh_batch.extend(2)\n", + "mesh_4 = mesh_batch.extend(2)\n", "\n", "# visualize the batch in different subplots, 2 per row\n", - "# title the subplots\n", - "fig = plot_meshes(mesh, in_subplots=True, ncols=2,\n", - " subplot_titles = [\"cow\" + str(i) for i in range(1,5)] # this should have a title for each subplot, titles can be \"\"\n", - " )\n", + "fig = plot_batch_individually(mesh_4)\n", "# we can update the figure height and width\n", - "fig.update_layout(height=500, width=500)\n", + "fig.update_layout(height=1000, width=500)\n", "fig.show()" ] }, @@ -645,7 +698,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can also modify the axis arguments and axis backgrounds." + "We can also modify the axis arguments and axis backgrounds in both functions. " ] }, { @@ -654,14 +707,35 @@ "metadata": {}, "outputs": [], "source": [ - "fig2 = plot_meshes(mesh_batch, xaxis={\"backgroundcolor\":\"rgb(200, 200, 230)\"},\n", - " yaxis={\"backgroundcolor\":\"rgb(230, 200, 200)\"},\n", - " zaxis={\"backgroundcolor\":\"rgb(200, 230, 200)\"}, \n", - " subplot_titles=[\"2 meshes\"],\n", - " axis_args=AxisArgs(showgrid=True))\n", + "fig2 = plot_scene({\n", + " \"cow_plot1\": {\n", + " \"cows\": mesh_batch\n", + " }\n", + "},\n", + " xaxis={\"backgroundcolor\":\"rgb(200, 200, 230)\"},\n", + " yaxis={\"backgroundcolor\":\"rgb(230, 200, 200)\"},\n", + " zaxis={\"backgroundcolor\":\"rgb(200, 230, 200)\"}, \n", + " axis_args=AxisArgs(showgrid=True))\n", "fig2.show()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig3 = plot_batch_individually(\n", + " mesh_4, \n", + " ncols=2,\n", + " subplot_titles = [\"cow1\", \"cow2\", \"cow3\", \"cow4\"], # customize subplot titles\n", + " xaxis={\"backgroundcolor\":\"rgb(200, 200, 230)\"},\n", + " yaxis={\"backgroundcolor\":\"rgb(230, 200, 200)\"},\n", + " zaxis={\"backgroundcolor\":\"rgb(200, 230, 200)\"}, \n", + " axis_args=AxisArgs(showgrid=True))\n", + "fig3.show()" + ] + }, { "cell_type": "markdown", "metadata": {