# Illustrate upsampling in 2d
# Code from Jason Brownlee
# https://machinelearningmastery.com/generative_adversarial_networks/


import tensorflow as tf
from tensorflow import keras

from numpy import asarray

#from keras.models import Sequential
from tensorflow.keras.models import Sequential

#from keras.layers import UpSampling2D
from tensorflow.keras.layers import UpSampling2D

X = asarray([[1, 2],
			 [3, 4]])

X = asarray([[1, 2, 3],
			 [4, 5, 6],
             [7,8,9]])
print(X)
nr = X.shape[0]
nc = X.shape[1]
 
# reshape input data into one sample a sample with a channel
X = X.reshape((1, nr, nc, 1))

model = Sequential()
model.add(UpSampling2D(input_shape=(nr, nc, 1))) # nearest neighbor

yhat = model.predict(X)
yhat = yhat.reshape((2*nr, 2*nc))
print(yhat)

model = Sequential()
model.add(UpSampling2D(input_shape=(nc, nc, 1), interpolation='bilinear'))

yhat = model.predict(X)
yhat = yhat.reshape((2*nr, 2*nc))
print(yhat)
[((17, 4, 18, 12), 'numpy.asarray', 'asarray', ({(17, 12, 18, 11): '[[1, 2], [3, 4]]'}, {}), '([[1, 2], [3, 4]])', False, 'from numpy import asarray\n'), ((20, 4, 22, 22), 'numpy.asarray', 'asarray', ({(20, 12, 22, 21): '[[1, 2, 3], [4, 5, 6], [7, 8, 9]]'}, {}), '([[1, 2, 3], [4, 5, 6], [7, 8, 9]])', False, 'from numpy import asarray\n'), ((30, 8, 30, 20), 'tensorflow.keras.models.Sequential', 'Sequential', ({}, {}), '()', False, 'from tensorflow.keras.models import Sequential\n'), ((37, 8, 37, 20), 'tensorflow.keras.models.Sequential', 'Sequential', ({}, {}), '()', False, 'from tensorflow.keras.models import Sequential\n'), ((31, 10, 31, 47), 'tensorflow.keras.layers.UpSampling2D', 'UpSampling2D', (), '', False, 'from tensorflow.keras.layers import UpSampling2D\n'), ((38, 10, 38, 73), 'tensorflow.keras.layers.UpSampling2D', 'UpSampling2D', (), '', False, 'from tensorflow.keras.layers import UpSampling2D\n')]