In [ ]:
!pip install six pypng pillow

In [1]:
import PIL
from PIL import Image
from PIL import ImageFilter, ImageEnhance
import numpy as np
import matplotlib.pyplot as plt
import six
from six.moves import cPickle as pickle
import png
import os

In [15]:
def extractImagesAndLabels(path, file, dataset):
    f = open(path+file, 'rb')
    dict = pickle.load(f)
    images = dict[dataset]
    labels = dict['labels']
    return images, labels, dict

def extractCategories(path, file):
    f = open(path+file, 'rb')
    dict = pickle.load(f)
    return dict['label_names']

def getImage(images, id):
    reshapedimages = np.reshape(images, (10000, 100, 100, 3))
    print(reshapedimages.shape)
    image = reshapedimages[id]
    #image = image.transpose([1, 2, 0])
    image = image.astype('float32')
    image /= 255
    return image

def showImage(id):
    image = getImage(images,id)
    %matplotlib inline
    imgplot = plt.imshow(image)
    labelid = labels[id]
    category = categories[labelid]
    print("category : "+category)

In [5]:
image_dims = 100
images, labels, datadict = extractImagesAndLabels("data/CIFAR-10/cifar-10-batches-py/", "test_batch_100", "bigdata")
categories = extractCategories("data/CIFAR-10/cifar-10-batches-py/", "batches.meta")

In [20]:
print(len(images))
print(images[1].shape)

imgid=39
image = getImage(images, imgid)
print(image.shape)
%matplotlib inline
imgplot = plt.imshow(image)
categoryid = labels[imgid]
print(categories[categoryid])


10000
(30000,)
(10000, 100, 100, 3)
(100, 100, 3)
dog

In [ ]: