Last active
November 27, 2018 23:31
-
-
Save jamesonthecrow/0caad8d2f21a48f056a2727e43e7fd79 to your computer and use it in GitHub Desktop.
An illustration of fast artistic style transfer with a width multiplier included.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def build( | |
cls, | |
image_size, | |
alpha=1.0, | |
input_tensor=None, | |
checkpoint_file=None): | |
"""Build a Transfer Network Model using keras' functional API. | |
Args: | |
image_size - the size of the input and output image (H, W) | |
alpha - a width parameter to scale the number of channels by | |
Returns: | |
model: a keras model object | |
""" | |
x = keras.layers.Input( | |
shape=(image_size[0], image_size[1], 3), tensor=input_tensor) | |
out = cls._convolution(x, int(alpha * 32), 9, strides=1) | |
out = cls._convolution(out, int(alpha * 64), 3, strides=2) | |
out = cls._convolution(out, int(alpha * 128), 3, strides=2) | |
out = cls._residual_block(out, int(alpha * 128)) | |
out = cls._residual_block(out, int(alpha * 128)) | |
out = cls._residual_block(out, int(alpha * 128)) | |
out = cls._residual_block(out, int(alpha * 128)) | |
out = cls._residual_block(out, int(alpha * 128)) | |
out = cls._upsample(out, int(alpha * 64), 3) | |
out = cls._upsample(out, int(alpha * 32), 3) | |
out = cls._convolution(out, 3, 9, relu=False, padding='same') | |
# Restrict outputs of pixel values to -1 and 1. | |
out = keras.layers.Activation('tanh')(out) | |
# Deprocess the image into valid image data. Note we'll need to define | |
# a custom layer for this in Core ML as well. | |
out = layers.DeprocessStylizedImage()(out) | |
model = keras.models.Model(inputs=x, outputs=out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment