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
This commit is contained in:
Amitav Baruah
2020-10-20 17:14:38 -07:00
committed by Facebook GitHub Bot
parent bf7aca320a
commit 3d1863ce6f
2 changed files with 135 additions and 28 deletions

View File

@@ -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": {