Pytorch plot_visualization_util crashes

OrielBanne: <p>hi -</p>
<p>I am using pytorch visualization utilities example (<a href="https://pytorch.org/vision/master/auto_examples/plot_visualization_utils.html" rel="noopener nofollow ugc">https://pytorch.org/vision/master/auto_examples/plot_visualization_utils.html</a>)</p>
<p>I uploaded 2 dog images:</p>
<p>import torchvision.transforms as T<br>
from <a href="http://torchvision.io" rel="noopener nofollow ugc">torchvision.io</a> import read_image</p>
<p>plt.rcParams[“savefig.bbox”] = ‘tight’<br>
torch.manual_seed(1)</p>
<p>def show(imgs):<br>
fix, axs = plt.subplots(ncols=len(imgs), squeeze=False)<br>
for i, img in enumerate(imgs):<br>
img = T.ToPILImage()(img.to(‘cpu’))<br>
axs[0, i].imshow(np.asarray(img))<br>
axs[0, i].set(xticklabels=<span class="chcklst-box fa fa-square-o fa-fw"></span>, yticklabels=<span class="chcklst-box fa fa-square-o fa-fw"></span>, xticks=<span class="chcklst-box fa fa-square-o fa-fw"></span>, yticks=<span class="chcklst-box fa fa-square-o fa-fw"></span>)</p>
<h1><a name="read-dog-images-1" class="anchor" href="#read-dog-images-1"></a>read dog images</h1>
<p>dog1_int = read_image(str(Path(‘assets’) / ‘dog-photo-37.jpg’))<br>
dog2_int = read_image(str(Path(‘assets’) / ‘dog_field.jpg’))</p>
<p>show([dog1_int, dog2_int])</p>
<p>dog1 = transforms.functional.invert(dog1_int.to(torch.float))<br>
dog2 = transforms.functional.invert(dog2_int.to(torch.float))</p>
<p>show([dog1, dog2])<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/8/18f659df5679d72731aa46fc9b6ed6ff49e9a211.png" data-download-href="https://discuss.pytorch.org/uploads/default/18f659df5679d72731aa46fc9b6ed6ff49e9a211" title="Screen Shot 2021-07-29 at 12.17.32"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/8/18f659df5679d72731aa46fc9b6ed6ff49e9a211_2_690x418.png" alt="Screen Shot 2021-07-29 at 12.17.32" data-base62-sha1="3yPgmRjDLwJ55euOQ2aC446ZSWR" width="690" height="418" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/8/18f659df5679d72731aa46fc9b6ed6ff49e9a211_2_690x418.png, https://discuss.pytorch.org/uploads/default/original/3X/1/8/18f659df5679d72731aa46fc9b6ed6ff49e9a211.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/1/8/18f659df5679d72731aa46fc9b6ed6ff49e9a211.png 2x" data-dominant-color="DDDED8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-07-29 at 12.17.32</span><span class="informations">998×606 190 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/6/b6b5ede49fc38b18861029890888f5f38d1f1fb0.png" data-download-href="https://discuss.pytorch.org/uploads/default/b6b5ede49fc38b18861029890888f5f38d1f1fb0" title="Screen Shot 2021-07-29 at 12.17.51"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/6/b6b5ede49fc38b18861029890888f5f38d1f1fb0_2_690x418.png" alt="Screen Shot 2021-07-29 at 12.17.51" data-base62-sha1="q4kGeRbIGDgpxiYZuNACuXq720w" width="690" height="418" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/6/b6b5ede49fc38b18861029890888f5f38d1f1fb0_2_690x418.png, https://discuss.pytorch.org/uploads/default/original/3X/b/6/b6b5ede49fc38b18861029890888f5f38d1f1fb0.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/6/b6b5ede49fc38b18861029890888f5f38d1f1fb0.png 2x" data-dominant-color="DCDDDD"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-07-29 at 12.17.51</span><span class="informations">998×606 198 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>as you see - - the images are totally changed. my guess is I am not using the right interpolation or - I am not using the correct image format.</p>
<p>well - I think I found the issue, see response below.</p>
<p>trying to continue - plot bounding boxes produced by torchvision detection models. this demo causes a crash of the NB:</p>
<p>from torchvision.models.detection import fasterrcnn_resnet50_fpn<br>
from torchvision.transforms.functional import convert_image_dtype</p>
<p>batch_int = torch.stack([dog1_int, dog2_int])<br>
batch = convert_image_dtype(batch_int, dtype=torch.float)</p>
<p>model = fasterrcnn_resnet50_fpn(pretrained=True, progress=False)<br>
model = model.eval()</p>
<p>outputs = model(batch)<br>
print(outputs)</p>
<p>the crash:</p>
<p>Kernel Restarting</p>
<p>The kernel for Documents/pytorch deep learning/faster rcnn/plot_visualization_utils.ipynb appears to have died. It will restart automatically</p>

OrielBanne: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/0/f028c26fa3645b1a5ee39cc4a128f96e56c37fc6.png" data-download-href="https://discuss.pytorch.org/uploads/default/f028c26fa3645b1a5ee39cc4a128f96e56c37fc6" title="Screen Shot 2021-07-29 at 12.34.51"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/0/f028c26fa3645b1a5ee39cc4a128f96e56c37fc6_2_690x418.png" alt="Screen Shot 2021-07-29 at 12.34.51" data-base62-sha1="ygxV1AsHPDCtLUmxAbNYGN8nOZg" width="690" height="418" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/0/f028c26fa3645b1a5ee39cc4a128f96e56c37fc6_2_690x418.png, https://discuss.pytorch.org/uploads/default/original/3X/f/0/f028c26fa3645b1a5ee39cc4a128f96e56c37fc6.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/0/f028c26fa3645b1a5ee39cc4a128f96e56c37fc6.png 2x" data-dominant-color="DADCD6"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-07-29 at 12.34.51</span><span class="informations">998×606 189 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>changing the type worked</p>