Skip to content

Instantly share code, notes, and snippets.

@whenyd
Created February 11, 2018 02:47
Show Gist options
  • Save whenyd/7f2a58aa8b93446a1bd7b140c0937f04 to your computer and use it in GitHub Desktop.
Save whenyd/7f2a58aa8b93446a1bd7b140c0937f04 to your computer and use it in GitHub Desktop.
Up-resolution using transposed convolution.
from keras.models import Model
from keras.layers import Input, Conv2D, MaxPooling2D, Conv2DTranspose
input_img = Input(shape=(224, 224, 3))
x = Conv2D(16, (3, 3), padding='same', activation='relu')(input_img)
x = MaxPooling2D((2, 2))(x)
x = MaxPooling2D((2, 2))(x)
x_8x = MaxPooling2D((2, 2))(x)
x_16x = MaxPooling2D((2, 2))(x_8x)
x_32x = MaxPooling2D((2, 2))(x_16x)
# I think the last two layers are not necessary.
# x_32x = Conv2D(16, (7, 7), activation='relu')(x_32x)
# x_32x = Conv2D(16, (1, 1), activation='relu')(x_32x)
# It should be reshaped to 7x7.
up_32x = Conv2DTranspose(1, (64, 64), strides=32, padding='same')(x_32x)
model = Model(input_img, up_32x)
print(model.output_shape)
# >>> (None, 224, 224, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment