Inspecting the sequence dataset

Data

Full games are represented as image sequences ("movies"). The network has to predict the next frame of an unfinished sequence.

In [2]:
import numpy as np
import imageio
from matplotlib.pyplot import imshow
%matplotlib inline
import keras.backend as K
from keras.utils.np_utils import to_categorical
import random
Using TensorFlow backend.
In [3]:
sequenceDataset = np.load('sequence5x4.npz')
In [4]:
games = sequenceDataset['games']
print(games.shape)
(1000, 49, 11, 13)
In [5]:
exampleGameIdx = 4
exampleGameFrame = 47
game = games[exampleGameIdx]
print(game[exampleGameFrame])
[[  0   0   0   0   0   0   0   0   0   0   0   0   0]
 [  0 215 255 215 255 215 255 215 255 215 255 215   0]
 [  0 255 150 255 150 255 150 255 150 255  65 255   0]
 [  0 215 255 215 255 215 255 215 255 215 255 215   0]
 [  0 255 150 255 150 255 150 255 150 255  65 255   0]
 [  0 215 255 215 255 215 255 215 255 215 255 215   0]
 [  0 255 150 255 150 255 150 255 150 255   0   0   0]
 [  0 215 255 215 255 215 255 215 255 215 255 215   0]
 [  0 255 150 255 150 255  65 255  65 255 150 255   0]
 [  0 215 255 215 255 215 255 215 255 215 255 215   0]
 [  0   0   0   0   0   0   0   0   0   0   0   0   0]]
In [6]:
imageio.mimwrite('test.gif', game)

Dots and Boxes game animation

In [7]:
game2 = np.kron(game, np.ones((10,10), dtype=np.uint8))
imageio.mimwrite('test2.gif', game2)

Dots and Boxes game animation

In [8]:
x_train = games[:,:-1,:,:]
y_train = games[:,1:,:,:]
print(x_train.shape)
print(y_train.shape)

x_train = x_train.astype(K.floatx())
y_train = y_train.astype(K.floatx())
x_train /= 255
y_train /= 255
(1000, 48, 11, 13)
(1000, 48, 11, 13)
In [9]:
np.set_printoptions(precision=2, suppress=True, linewidth=90)

print(x_train[exampleGameIdx,exampleGameFrame])
print(y_train[exampleGameIdx,exampleGameFrame])
print(x_train.shape)
print(y_train.shape)
[[ 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.25  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.25  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.    0.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.25  1.    0.25  1.    0.59  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.  ]]
[[ 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.25  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.25  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.59  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    1.    0.59  1.    0.59  1.    0.25  1.    0.25  1.    0.59  1.    0.  ]
 [ 0.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  1.    0.84  0.  ]
 [ 0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.    0.  ]]
(1000, 48, 11, 13)
(1000, 48, 11, 13)
In [13]:
cat_shape = y_train.shape + (2,)
y_cat = to_categorical(y_train).reshape(cat_shape)
print(y_cat.shape)
print(y_cat[exampleGameIdx,exampleGameFrame,:,:,0])
print(y_cat[exampleGameIdx,exampleGameFrame,:,:,1])
(1000, 48, 11, 13, 2)
[[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
 [ 1.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  1.]
 [ 1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.]
 [ 1.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  1.]
 [ 1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.]
 [ 1.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  1.]
 [ 1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.]
 [ 1.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  1.]
 [ 1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.]
 [ 1.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  1.]
 [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]]
[[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  0.]
 [ 0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.]
 [ 0.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  0.]
 [ 0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.]
 [ 0.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  0.]
 [ 0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.]
 [ 0.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  0.]
 [ 0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.]
 [ 0.  0.  1.  0.  1.  0.  1.  0.  1.  0.  1.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
In [ ]: