#%% Setup.
import numpy as np

from matplotlib import pyplot as plt
from scipy.ndimage import zoom

import keras
from keras.utils import np_utils
import keras.backend as K

from eva.models.gated_pixelcnn import GatedPixelCNN

from eva.util.mutil import generate

INPUTS = {
    'cifar10' : (32, 32, 3),
    'mnist_rgb' : (28, 28, 3),
    'mnist' : (28, 28, 1)
}

#%% Args.
# Input.
TYPE = 'mnist_rgb'

# Model.
FILTERS = 126
BLOCKS = 1
CLASSES = 10

# Generation.
BATCH = 10
LATENT = None

# Parse model.
INPUT = INPUTS[TYPE]
M = GatedPixelCNN(INPUT, FILTERS, BLOCKS, LATENT)
M.load_weights('eva/examples/model.h5')

#%% Choice (Probabilistic).
batch = generate(M, LATENT, BATCH, deterministic=False)
for pic in batch:
    plt.imshow(pic, interpolation='nearest')
    plt.show()

#%% ArgMax (Deterministic)
batch = generate(M, LATENT, BATCH, deterministic=True)
for pic in batch:
    plt.imshow(pic, interpolation='nearest')
    plt.show()

#%% Test generation.
# get_color = lambda model, pixels, cols, row, col, channel, latent=None: model.predict_on_batch(pixels if latent is None else [pixels, latent])[channel][:, row*cols+col]
# to_255 = lambda color: color

# shape = M.input_shape
# pixels = np.zeros(shape=(BATCH,) + (shape if isinstance(shape, tuple) else shape[0])[1:])
# latent_vec = None
# batch, rows, cols, channels = pixels.shape
# for row in range(rows):
#     for col in range(cols):
#         for channel in range(channels):
#             ps = get_color(M, pixels, cols, row, col, channel, latent_vec)
#             if deterministic:
#                 pixels[:, row, col, channel] = to_255(np.array([np.argmax(p) for p in ps]))
#                 continue
#             pixels[:, row, col, channel] = to_255(np.array([np.random.choice(256, p=p) for p in ps]))
# return pixels
# ps = get_color(M, pixels, 32, 0, 1, 0)
# pixels[:, 0, 1, 0] = to_255(np.array([np.random.choice(256, p=p) for p in ps]))
@@ -937,980 +937,4 @@
 w()%0A
-%0A#%25%25 Test generation.%0A# get_color = lambda model, pixels, cols, row, col, channel, latent=None: model.predict_on_batch(pixels if latent is None else %5Bpixels, latent%5D)%5Bchannel%5D%5B:, row*cols+col%5D%0A# to_255 = lambda color: color%0A%0A# shape = M.input_shape%0A# pixels = np.zeros(shape=(BATCH,) + (shape if isinstance(shape, tuple) else shape%5B0%5D)%5B1:%5D)%0A# latent_vec = None%0A# batch, rows, cols, channels = pixels.shape%0A# for row in range(rows):%0A#     for col in range(cols):%0A#         for channel in range(channels):%0A#             ps = get_color(M, pixels, cols, row, col, channel, latent_vec)%0A#             if deterministic:%0A#                 pixels%5B:, row, col, channel%5D = to_255(np.array(%5Bnp.argmax(p) for p in ps%5D))%0A#                 continue%0A#             pixels%5B:, row, col, channel%5D = to_255(np.array(%5Bnp.random.choice(256, p=p) for p in ps%5D))%0A# return pixels%0A# ps = get_color(M, pixels, 32, 0, 1, 0)%0A# pixels%5B:, 0, 1, 0%5D = to_255(np.array(%5Bnp.random.choice(256, p=p) for p in ps%5D))

Delete debugging code