Pytorch plot_visualization_util crashes

hi -

I am using pytorch visualization utilities example (Visualization utilities — Torchvision master documentation)

I uploaded 2 dog images:

import torchvision.transforms as T
from torchvision.io import read_image

plt.rcParams[“savefig.bbox”] = ‘tight’
torch.manual_seed(1)

def show(imgs):
fix, axs = plt.subplots(ncols=len(imgs), squeeze=False)
for i, img in enumerate(imgs):
img = T.ToPILImage()(img.to(‘cpu’))
axs[0, i].imshow(np.asarray(img))
axs[0, i].set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])

read dog images

dog1_int = read_image(str(Path(‘assets’) / ‘dog-photo-37.jpg’))
dog2_int = read_image(str(Path(‘assets’) / ‘dog_field.jpg’))

show([dog1_int, dog2_int])

dog1 = transforms.functional.invert(dog1_int.to(torch.float))
dog2 = transforms.functional.invert(dog2_int.to(torch.float))

show([dog1, dog2])


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.

well - I think I found the issue, see response below.

trying to continue - plot bounding boxes produced by torchvision detection models. this demo causes a crash of the NB:

from torchvision.models.detection import fasterrcnn_resnet50_fpn
from torchvision.transforms.functional import convert_image_dtype

batch_int = torch.stack([dog1_int, dog2_int])
batch = convert_image_dtype(batch_int, dtype=torch.float)

model = fasterrcnn_resnet50_fpn(pretrained=True, progress=False)
model = model.eval()

outputs = model(batch)
print(outputs)

the crash:

Kernel Restarting

The kernel for Documents/pytorch deep learning/faster rcnn/plot_visualization_utils.ipynb appears to have died. It will restart automatically

changing the type worked