Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading an image from cifar-10 dataset

I am using cifar-10 dataset for my training my classifier. I have downloaded the dataset and tried to display am image from the dataset. I have used the following code:

from six.moves import cPickle as pickle
from  PIL import Image
import numpy as np

f = open('/home/jayanth/udacity/cifar-10-batches-py/data_batch_1', 'rb')

tupled_data= pickle.load(f, encoding='bytes')

f.close()

img = tupled_data[b'data']

single_img = np.array(img[5])

single_img_reshaped = single_img.reshape(32,32,3)

plt.imshow(single_img_reshaped)

the description of data is as follows: Each array stores a 32x32 colour image. The first 1024 entries contain the red channel values, the next 1024 the green, and the final 1024 the blue. The image is stored in row-major order, so that the first 32 entries of the array are the red channel values of the first row of the image.

Is my implementation correct?

the above code gave me the following image: enter image description here

like image 222
Jayanth Avatar asked Jul 14 '17 14:07

Jayanth


People also ask

How do I load a CIFAR-10 dataset?

Utility to load cifar-10 image data into training and test data sets. Download the cifar-10 python version dataset from here, and extract the cifar-10-batches-py folder into the same directory as the load_cifar_10.py script. The code contains example usage, and runs under Python 3 only.

Do CIFAR-10 and cifar100 have same images?

The test sets of the popular CIFAR-10 and CIFAR-100 datasets contain 3.25% and 10% duplicate images, respectively, i.e., images that can also be found in very similar form in the training set or the test set itself.

Is CIFAR-10 a subset of Imagenet?

CIFAR-10 is a labeled subset of the 80 million tiny images dataset.

How to load CIFAR-10 image data into training and test data sets?

Utility to load cifar-10 image data into training and test data sets. Download the cifar-10 python version dataset from here, and extract the cifar-10-batches-py folder into the same directory as the load_cifar_10.py script. The code contains example usage, and runs under Python 3 only.

What is the size of the cifar-100 dataset?

CIFAR-100 dataset also consists of 60,000 color images of 32x32 size. It has 100 classes, each contains 600 images. Per class, there are 500 trading images and 100 testing images.

What is the difference between CIFAR-10 and cifar-100?

The CIFAR-10 dataset consists of 60,000 color images of 32x32 size. The dataset has 10 classes, each class having 6,000 images. The dataset is divided in to two group training and testing images: 50,000 training images, 10,000 testing images. CIFAR-100 dataset also consists of 60,000 color images of 32x32 size.

How do I use CIFAR-10 with Python?

Download the cifar-10 python version dataset from here, and extract the cifar-10-batches-py folder into the same directory as the load_cifar_10.py script. The code contains example usage, and runs under Python 3 only. Note that the load_cifar_10_data () function has the option to load the images as negatives using negatives=True.


2 Answers

Since Python uses the default C-like indexing order (row-major order), it can be forced to work in column-major order:

import numpy as np
import matplotlib.pyplot as plt

# I assume you have loaded your data into x_train (see some tutorial)

data = x_train[0, :] # get a row data
data = np.reshape(data, (32,32,3), order='F' ) # Fortran-like indexing order
plt.imshow(data)
like image 177
Carl Avatar answered Sep 30 '22 01:09

Carl


I used

single_img_reshaped = np.transpose(np.reshape(single_img,(3, 32,32)), (1,2,0))

to get the correct format in my program.

like image 39
Thomas Pinetz Avatar answered Sep 30 '22 03:09

Thomas Pinetz