Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

python - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...