diff --git a/docs/tutorials/bundle_adjustment.ipynb b/docs/tutorials/bundle_adjustment.ipynb index e5dfe700..67862446 100644 --- a/docs/tutorials/bundle_adjustment.ipynb +++ b/docs/tutorials/bundle_adjustment.ipynb @@ -82,6 +82,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", diff --git a/docs/tutorials/camera_position_optimization_with_differentiable_rendering.ipynb b/docs/tutorials/camera_position_optimization_with_differentiable_rendering.ipynb index bf9216a4..ee879db3 100644 --- a/docs/tutorials/camera_position_optimization_with_differentiable_rendering.ipynb +++ b/docs/tutorials/camera_position_optimization_with_differentiable_rendering.ipynb @@ -69,6 +69,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", @@ -99,7 +100,7 @@ "from pytorch3d.io import load_obj\n", "\n", "# datastructures\n", - "from pytorch3d.structures import Meshes, Textures\n", + "from pytorch3d.structures import Meshes\n", "\n", "# 3D transformations functions\n", "from pytorch3d.transforms import Rotate, Translate\n", @@ -108,7 +109,7 @@ "from pytorch3d.renderer import (\n", " FoVPerspectiveCameras, look_at_view_transform, look_at_rotation, \n", " RasterizationSettings, MeshRenderer, MeshRasterizer, BlendParams,\n", - " SoftSilhouetteShader, HardPhongShader, PointLights\n", + " SoftSilhouetteShader, HardPhongShader, PointLights, TexturesVertex,\n", ")" ] }, @@ -175,7 +176,7 @@ "\n", "# Initialize each vertex to be white in color.\n", "verts_rgb = torch.ones_like(verts)[None] # (1, V, 3)\n", - "textures = Textures(verts_rgb=verts_rgb.to(device))\n", + "textures = TexturesVertex(verts_features=verts_rgb.to(device))\n", "\n", "# Create a Meshes object for the teapot. Here we have only one mesh in the batch.\n", "teapot_mesh = Meshes(\n", diff --git a/docs/tutorials/dataloaders_ShapeNetCore_R2N2.ipynb b/docs/tutorials/dataloaders_ShapeNetCore_R2N2.ipynb index 8d7e6e49..15c3f9e0 100644 --- a/docs/tutorials/dataloaders_ShapeNetCore_R2N2.ipynb +++ b/docs/tutorials/dataloaders_ShapeNetCore_R2N2.ipynb @@ -44,6 +44,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", diff --git a/docs/tutorials/deform_source_mesh_to_target_mesh.ipynb b/docs/tutorials/deform_source_mesh_to_target_mesh.ipynb index 030cad59..f6a83206 100644 --- a/docs/tutorials/deform_source_mesh_to_target_mesh.ipynb +++ b/docs/tutorials/deform_source_mesh_to_target_mesh.ipynb @@ -83,6 +83,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", @@ -494,7 +495,7 @@ "bento/extensions/theme/main.css": true }, "colab": { - "name": "FitMesh.ipynb", + "name": "deform_source_mesh_to_target_mesh.ipynb", "provenance": [] }, "kernelspec": { diff --git a/docs/tutorials/fit_textured_mesh.ipynb b/docs/tutorials/fit_textured_mesh.ipynb index 3c4c8250..b751dc3a 100644 --- a/docs/tutorials/fit_textured_mesh.ipynb +++ b/docs/tutorials/fit_textured_mesh.ipynb @@ -61,6 +61,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", diff --git a/docs/tutorials/render_colored_points.ipynb b/docs/tutorials/render_colored_points.ipynb index bab57376..954fd354 100644 --- a/docs/tutorials/render_colored_points.ipynb +++ b/docs/tutorials/render_colored_points.ipynb @@ -43,6 +43,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", diff --git a/docs/tutorials/render_textured_meshes.ipynb b/docs/tutorials/render_textured_meshes.ipynb index 6dca1a3d..1e3033cc 100644 --- a/docs/tutorials/render_textured_meshes.ipynb +++ b/docs/tutorials/render_textured_meshes.ipynb @@ -66,6 +66,7 @@ "source": [ "!pip install torch torchvision\n", "import sys\n", + "import torch\n", "if torch.__version__=='1.6.0+cu101' and sys.platform.startswith('linux'):\n", " !pip install pytorch3d\n", "else:\n", @@ -542,7 +543,7 @@ "source": [ "# We can pass arbirary keyword arguments to the rasterizer/shader via the renderer\n", "# so the renderer does not need to be reinitialized if any of the settings change.\n", - "images = renderer(mesh, cameras=cameras, lights=lights)" + "images = renderer(meshes, cameras=cameras, lights=lights)" ] }, { diff --git a/pytorch3d/renderer/mesh/rasterizer.py b/pytorch3d/renderer/mesh/rasterizer.py index ac0b7402..424cdb44 100644 --- a/pytorch3d/renderer/mesh/rasterizer.py +++ b/pytorch3d/renderer/mesh/rasterizer.py @@ -94,6 +94,12 @@ class MeshRasterizer(nn.Module): msg = "Cameras must be specified either at initialization \ or in the forward pass of MeshRasterizer" raise ValueError(msg) + + n_cameras = len(cameras) + if n_cameras != 1 and n_cameras != len(meshes_world): + msg = "Wrong number (%r) of cameras for %r meshes" + raise ValueError(msg % (n_cameras, len(meshes_world))) + verts_world = meshes_world.verts_padded() # NOTE: Retaining view space z coordinate for now.