<jupyter_start><jupyter_text><jupyter_code>from numpy import asarray
from keras.models import Sequential
from keras.layers import UpSampling2D

X = asarray([[4, 7],
			 [9, 14]])
print(X)

X = X.reshape((1, 2, 2, 1))

model = Sequential()
model.add(UpSampling2D(input_shape=(2, 2, 1)))
model.add(UpSampling2D(size = (4,4)))

model.summary()

yhat = model.predict(X)

yhat = yhat.reshape((16, 16))

print(yhat)
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Reshape
from keras.layers import UpSampling2D
from keras.layers import Conv2D

model = Sequential()
model.add(Dense(128 * 5 * 5, input_dim=100))
model.add(Reshape((5, 5, 128)))
model.add(UpSampling2D())
model.add(Conv2D(1, (3,3), padding='same'))

model.summary()
# example of using the transpose convolutional layer
from numpy import asarray
from keras.models import Sequential
from keras.layers import Conv2DTranspose

X = asarray([[21, 32],
			 [33, 46]])

print(X)

X = X.reshape((1, 2, 2, 1))

model = Sequential()
model.add(Conv2DTranspose(1, (1,1), strides=(2,2), input_shape=(2, 2, 1)))
model.summary()
weights = [asarray([[[[1]]]]), asarray([0])]
model.set_weights(weights)
yhat = model.predict(X)
yhat = yhat.reshape((4, 4))
print(yhat)
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Reshape
from keras.layers import Conv2DTranspose
from keras.layers import Conv2D

model = Sequential()
model.add(Dense(128 * 5 * 5, input_dim=100))
model.add(Reshape((5, 5, 128)))
model.add(Conv2DTranspose(1, (3,3), strides=(2,2), padding='same'))
model.summary()<jupyter_output>Model: "sequential_12"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 3200)              323200    
_________________________________________________________________
reshape_1 (Reshape)          (None, 5, 5, 128)         0         
_________________________________________________________________
conv2d_transpose_1 (Conv2DTr (None, 10, 10, 1)         1153      
=================================================================
Total params: 324,353
Trainable params: 324,353
Non-trainable params: 0
_________________________________________________________________
{'fraction_non_alphanumeric': 0.17312552653748947, 'fraction_numerical': 0.05602358887952822, 'mean_word_length': 5.350267379679145, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '427351', 'license': 'MIT', 'n_tokens_mistral': 841, 'n_tokens_neox': 747, 'n_words': 188, 'path': 'Daily Practice/UpSampling2DPractice.ipynb', 'repo_name': 'DJ-python/github-slideshow', 'size': '2374'}