import numpy as np
from keras.models import Sequential
from keras.layers import UpSampling2D
We will define an input array and reshape it, to feed it to the model.
# define input data
X = np.array([10, 6, 3, 20])
# show input data for context
print(X)
# reshape input data into one sample a sample with a channel
X = X.reshape((1, 2, 2, 1))
# define model
model = Sequential()
model.add(UpSampling2D(input_shape=(2, 2, 1)))
# summarize the model
model.summary()
# make a prediction with the model
y_pred = model.predict(X)
# reshape output to remove channel to make printing easier
y_pred = y_pred.reshape((4, 4))
# summarize output
print(y_pred)
[10 6 3 20] Model: "sequential_1" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= up_sampling2d_1 (UpSampling2 (None, 4, 4, 1) 0 ================================================================= Total params: 0 Trainable params: 0 Non-trainable params: 0 _________________________________________________________________ [[10. 10. 6. 6.] [10. 10. 6. 6.] [ 3. 3. 20. 20.] [ 3. 3. 20. 20.]]
Define the model as Sequential and add UpSampling to it.
# define model
model = Sequential()
model.add(UpSampling2D(input_shape=(2, 2, 1)))
# summarize the model
model.summary()
y_pred = model.predict(X)
# reshape output to remove channel to make printing easier
y_pred = y_pred.reshape((4, 4))
# summarize output
print(y_pred)