From 1c45ec9770ee3010477272e4cd5387f9ccb8cb51 Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Wed, 14 Apr 2021 12:51:18 -0700 Subject: [PATCH] Avoid gradients when rendering for visualization Summary: The renderer gets used for visualization only in places. Here we avoid creating an autograd graph during that, which is not needed and can fail because some of the graph which existed earlier might be needed and has not been retained after the optimizer step. See https://github.com/facebookresearch/pytorch3d/issues/624 Reviewed By: gkioxari Differential Revision: D27593018 fbshipit-source-id: 62ae7a5a790111273aa4c566f172abd36c844bfb --- docs/tutorials/fit_textured_mesh.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/tutorials/fit_textured_mesh.ipynb b/docs/tutorials/fit_textured_mesh.ipynb index 83ad5c73..4e3287ad 100644 --- a/docs/tutorials/fit_textured_mesh.ipynb +++ b/docs/tutorials/fit_textured_mesh.ipynb @@ -455,7 +455,8 @@ " target_image=target_rgb[1], title='', \n", " silhouette=False):\n", " inds = 3 if silhouette else range(3)\n", - " predicted_images = renderer(predicted_mesh)\n", + " with torch.no_grad():\n", + " predicted_images = renderer(predicted_mesh)\n", " plt.figure(figsize=(20, 10))\n", " plt.subplot(1, 2, 1)\n", " plt.imshow(predicted_images[0, ..., inds].cpu().detach().numpy())\n",