Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read (SVHN) Dataset in python

Tags:

python

numpy

mat

I would like to read using python the following dataset: http://ufldl.stanford.edu/housenumbers/train_32x32.mat

I had loaded this mat file using io.loadmat('train_32x32.mat') but when I am trying to show an images from the above numpy array, I do not get the image with good resolution and coloring.

Any idea how to read and to plot images from this dataset?

like image 357
user3698971 Avatar asked Mar 21 '15 17:03

user3698971


1 Answers

The output of the loadmat function is a dictionary. See the code below:

import numpy as np
import scipy.io as sio
import matplotlib.pyplot as plt
%matplotlib inline

image_ind = 10
train_data = sio.loadmat('train_32x32.mat')

# access to the dict
x_train = train_data['X']
y_train = train_data['y']

# show sample
plt.imshow(x_train[:,:,:,image_ind])
plt.show()


print y_train[image_ind]
like image 132
Godfather Avatar answered Oct 20 '22 03:10

Godfather