application_vnd.jupyter.stderr_output_9.png application_vnd.jupyter.stderr_output_7.png application_vnd.jupyter.stderr_output_11.png text_plain_output_4.png text_plain_output_10.png text_plain_output_6.png application_vnd.jupyter.stderr_output_3.png application_vnd.jupyter.stderr_output_5.png text_plain_output_8.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png image_output_1.png text_plain_output_12.png
from PIL import Image

from io import BytesIO

from torchvision import datasets, models, transforms

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import torch

train_on_gpu = torch.cuda.is_available()

data_dir = '../input'
train_dir = data_dir + '/train'
test_dir = data_dir + '/test'

pil2tensor = transforms.ToTensor()
tensor2pil = transforms.ToPILImage()
pil_image = Image.open(train_dir + '/0a750c2e8.jpg')
rgb_image = pil2tensor(pil_image)
def plot_image(tensor):
    pass

from io import BytesIO
import IPython.display
r_image = rgb_image[0]
g_image = rgb_image[1]
b_image = rgb_image[2]
def show_grayscale_image(tensor):
    f = BytesIO()
    a = np.uint8(tensor.mul(255).numpy())
    Image.fromarray(a).save(f, 'png')
    IPython.display.display(IPython.display.Image(data=f.getvalue()))
show_grayscale_image(torch.cat((r_image, g_image, b_image), 1))