In [1]:
from __future__ import division, print_function, absolute_import

import tflearn
from tflearn.layers.core import input_data, dropout, fully_connected, flatten
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression
import matplotlib.pyplot as plt
import random
import numpy as np

In [2]:
# Data loading and preprocessing
import tflearn.datasets.mnist as mnist
X, Y, testX, testY = mnist.load_data(one_hot=False)
X = X.reshape([-1, 28, 28])
testX = testX.reshape([-1, 28, 28])


Extracting mnist/train-images-idx3-ubyte.gz
Extracting mnist/train-labels-idx1-ubyte.gz
Extracting mnist/t10k-images-idx3-ubyte.gz
Extracting mnist/t10k-labels-idx1-ubyte.gz
/home/ankdesh/installed/anaconda2/envs/tf0.11/lib/python2.7/gzip.py:275: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  chunk = self.extrabuf[offset: offset + size]
/home/ankdesh/installed/anaconda2/envs/tf0.11/lib/python2.7/site-packages/tflearn/datasets/mnist.py:52: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  data = data.reshape(num_images, rows, cols, 1)

In [3]:
indices = [1,2]
Y[indices]


Out[3]:
array([3, 4], dtype=uint8)

In [4]:
NUM_SAMPLES_TO_GEN = 100
WIDTH_SAMPLE = 3
NUM_IMGS_AVAILABLE = X.shape[0]

In [6]:
%matplotlib inline
asd = np.concatenate((X[0],X[1]), axis=1)
print (asd.shape)
plt.imshow (asd, cmap='Greys')


(28, 56)
Out[6]:
<matplotlib.image.AxesImage at 0x7f5162737110>

In [7]:
asd = np.random.randint(0, NUM_IMGS_AVAILABLE, size=WIDTH_SAMPLE)

In [8]:
X_seq = np.empty(shape=(NUM_SAMPLES_TO_GEN, 28, 28 * WIDTH_SAMPLE),dtype='float32')
Y_seq = np.empty(shape=(NUM_SAMPLES_TO_GEN, WIDTH_SAMPLE),dtype='uint8')
for i in range(NUM_SAMPLES_TO_GEN): # For each sample to generate
    indices = np.random.randint(0,NUM_IMGS_AVAILABLE - 1, size=WIDTH_SAMPLE) # generate indices for creating this wide image
    X_seq[i] = np.concatenate(X[indices], axis=1)
    Y_seq[i] = Y[indices]

In [9]:
print (Y_seq[99])
plt.imshow(X_seq[99], cmap='Greys')


[6 5 5]
Out[9]:
<matplotlib.image.AxesImage at 0x7f5162674b90>

In [ ]: