Skip to content

Instantly share code, notes, and snippets.

@tishibas
Created April 13, 2015 02:52
Show Gist options
  • Save tishibas/8830b18481a6ef58bf7c to your computer and use it in GitHub Desktop.
Save tishibas/8830b18481a6ef58bf7c to your computer and use it in GitHub Desktop.
How does the mat file which can be obtained from SVHN convert to image file.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import scipy.io
import scipy.misc
train_data = scipy.io.loadmat("train_32x32.mat")
train_x = train_data['X']
train_y = [flatten for inner in train_data['y'] for flatten in inner]
print train_x.shape
f = open('train_data.txt', 'w')
for i in range(train_x.shape[3]):
img_name = "img/train%08d.png" % i
scipy.misc.imsave(img_name, train_x[:,:,:,i])
f.write(img_name + "\t" + str(train_y[i]) + "\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment