Why CIFAR-10 images are not displayed properly using matplotlib?

前端 未结 9 853
独厮守ぢ
独厮守ぢ 2021-02-06 12:28

From the training set I took a image(\'img\') of size (3,32,32). I have used plt.imshow(img.T). The image is not clear. Now changes I have to make to image(\'img\') to make it m

9条回答
  •  失恋的感觉
    2021-02-06 13:08

    Following prints 5X5 grid of random Cifar10 images. It isn't blurry, though not perfect either. Any suggestions welcome.

    %matplotlib inline
    import numpy as np
    import matplotlib.pyplot as plt
    from six.moves import cPickle 
    
    f = open('data/cifar10/cifar-10-batches-py/data_batch_1', 'rb')
    datadict = cPickle.load(f,encoding='latin1')
    f.close()
    X = datadict["data"] 
    Y = datadict['labels']
    X = X.reshape(10000, 3, 32, 32).transpose(0,2,3,1).astype("uint8")
    Y = np.array(Y)
    
    #Visualizing CIFAR 10
    fig, axes1 = plt.subplots(5,5,figsize=(3,3))
    for j in range(5):
        for k in range(5):
            i = np.random.choice(range(len(X)))
            axes1[j][k].set_axis_off()
            axes1[j][k].imshow(X[i:i+1][0])
    

提交回复
热议问题