Cnat view .png grayscle images using follwing code

Schroter: <p>Hi All,</p>
<p>I am trying to create an image classifier using <a href="https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html" rel="noopener nofollow ugc">this tutorial</a>. In my case, I am trying to use gray scale .png images. However, when viewing the images it is not shown properly as below. Please, find the relavant code and output below.</p>
<pre><code class="lang-auto"># Data augmentation and normalization for training
# Just normalization for validation
data_transforms = {
    'train': transforms.Compose([
        transforms.RandomResizedCrop(224),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
    'val': transforms.Compose([
        transforms.Resize(256),
        transforms.CenterCrop(224),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
}

data_dir = 'data/hymenoptera_data'
image_datasets = {x: datasets.ImageFolder(os.path.join(data_dir, x),
                                          data_transforms[x])
                  for x in ['train', 'val']}
dataloaders = {x: torch.utils.data.DataLoader(image_datasets[x], batch_size=4,
                                             shuffle=True, num_workers=4)
              for x in ['train', 'val']}
dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val']}
class_names = image_datasets['train'].classes

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

def imshow(inp, title=None):
    """Display image for Tensor."""
    inp = inp.numpy().transpose((1, 2, 0))
    mean = np.array([0.485, 0.456, 0.406])
    std = np.array([0.229, 0.224, 0.225])
    inp = std * inp + mean
    inp = np.clip(inp, 0, 1)
    plt.imshow(inp)
    if title is not None:
        plt.title(title)
    plt.pause(0.001)  # pause a bit so that plots are updated


# Get a batch of training data
inputs, classes = next(iter(dataloaders['train']))

# Make a grid from batch
out = torchvision.utils.make_grid(inputs)

imshow(out, title=[class_names[x] for x in classes])

</code></pre>
<p>Output images:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/d/3dc15921db3d3bc2faac241859b72e09ea3d4dfe.png" data-download-href="https://discuss.pytorch.org/uploads/default/3dc15921db3d3bc2faac241859b72e09ea3d4dfe" title="Screen Shot 2023-09-23 at 7.51.12 pm"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/d/3dc15921db3d3bc2faac241859b72e09ea3d4dfe_2_689x239.png" alt="Screen Shot 2023-09-23 at 7.51.12 pm" data-base62-sha1="8Ojn4UWwbYuzMj3EVZhGJ9snRx4" width="689" height="239" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/d/3dc15921db3d3bc2faac241859b72e09ea3d4dfe_2_689x239.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/d/3dc15921db3d3bc2faac241859b72e09ea3d4dfe_2_1033x358.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/d/3dc15921db3d3bc2faac241859b72e09ea3d4dfe.png 2x" data-dominant-color="E0E1E1"><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 2023-09-23 at 7.51.12 pm</span><span class="informations">1106×384 68.3 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>
The actual images should look somthing like below.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/3/3301ebee708728e6456892e143d5bcfd5b9eddff.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/3301ebee708728e6456892e143d5bcfd5b9eddff" title="A_1403_1.RIGHT_CC"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/3301ebee708728e6456892e143d5bcfd5b9eddff_2_246x500.jpeg" alt="A_1403_1.RIGHT_CC" data-base62-sha1="7het13yGSlFOI3zBHv6BH0dvzun" width="246" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/3301ebee708728e6456892e143d5bcfd5b9eddff_2_246x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/3301ebee708728e6456892e143d5bcfd5b9eddff_2_369x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/3301ebee708728e6456892e143d5bcfd5b9eddff_2_492x1000.jpeg 2x" data-dominant-color="242424"><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">A_1403_1.RIGHT_CC</span><span class="informations">1493×3023 83.9 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>Would anyone be able to help me in this matter.</p>
<p>Thanks &amp; Best Regards</p>
<p>Michael</p>