├── AdaIN.py ├── LICENSE ├── Models ├── dis.json ├── dis_101.h5 ├── gen.json ├── gen_101.h5 ├── sty.json └── sty_101.h5 ├── README.md ├── Results ├── i1003ii.jpg ├── i1003mm.jpg ├── i1003tt.jpg ├── i1004ii.jpg ├── i1004mm.jpg ├── i1004tt.jpg ├── i1005ii.jpg ├── i1005mm.jpg ├── i1005tt.jpg ├── i1006ii.jpg ├── i1006mm.jpg ├── i1006tt.jpg ├── i1007ii.jpg ├── i1007mm.jpg ├── i1007tt.jpg ├── i1008ii.jpg ├── i1008mm.jpg ├── i1008tt.jpg ├── i1009ii.jpg ├── i1009mm.jpg ├── i1009tt.jpg ├── i1010ii.jpg ├── i1010mm.jpg ├── i1010tt.jpg ├── i1011ii.jpg ├── i1011mm.jpg ├── i1011tt.jpg ├── i308.jpg └── i325.jpg ├── adamlr.py ├── data ├── Earth-256 │ ├── im (1).jpg │ └── im (2).jpg └── Flowers │ ├── im (1).jpg │ └── im (2).jpg ├── mixed-stylegan.py └── stylegan.py /AdaIN.py: -------------------------------------------------------------------------------- 1 | from keras.layers import Layer 2 | from keras import backend as K 3 | 4 | #Input b and g should be 1x1xC 5 | class AdaInstanceNormalization(Layer): 6 | def __init__(self, 7 | axis=-1, 8 | momentum=0.99, 9 | epsilon=1e-3, 10 | center=True, 11 | scale=True, 12 | **kwargs): 13 | super(AdaInstanceNormalization, self).__init__(**kwargs) 14 | self.axis = axis 15 | self.momentum = momentum 16 | self.epsilon = epsilon 17 | self.center = center 18 | self.scale = scale 19 | 20 | 21 | def build(self, input_shape): 22 | 23 | dim = input_shape[0][self.axis] 24 | if dim is None: 25 | raise ValueError('Axis ' + str(self.axis) + ' of ' 26 | 'input tensor should have a defined dimension ' 27 | 'but the layer received an input with shape ' + 28 | str(input_shape[0]) + '.') 29 | 30 | super(AdaInstanceNormalization, self).build(input_shape) 31 | 32 | def call(self, inputs, training=None): 33 | input_shape = K.int_shape(inputs[0]) 34 | reduction_axes = list(range(0, len(input_shape))) 35 | 36 | beta = inputs[1] 37 | gamma = inputs[2] 38 | 39 | if self.axis is not None: 40 | del reduction_axes[self.axis] 41 | 42 | del reduction_axes[0] 43 | mean = K.mean(inputs[0], reduction_axes, keepdims=True) 44 | stddev = K.std(inputs[0], reduction_axes, keepdims=True) + self.epsilon 45 | normed = (inputs[0] - mean) / stddev 46 | 47 | return normed * gamma + beta 48 | 49 | def get_config(self): 50 | config = { 51 | 'axis': self.axis, 52 | 'momentum': self.momentum, 53 | 'epsilon': self.epsilon, 54 | 'center': self.center, 55 | 'scale': self.scale 56 | } 57 | base_config = super(AdaInstanceNormalization, self).get_config() 58 | return dict(list(base_config.items()) + list(config.items())) 59 | 60 | def compute_output_shape(self, input_shape): 61 | 62 | return input_shape[0] 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | #Input b and g should be HxWxC 71 | class SPADE(Layer): 72 | def __init__(self, 73 | axis=-1, 74 | momentum=0.99, 75 | epsilon=1e-3, 76 | center=True, 77 | scale=True, 78 | **kwargs): 79 | super(SPADE, self).__init__(**kwargs) 80 | self.axis = axis 81 | self.momentum = momentum 82 | self.epsilon = epsilon 83 | self.center = center 84 | self.scale = scale 85 | 86 | 87 | def build(self, input_shape): 88 | 89 | dim = input_shape[0][self.axis] 90 | if dim is None: 91 | raise ValueError('Axis ' + str(self.axis) + ' of ' 92 | 'input tensor should have a defined dimension ' 93 | 'but the layer received an input with shape ' + 94 | str(input_shape[0]) + '.') 95 | 96 | super(SPADE, self).build(input_shape) 97 | 98 | def call(self, inputs, training=None): 99 | input_shape = K.int_shape(inputs[0]) 100 | 101 | beta = inputs[1] 102 | gamma = inputs[2] 103 | 104 | reduction_axes = [0, 1, 2] 105 | mean = K.mean(inputs[0], reduction_axes, keepdims=True) 106 | stddev = K.std(inputs[0], reduction_axes, keepdims=True) + self.epsilon 107 | normed = (inputs[0] - mean) / stddev 108 | 109 | return normed * gamma + beta 110 | 111 | def get_config(self): 112 | config = { 113 | 'axis': self.axis, 114 | 'momentum': self.momentum, 115 | 'epsilon': self.epsilon, 116 | 'center': self.center, 117 | 'scale': self.scale 118 | } 119 | base_config = super(SPADE, self).get_config() 120 | return dict(list(base_config.items()) + list(config.items())) 121 | 122 | def compute_output_shape(self, input_shape): 123 | 124 | return input_shape[0] 125 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Matthew 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Models/dis.json: -------------------------------------------------------------------------------- 1 | {"class_name": "Model", "config": {"name": "model_1", "layers": [{"name": "input_1", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 256, 256, 3], "dtype": "float32", "sparse": false, "name": "input_1"}, "inbound_nodes": []}, {"name": "conv2d_1", "class_name": "Conv2D", "config": {"name": "conv2d_1", "trainable": true, "filters": 16, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_1", 0, 0, {}]]]}, {"name": "leaky_re_lu_1", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_1", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_1", 0, 0, {}]]]}, {"name": "average_pooling2d_1", "class_name": "AveragePooling2D", "config": {"name": "average_pooling2d_1", "trainable": true, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_1", 0, 0, {}]]]}, {"name": "conv2d_2", "class_name": "Conv2D", "config": {"name": "conv2d_2", "trainable": true, "filters": 16, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["average_pooling2d_1", 0, 0, {}]]]}, {"name": "leaky_re_lu_2", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_2", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_2", 0, 0, {}]]]}, {"name": "conv2d_3", "class_name": "Conv2D", "config": {"name": "conv2d_3", "trainable": true, "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_2", 0, 0, {}]]]}, {"name": "leaky_re_lu_3", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_3", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_3", 0, 0, {}]]]}, {"name": "average_pooling2d_2", "class_name": "AveragePooling2D", "config": {"name": "average_pooling2d_2", "trainable": true, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_3", 0, 0, {}]]]}, {"name": "conv2d_4", "class_name": "Conv2D", "config": {"name": "conv2d_4", "trainable": true, "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["average_pooling2d_2", 0, 0, {}]]]}, {"name": "leaky_re_lu_4", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_4", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_4", 0, 0, {}]]]}, {"name": "conv2d_5", "class_name": "Conv2D", "config": {"name": "conv2d_5", "trainable": true, "filters": 64, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_4", 0, 0, {}]]]}, {"name": "leaky_re_lu_5", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_5", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_5", 0, 0, {}]]]}, {"name": "average_pooling2d_3", "class_name": "AveragePooling2D", "config": {"name": "average_pooling2d_3", "trainable": true, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_5", 0, 0, {}]]]}, {"name": "conv2d_6", "class_name": "Conv2D", "config": {"name": "conv2d_6", "trainable": true, "filters": 64, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["average_pooling2d_3", 0, 0, {}]]]}, {"name": "leaky_re_lu_6", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_6", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_6", 0, 0, {}]]]}, {"name": "conv2d_7", "class_name": "Conv2D", "config": {"name": "conv2d_7", "trainable": true, "filters": 128, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_6", 0, 0, {}]]]}, {"name": "leaky_re_lu_7", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_7", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_7", 0, 0, {}]]]}, {"name": "average_pooling2d_4", "class_name": "AveragePooling2D", "config": {"name": "average_pooling2d_4", "trainable": true, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_7", 0, 0, {}]]]}, {"name": "conv2d_8", "class_name": "Conv2D", "config": {"name": "conv2d_8", "trainable": true, "filters": 128, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["average_pooling2d_4", 0, 0, {}]]]}, {"name": "leaky_re_lu_8", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_8", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_8", 0, 0, {}]]]}, {"name": "conv2d_9", "class_name": "Conv2D", "config": {"name": "conv2d_9", "trainable": true, "filters": 192, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_8", 0, 0, {}]]]}, {"name": "leaky_re_lu_9", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_9", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_9", 0, 0, {}]]]}, {"name": "average_pooling2d_5", "class_name": "AveragePooling2D", "config": {"name": "average_pooling2d_5", "trainable": true, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_9", 0, 0, {}]]]}, {"name": "conv2d_10", "class_name": "Conv2D", "config": {"name": "conv2d_10", "trainable": true, "filters": 192, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["average_pooling2d_5", 0, 0, {}]]]}, {"name": "leaky_re_lu_10", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_10", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_10", 0, 0, {}]]]}, {"name": "conv2d_11", "class_name": "Conv2D", "config": {"name": "conv2d_11", "trainable": true, "filters": 256, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_10", 0, 0, {}]]]}, {"name": "leaky_re_lu_11", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_11", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_11", 0, 0, {}]]]}, {"name": "average_pooling2d_6", "class_name": "AveragePooling2D", "config": {"name": "average_pooling2d_6", "trainable": true, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_11", 0, 0, {}]]]}, {"name": "conv2d_12", "class_name": "Conv2D", "config": {"name": "conv2d_12", "trainable": true, "filters": 256, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["average_pooling2d_6", 0, 0, {}]]]}, {"name": "leaky_re_lu_12", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_12", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["conv2d_12", 0, 0, {}]]]}, {"name": "flatten_1", "class_name": "Flatten", "config": {"name": "flatten_1", "trainable": true, "data_format": "channels_last"}, "inbound_nodes": [[["leaky_re_lu_12", 0, 0, {}]]]}, {"name": "dense_1", "class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "units": 128, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["flatten_1", 0, 0, {}]]]}, {"name": "leaky_re_lu_13", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_13", "trainable": true, "alpha": 0.009999999776482582}, "inbound_nodes": [[["dense_1", 0, 0, {}]]]}, {"name": "dropout_1", "class_name": "Dropout", "config": {"name": "dropout_1", "trainable": true, "rate": 0.6, "noise_shape": null, "seed": null}, "inbound_nodes": [[["leaky_re_lu_13", 0, 0, {}]]]}, {"name": "dense_2", "class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["dropout_1", 0, 0, {}]]]}], "input_layers": [["input_1", 0, 0]], "output_layers": [["dense_2", 0, 0]]}, "keras_version": "2.2.4", "backend": "tensorflow"} -------------------------------------------------------------------------------- /Models/dis_101.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Models/dis_101.h5 -------------------------------------------------------------------------------- /Models/gen.json: -------------------------------------------------------------------------------- 1 | {"class_name": "Model", "config": {"name": "model_2", "layers": [{"name": "input_9", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 256, 256, 1], "dtype": "float32", "sparse": false, "name": "input_9"}, "inbound_nodes": []}, {"name": "activation_1", "class_name": "Activation", "config": {"name": "activation_1", "trainable": false, "activation": "linear"}, "inbound_nodes": [[["input_9", 0, 0, {}]]]}, {"name": "cropping2d_1", "class_name": "Cropping2D", "config": {"name": "cropping2d_1", "trainable": false, "cropping": [[64, 64], [64, 64]], "data_format": "channels_last"}, "inbound_nodes": [[["activation_1", 0, 0, {}]]]}, {"name": "cropping2d_2", "class_name": "Cropping2D", "config": {"name": "cropping2d_2", "trainable": false, "cropping": [[32, 32], [32, 32]], "data_format": "channels_last"}, "inbound_nodes": [[["cropping2d_1", 0, 0, {}]]]}, {"name": "cropping2d_3", "class_name": "Cropping2D", "config": {"name": "cropping2d_3", "trainable": false, "cropping": [[16, 16], [16, 16]], "data_format": "channels_last"}, "inbound_nodes": [[["cropping2d_2", 0, 0, {}]]]}, {"name": "input_10", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 1], "dtype": "float32", "sparse": false, "name": "input_10"}, "inbound_nodes": []}, {"name": "cropping2d_4", "class_name": "Cropping2D", "config": {"name": "cropping2d_4", "trainable": false, "cropping": [[8, 8], [8, 8]], "data_format": "channels_last"}, "inbound_nodes": [[["cropping2d_3", 0, 0, {}]]]}, {"name": "dense_3", "class_name": "Dense", "config": {"name": "dense_3", "trainable": false, "units": 4096, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Ones", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_10", 0, 0, {}]]]}, {"name": "cropping2d_5", "class_name": "Cropping2D", "config": {"name": "cropping2d_5", "trainable": false, "cropping": [[4, 4], [4, 4]], "data_format": "channels_last"}, "inbound_nodes": [[["cropping2d_4", 0, 0, {}]]]}, {"name": "reshape_1", "class_name": "Reshape", "config": {"name": "reshape_1", "trainable": false, "target_shape": [4, 4, 256]}, "inbound_nodes": [[["dense_3", 0, 0, {}]]]}, {"name": "cropping2d_6", "class_name": "Cropping2D", "config": {"name": "cropping2d_6", "trainable": false, "cropping": [[2, 2], [2, 2]], "data_format": "channels_last"}, "inbound_nodes": [[["cropping2d_5", 0, 0, {}]]]}, {"name": "input_2", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_2"}, "inbound_nodes": []}, {"name": "conv2d_14", "class_name": "Conv2D", "config": {"name": "conv2d_14", "trainable": false, "filters": 256, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["reshape_1", 0, 0, {}]]]}, {"name": "conv2d_13", "class_name": "Conv2D", "config": {"name": "conv2d_13", "trainable": false, "filters": 256, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_6", 0, 0, {}]]]}, {"name": "dense_4", "class_name": "Dense", "config": {"name": "dense_4", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_2", 0, 0, {}]]]}, {"name": "dense_5", "class_name": "Dense", "config": {"name": "dense_5", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_2", 0, 0, {}]]]}, {"name": "add_1", "class_name": "Add", "config": {"name": "add_1", "trainable": false}, "inbound_nodes": [[["conv2d_14", 0, 0, {}], ["conv2d_13", 0, 0, {}]]]}, {"name": "reshape_2", "class_name": "Reshape", "config": {"name": "reshape_2", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_4", 0, 0, {}]]]}, {"name": "reshape_3", "class_name": "Reshape", "config": {"name": "reshape_3", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_5", 0, 0, {}]]]}, {"name": "ada_instance_normalization_1", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_1", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_1", 0, 0, {}], ["reshape_2", 0, 0, {}], ["reshape_3", 0, 0, {}]]]}, {"name": "leaky_re_lu_14", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_14", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_1", 0, 0, {}]]]}, {"name": "conv2d_16", "class_name": "Conv2D", "config": {"name": "conv2d_16", "trainable": false, "filters": 256, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_14", 0, 0, {}]]]}, {"name": "conv2d_15", "class_name": "Conv2D", "config": {"name": "conv2d_15", "trainable": false, "filters": 256, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_6", 0, 0, {}]]]}, {"name": "dense_6", "class_name": "Dense", "config": {"name": "dense_6", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_2", 0, 0, {}]]]}, {"name": "dense_7", "class_name": "Dense", "config": {"name": "dense_7", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_2", 0, 0, {}]]]}, {"name": "add_2", "class_name": "Add", "config": {"name": "add_2", "trainable": false}, "inbound_nodes": [[["conv2d_16", 0, 0, {}], ["conv2d_15", 0, 0, {}]]]}, {"name": "reshape_4", "class_name": "Reshape", "config": {"name": "reshape_4", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_6", 0, 0, {}]]]}, {"name": "reshape_5", "class_name": "Reshape", "config": {"name": "reshape_5", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_7", 0, 0, {}]]]}, {"name": "ada_instance_normalization_2", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_2", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_2", 0, 0, {}], ["reshape_4", 0, 0, {}], ["reshape_5", 0, 0, {}]]]}, {"name": "leaky_re_lu_15", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_15", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_2", 0, 0, {}]]]}, {"name": "up_sampling2d_1", "class_name": "UpSampling2D", "config": {"name": "up_sampling2d_1", "trainable": false, "size": [2, 2], "data_format": "channels_last", "interpolation": "bilinear"}, "inbound_nodes": [[["leaky_re_lu_15", 0, 0, {}]]]}, {"name": "input_3", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_3"}, "inbound_nodes": []}, {"name": "conv2d_18", "class_name": "Conv2D", "config": {"name": "conv2d_18", "trainable": false, "filters": 256, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["up_sampling2d_1", 0, 0, {}]]]}, {"name": "conv2d_17", "class_name": "Conv2D", "config": {"name": "conv2d_17", "trainable": false, "filters": 256, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_5", 0, 0, {}]]]}, {"name": "dense_8", "class_name": "Dense", "config": {"name": "dense_8", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_3", 0, 0, {}]]]}, {"name": "dense_9", "class_name": "Dense", "config": {"name": "dense_9", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_3", 0, 0, {}]]]}, {"name": "add_3", "class_name": "Add", "config": {"name": "add_3", "trainable": false}, "inbound_nodes": [[["conv2d_18", 0, 0, {}], ["conv2d_17", 0, 0, {}]]]}, {"name": "reshape_6", "class_name": "Reshape", "config": {"name": "reshape_6", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_8", 0, 0, {}]]]}, {"name": "reshape_7", "class_name": "Reshape", "config": {"name": "reshape_7", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_9", 0, 0, {}]]]}, {"name": "ada_instance_normalization_3", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_3", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_3", 0, 0, {}], ["reshape_6", 0, 0, {}], ["reshape_7", 0, 0, {}]]]}, {"name": "leaky_re_lu_16", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_16", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_3", 0, 0, {}]]]}, {"name": "conv2d_20", "class_name": "Conv2D", "config": {"name": "conv2d_20", "trainable": false, "filters": 256, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_16", 0, 0, {}]]]}, {"name": "conv2d_19", "class_name": "Conv2D", "config": {"name": "conv2d_19", "trainable": false, "filters": 256, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_5", 0, 0, {}]]]}, {"name": "dense_10", "class_name": "Dense", "config": {"name": "dense_10", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_3", 0, 0, {}]]]}, {"name": "dense_11", "class_name": "Dense", "config": {"name": "dense_11", "trainable": false, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_3", 0, 0, {}]]]}, {"name": "add_4", "class_name": "Add", "config": {"name": "add_4", "trainable": false}, "inbound_nodes": [[["conv2d_20", 0, 0, {}], ["conv2d_19", 0, 0, {}]]]}, {"name": "reshape_8", "class_name": "Reshape", "config": {"name": "reshape_8", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_10", 0, 0, {}]]]}, {"name": "reshape_9", "class_name": "Reshape", "config": {"name": "reshape_9", "trainable": false, "target_shape": [1, 1, 256]}, "inbound_nodes": [[["dense_11", 0, 0, {}]]]}, {"name": "ada_instance_normalization_4", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_4", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_4", 0, 0, {}], ["reshape_8", 0, 0, {}], ["reshape_9", 0, 0, {}]]]}, {"name": "leaky_re_lu_17", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_17", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_4", 0, 0, {}]]]}, {"name": "up_sampling2d_2", "class_name": "UpSampling2D", "config": {"name": "up_sampling2d_2", "trainable": false, "size": [2, 2], "data_format": "channels_last", "interpolation": "bilinear"}, "inbound_nodes": [[["leaky_re_lu_17", 0, 0, {}]]]}, {"name": "input_4", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_4"}, "inbound_nodes": []}, {"name": "conv2d_22", "class_name": "Conv2D", "config": {"name": "conv2d_22", "trainable": false, "filters": 192, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["up_sampling2d_2", 0, 0, {}]]]}, {"name": "conv2d_21", "class_name": "Conv2D", "config": {"name": "conv2d_21", "trainable": false, "filters": 192, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_4", 0, 0, {}]]]}, {"name": "dense_12", "class_name": "Dense", "config": {"name": "dense_12", "trainable": false, "units": 192, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_4", 0, 0, {}]]]}, {"name": "dense_13", "class_name": "Dense", "config": {"name": "dense_13", "trainable": false, "units": 192, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_4", 0, 0, {}]]]}, {"name": "add_5", "class_name": "Add", "config": {"name": "add_5", "trainable": false}, "inbound_nodes": [[["conv2d_22", 0, 0, {}], ["conv2d_21", 0, 0, {}]]]}, {"name": "reshape_10", "class_name": "Reshape", "config": {"name": "reshape_10", "trainable": false, "target_shape": [1, 1, 192]}, "inbound_nodes": [[["dense_12", 0, 0, {}]]]}, {"name": "reshape_11", "class_name": "Reshape", "config": {"name": "reshape_11", "trainable": false, "target_shape": [1, 1, 192]}, "inbound_nodes": [[["dense_13", 0, 0, {}]]]}, {"name": "ada_instance_normalization_5", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_5", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_5", 0, 0, {}], ["reshape_10", 0, 0, {}], ["reshape_11", 0, 0, {}]]]}, {"name": "leaky_re_lu_18", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_18", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_5", 0, 0, {}]]]}, {"name": "conv2d_24", "class_name": "Conv2D", "config": {"name": "conv2d_24", "trainable": false, "filters": 192, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_18", 0, 0, {}]]]}, {"name": "conv2d_23", "class_name": "Conv2D", "config": {"name": "conv2d_23", "trainable": false, "filters": 192, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_4", 0, 0, {}]]]}, {"name": "dense_14", "class_name": "Dense", "config": {"name": "dense_14", "trainable": false, "units": 192, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_4", 0, 0, {}]]]}, {"name": "dense_15", "class_name": "Dense", "config": {"name": "dense_15", "trainable": false, "units": 192, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_4", 0, 0, {}]]]}, {"name": "add_6", "class_name": "Add", "config": {"name": "add_6", "trainable": false}, "inbound_nodes": [[["conv2d_24", 0, 0, {}], ["conv2d_23", 0, 0, {}]]]}, {"name": "reshape_12", "class_name": "Reshape", "config": {"name": "reshape_12", "trainable": false, "target_shape": [1, 1, 192]}, "inbound_nodes": [[["dense_14", 0, 0, {}]]]}, {"name": "reshape_13", "class_name": "Reshape", "config": {"name": "reshape_13", "trainable": false, "target_shape": [1, 1, 192]}, "inbound_nodes": [[["dense_15", 0, 0, {}]]]}, {"name": "ada_instance_normalization_6", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_6", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_6", 0, 0, {}], ["reshape_12", 0, 0, {}], ["reshape_13", 0, 0, {}]]]}, {"name": "leaky_re_lu_19", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_19", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_6", 0, 0, {}]]]}, {"name": "up_sampling2d_3", "class_name": "UpSampling2D", "config": {"name": "up_sampling2d_3", "trainable": false, "size": [2, 2], "data_format": "channels_last", "interpolation": "bilinear"}, "inbound_nodes": [[["leaky_re_lu_19", 0, 0, {}]]]}, {"name": "input_5", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_5"}, "inbound_nodes": []}, {"name": "conv2d_26", "class_name": "Conv2D", "config": {"name": "conv2d_26", "trainable": false, "filters": 128, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["up_sampling2d_3", 0, 0, {}]]]}, {"name": "conv2d_25", "class_name": "Conv2D", "config": {"name": "conv2d_25", "trainable": false, "filters": 128, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_3", 0, 0, {}]]]}, {"name": "dense_16", "class_name": "Dense", "config": {"name": "dense_16", "trainable": false, "units": 128, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_5", 0, 0, {}]]]}, {"name": "dense_17", "class_name": "Dense", "config": {"name": "dense_17", "trainable": false, "units": 128, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_5", 0, 0, {}]]]}, {"name": "add_7", "class_name": "Add", "config": {"name": "add_7", "trainable": false}, "inbound_nodes": [[["conv2d_26", 0, 0, {}], ["conv2d_25", 0, 0, {}]]]}, {"name": "reshape_14", "class_name": "Reshape", "config": {"name": "reshape_14", "trainable": false, "target_shape": [1, 1, 128]}, "inbound_nodes": [[["dense_16", 0, 0, {}]]]}, {"name": "reshape_15", "class_name": "Reshape", "config": {"name": "reshape_15", "trainable": false, "target_shape": [1, 1, 128]}, "inbound_nodes": [[["dense_17", 0, 0, {}]]]}, {"name": "ada_instance_normalization_7", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_7", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_7", 0, 0, {}], ["reshape_14", 0, 0, {}], ["reshape_15", 0, 0, {}]]]}, {"name": "leaky_re_lu_20", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_20", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_7", 0, 0, {}]]]}, {"name": "conv2d_28", "class_name": "Conv2D", "config": {"name": "conv2d_28", "trainable": false, "filters": 128, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_20", 0, 0, {}]]]}, {"name": "conv2d_27", "class_name": "Conv2D", "config": {"name": "conv2d_27", "trainable": false, "filters": 128, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_3", 0, 0, {}]]]}, {"name": "dense_18", "class_name": "Dense", "config": {"name": "dense_18", "trainable": false, "units": 128, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_5", 0, 0, {}]]]}, {"name": "dense_19", "class_name": "Dense", "config": {"name": "dense_19", "trainable": false, "units": 128, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_5", 0, 0, {}]]]}, {"name": "add_8", "class_name": "Add", "config": {"name": "add_8", "trainable": false}, "inbound_nodes": [[["conv2d_28", 0, 0, {}], ["conv2d_27", 0, 0, {}]]]}, {"name": "reshape_16", "class_name": "Reshape", "config": {"name": "reshape_16", "trainable": false, "target_shape": [1, 1, 128]}, "inbound_nodes": [[["dense_18", 0, 0, {}]]]}, {"name": "reshape_17", "class_name": "Reshape", "config": {"name": "reshape_17", "trainable": false, "target_shape": [1, 1, 128]}, "inbound_nodes": [[["dense_19", 0, 0, {}]]]}, {"name": "ada_instance_normalization_8", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_8", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_8", 0, 0, {}], ["reshape_16", 0, 0, {}], ["reshape_17", 0, 0, {}]]]}, {"name": "leaky_re_lu_21", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_21", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_8", 0, 0, {}]]]}, {"name": "up_sampling2d_4", "class_name": "UpSampling2D", "config": {"name": "up_sampling2d_4", "trainable": false, "size": [2, 2], "data_format": "channels_last", "interpolation": "bilinear"}, "inbound_nodes": [[["leaky_re_lu_21", 0, 0, {}]]]}, {"name": "input_6", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_6"}, "inbound_nodes": []}, {"name": "conv2d_30", "class_name": "Conv2D", "config": {"name": "conv2d_30", "trainable": false, "filters": 64, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["up_sampling2d_4", 0, 0, {}]]]}, {"name": "conv2d_29", "class_name": "Conv2D", "config": {"name": "conv2d_29", "trainable": false, "filters": 64, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_2", 0, 0, {}]]]}, {"name": "dense_20", "class_name": "Dense", "config": {"name": "dense_20", "trainable": false, "units": 64, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_6", 0, 0, {}]]]}, {"name": "dense_21", "class_name": "Dense", "config": {"name": "dense_21", "trainable": false, "units": 64, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_6", 0, 0, {}]]]}, {"name": "add_9", "class_name": "Add", "config": {"name": "add_9", "trainable": false}, "inbound_nodes": [[["conv2d_30", 0, 0, {}], ["conv2d_29", 0, 0, {}]]]}, {"name": "reshape_18", "class_name": "Reshape", "config": {"name": "reshape_18", "trainable": false, "target_shape": [1, 1, 64]}, "inbound_nodes": [[["dense_20", 0, 0, {}]]]}, {"name": "reshape_19", "class_name": "Reshape", "config": {"name": "reshape_19", "trainable": false, "target_shape": [1, 1, 64]}, "inbound_nodes": [[["dense_21", 0, 0, {}]]]}, {"name": "ada_instance_normalization_9", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_9", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_9", 0, 0, {}], ["reshape_18", 0, 0, {}], ["reshape_19", 0, 0, {}]]]}, {"name": "leaky_re_lu_22", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_22", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_9", 0, 0, {}]]]}, {"name": "conv2d_32", "class_name": "Conv2D", "config": {"name": "conv2d_32", "trainable": false, "filters": 64, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_22", 0, 0, {}]]]}, {"name": "conv2d_31", "class_name": "Conv2D", "config": {"name": "conv2d_31", "trainable": false, "filters": 64, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_2", 0, 0, {}]]]}, {"name": "dense_22", "class_name": "Dense", "config": {"name": "dense_22", "trainable": false, "units": 64, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_6", 0, 0, {}]]]}, {"name": "dense_23", "class_name": "Dense", "config": {"name": "dense_23", "trainable": false, "units": 64, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_6", 0, 0, {}]]]}, {"name": "add_10", "class_name": "Add", "config": {"name": "add_10", "trainable": false}, "inbound_nodes": [[["conv2d_32", 0, 0, {}], ["conv2d_31", 0, 0, {}]]]}, {"name": "reshape_20", "class_name": "Reshape", "config": {"name": "reshape_20", "trainable": false, "target_shape": [1, 1, 64]}, "inbound_nodes": [[["dense_22", 0, 0, {}]]]}, {"name": "reshape_21", "class_name": "Reshape", "config": {"name": "reshape_21", "trainable": false, "target_shape": [1, 1, 64]}, "inbound_nodes": [[["dense_23", 0, 0, {}]]]}, {"name": "ada_instance_normalization_10", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_10", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_10", 0, 0, {}], ["reshape_20", 0, 0, {}], ["reshape_21", 0, 0, {}]]]}, {"name": "leaky_re_lu_23", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_23", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_10", 0, 0, {}]]]}, {"name": "up_sampling2d_5", "class_name": "UpSampling2D", "config": {"name": "up_sampling2d_5", "trainable": false, "size": [2, 2], "data_format": "channels_last", "interpolation": "bilinear"}, "inbound_nodes": [[["leaky_re_lu_23", 0, 0, {}]]]}, {"name": "input_7", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_7"}, "inbound_nodes": []}, {"name": "conv2d_34", "class_name": "Conv2D", "config": {"name": "conv2d_34", "trainable": false, "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["up_sampling2d_5", 0, 0, {}]]]}, {"name": "conv2d_33", "class_name": "Conv2D", "config": {"name": "conv2d_33", "trainable": false, "filters": 32, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_1", 0, 0, {}]]]}, {"name": "dense_24", "class_name": "Dense", "config": {"name": "dense_24", "trainable": false, "units": 32, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_7", 0, 0, {}]]]}, {"name": "dense_25", "class_name": "Dense", "config": {"name": "dense_25", "trainable": false, "units": 32, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_7", 0, 0, {}]]]}, {"name": "add_11", "class_name": "Add", "config": {"name": "add_11", "trainable": false}, "inbound_nodes": [[["conv2d_34", 0, 0, {}], ["conv2d_33", 0, 0, {}]]]}, {"name": "reshape_22", "class_name": "Reshape", "config": {"name": "reshape_22", "trainable": false, "target_shape": [1, 1, 32]}, "inbound_nodes": [[["dense_24", 0, 0, {}]]]}, {"name": "reshape_23", "class_name": "Reshape", "config": {"name": "reshape_23", "trainable": false, "target_shape": [1, 1, 32]}, "inbound_nodes": [[["dense_25", 0, 0, {}]]]}, {"name": "ada_instance_normalization_11", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_11", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_11", 0, 0, {}], ["reshape_22", 0, 0, {}], ["reshape_23", 0, 0, {}]]]}, {"name": "leaky_re_lu_24", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_24", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_11", 0, 0, {}]]]}, {"name": "conv2d_36", "class_name": "Conv2D", "config": {"name": "conv2d_36", "trainable": false, "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_24", 0, 0, {}]]]}, {"name": "conv2d_35", "class_name": "Conv2D", "config": {"name": "conv2d_35", "trainable": false, "filters": 32, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["cropping2d_1", 0, 0, {}]]]}, {"name": "dense_26", "class_name": "Dense", "config": {"name": "dense_26", "trainable": false, "units": 32, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_7", 0, 0, {}]]]}, {"name": "dense_27", "class_name": "Dense", "config": {"name": "dense_27", "trainable": false, "units": 32, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_7", 0, 0, {}]]]}, {"name": "add_12", "class_name": "Add", "config": {"name": "add_12", "trainable": false}, "inbound_nodes": [[["conv2d_36", 0, 0, {}], ["conv2d_35", 0, 0, {}]]]}, {"name": "reshape_24", "class_name": "Reshape", "config": {"name": "reshape_24", "trainable": false, "target_shape": [1, 1, 32]}, "inbound_nodes": [[["dense_26", 0, 0, {}]]]}, {"name": "reshape_25", "class_name": "Reshape", "config": {"name": "reshape_25", "trainable": false, "target_shape": [1, 1, 32]}, "inbound_nodes": [[["dense_27", 0, 0, {}]]]}, {"name": "ada_instance_normalization_12", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_12", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_12", 0, 0, {}], ["reshape_24", 0, 0, {}], ["reshape_25", 0, 0, {}]]]}, {"name": "leaky_re_lu_25", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_25", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_12", 0, 0, {}]]]}, {"name": "up_sampling2d_6", "class_name": "UpSampling2D", "config": {"name": "up_sampling2d_6", "trainable": false, "size": [2, 2], "data_format": "channels_last", "interpolation": "bilinear"}, "inbound_nodes": [[["leaky_re_lu_25", 0, 0, {}]]]}, {"name": "input_8", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_8"}, "inbound_nodes": []}, {"name": "conv2d_38", "class_name": "Conv2D", "config": {"name": "conv2d_38", "trainable": false, "filters": 16, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["up_sampling2d_6", 0, 0, {}]]]}, {"name": "conv2d_37", "class_name": "Conv2D", "config": {"name": "conv2d_37", "trainable": false, "filters": 16, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["activation_1", 0, 0, {}]]]}, {"name": "dense_28", "class_name": "Dense", "config": {"name": "dense_28", "trainable": false, "units": 16, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_8", 0, 0, {}]]]}, {"name": "dense_29", "class_name": "Dense", "config": {"name": "dense_29", "trainable": false, "units": 16, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_8", 0, 0, {}]]]}, {"name": "add_13", "class_name": "Add", "config": {"name": "add_13", "trainable": false}, "inbound_nodes": [[["conv2d_38", 0, 0, {}], ["conv2d_37", 0, 0, {}]]]}, {"name": "reshape_26", "class_name": "Reshape", "config": {"name": "reshape_26", "trainable": false, "target_shape": [1, 1, 16]}, "inbound_nodes": [[["dense_28", 0, 0, {}]]]}, {"name": "reshape_27", "class_name": "Reshape", "config": {"name": "reshape_27", "trainable": false, "target_shape": [1, 1, 16]}, "inbound_nodes": [[["dense_29", 0, 0, {}]]]}, {"name": "ada_instance_normalization_13", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_13", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_13", 0, 0, {}], ["reshape_26", 0, 0, {}], ["reshape_27", 0, 0, {}]]]}, {"name": "leaky_re_lu_26", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_26", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_13", 0, 0, {}]]]}, {"name": "conv2d_40", "class_name": "Conv2D", "config": {"name": "conv2d_40", "trainable": false, "filters": 16, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_26", 0, 0, {}]]]}, {"name": "conv2d_39", "class_name": "Conv2D", "config": {"name": "conv2d_39", "trainable": false, "filters": 16, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "Zeros", "config": {}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["activation_1", 0, 0, {}]]]}, {"name": "dense_30", "class_name": "Dense", "config": {"name": "dense_30", "trainable": false, "units": 16, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Ones", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_8", 0, 0, {}]]]}, {"name": "dense_31", "class_name": "Dense", "config": {"name": "dense_31", "trainable": false, "units": 16, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_8", 0, 0, {}]]]}, {"name": "add_14", "class_name": "Add", "config": {"name": "add_14", "trainable": false}, "inbound_nodes": [[["conv2d_40", 0, 0, {}], ["conv2d_39", 0, 0, {}]]]}, {"name": "reshape_28", "class_name": "Reshape", "config": {"name": "reshape_28", "trainable": false, "target_shape": [1, 1, 16]}, "inbound_nodes": [[["dense_30", 0, 0, {}]]]}, {"name": "reshape_29", "class_name": "Reshape", "config": {"name": "reshape_29", "trainable": false, "target_shape": [1, 1, 16]}, "inbound_nodes": [[["dense_31", 0, 0, {}]]]}, {"name": "ada_instance_normalization_14", "class_name": "AdaInstanceNormalization", "config": {"name": "ada_instance_normalization_14", "trainable": false, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true}, "inbound_nodes": [[["add_14", 0, 0, {}], ["reshape_28", 0, 0, {}], ["reshape_29", 0, 0, {}]]]}, {"name": "leaky_re_lu_27", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_27", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["ada_instance_normalization_14", 0, 0, {}]]]}, {"name": "conv2d_41", "class_name": "Conv2D", "config": {"name": "conv2d_41", "trainable": false, "filters": 3, "kernel_size": [1, 1], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_27", 0, 0, {}]]]}], "input_layers": [["input_2", 0, 0], ["input_3", 0, 0], ["input_4", 0, 0], ["input_5", 0, 0], ["input_6", 0, 0], ["input_7", 0, 0], ["input_8", 0, 0], ["input_9", 0, 0], ["input_10", 0, 0]], "output_layers": [["conv2d_41", 0, 0]]}, "keras_version": "2.2.4", "backend": "tensorflow"} -------------------------------------------------------------------------------- /Models/gen_101.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Models/gen_101.h5 -------------------------------------------------------------------------------- /Models/sty.json: -------------------------------------------------------------------------------- 1 | {"class_name": "Model", "config": {"name": "model_3", "layers": [{"name": "input_11", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 512], "dtype": "float32", "sparse": false, "name": "input_11"}, "inbound_nodes": []}, {"name": "dense_32", "class_name": "Dense", "config": {"name": "dense_32", "trainable": false, "units": 512, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["input_11", 0, 0, {}]]]}, {"name": "leaky_re_lu_28", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_28", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["dense_32", 0, 0, {}]]]}, {"name": "dense_33", "class_name": "Dense", "config": {"name": "dense_33", "trainable": false, "units": 512, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_28", 0, 0, {}]]]}, {"name": "leaky_re_lu_29", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_29", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["dense_33", 0, 0, {}]]]}, {"name": "dense_34", "class_name": "Dense", "config": {"name": "dense_34", "trainable": false, "units": 512, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_29", 0, 0, {}]]]}, {"name": "leaky_re_lu_30", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_30", "trainable": false, "alpha": 0.009999999776482582}, "inbound_nodes": [[["dense_34", 0, 0, {}]]]}, {"name": "dense_35", "class_name": "Dense", "config": {"name": "dense_35", "trainable": false, "units": 512, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 2.0, "mode": "fan_in", "distribution": "normal", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_30", 0, 0, {}]]]}], "input_layers": [["input_11", 0, 0]], "output_layers": [["dense_35", 0, 0]]}, "keras_version": "2.2.4", "backend": "tensorflow"} -------------------------------------------------------------------------------- /Models/sty_101.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Models/sty_101.h5 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StyleGAN-Keras 2 | StyleGAN made with Keras (without growth) 3 | 4 | ![alt text](https://i.imgur.com/o3jNlfn.jpg) 5 | A set of 256x256 samples trained for 1 million steps with a batch size of 4. 6 | 7 | ![alt text](https://i.imgur.com/iV6Y0Dn.jpg) 8 | Rows: 4^2 to 32^2 styles 9 | Columns: 32^2 to 256^2 styles 10 | 11 | This GAN is based off this paper: 12 | https://arxiv.org/abs/1812.04948 13 | 14 | "A Style-Based Generator Architecture for Generative Adversarial Networks" 15 | 16 | 17 | Additionally, in AdaIN.py, you will find code for Spatially Adaptive Denormalization (a.k.a SPADE) 18 | This is adapted (as best as I can) from this paper: 19 | https://arxiv.org/abs/1903.07291 20 | 21 | "Semantic Image Synthesis with Spatially-Adaptive Normalization" 22 | 23 | 24 | This StyleGAN is missing growth. Feel free to contribute this, if you'd like! 25 | 26 | Mixing regularities is left out in stylegan.py, but included in mixing-stylegan.py. It complicates the inputs of the generator. 27 | 28 | 29 | To train this on your own dataset, adjust lines 10 to 15 respectively, and load your own images into the /data/ folder under the naming convention 'im (n).suffix'. 30 | 31 | Enjoy! 32 | -------------------------------------------------------------------------------- /Results/i1003ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1003ii.jpg -------------------------------------------------------------------------------- /Results/i1003mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1003mm.jpg -------------------------------------------------------------------------------- /Results/i1003tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1003tt.jpg -------------------------------------------------------------------------------- /Results/i1004ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1004ii.jpg -------------------------------------------------------------------------------- /Results/i1004mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1004mm.jpg -------------------------------------------------------------------------------- /Results/i1004tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1004tt.jpg -------------------------------------------------------------------------------- /Results/i1005ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1005ii.jpg -------------------------------------------------------------------------------- /Results/i1005mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1005mm.jpg -------------------------------------------------------------------------------- /Results/i1005tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1005tt.jpg -------------------------------------------------------------------------------- /Results/i1006ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1006ii.jpg -------------------------------------------------------------------------------- /Results/i1006mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1006mm.jpg -------------------------------------------------------------------------------- /Results/i1006tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1006tt.jpg -------------------------------------------------------------------------------- /Results/i1007ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1007ii.jpg -------------------------------------------------------------------------------- /Results/i1007mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1007mm.jpg -------------------------------------------------------------------------------- /Results/i1007tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1007tt.jpg -------------------------------------------------------------------------------- /Results/i1008ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1008ii.jpg -------------------------------------------------------------------------------- /Results/i1008mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1008mm.jpg -------------------------------------------------------------------------------- /Results/i1008tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1008tt.jpg -------------------------------------------------------------------------------- /Results/i1009ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1009ii.jpg -------------------------------------------------------------------------------- /Results/i1009mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1009mm.jpg -------------------------------------------------------------------------------- /Results/i1009tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1009tt.jpg -------------------------------------------------------------------------------- /Results/i1010ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1010ii.jpg -------------------------------------------------------------------------------- /Results/i1010mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1010mm.jpg -------------------------------------------------------------------------------- /Results/i1010tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1010tt.jpg -------------------------------------------------------------------------------- /Results/i1011ii.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1011ii.jpg -------------------------------------------------------------------------------- /Results/i1011mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1011mm.jpg -------------------------------------------------------------------------------- /Results/i1011tt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i1011tt.jpg -------------------------------------------------------------------------------- /Results/i308.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i308.jpg -------------------------------------------------------------------------------- /Results/i325.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/Results/i325.jpg -------------------------------------------------------------------------------- /adamlr.py: -------------------------------------------------------------------------------- 1 | #This is code for a learning rate multiplier version of Adam 2 | #Original: https://erikbrorson.github.io/2018/04/30/Adam-with-learning-rate-multipliers/ 3 | 4 | import keras.backend as K 5 | from keras.optimizers import Optimizer 6 | 7 | class Adam_lr_mult(Optimizer): 8 | """Adam optimizer. 9 | Adam optimizer, with learning rate multipliers built on Keras implementation 10 | # Arguments 11 | lr: float >= 0. Learning rate. 12 | beta_1: float, 0 < beta < 1. Generally close to 1. 13 | beta_2: float, 0 < beta < 1. Generally close to 1. 14 | epsilon: float >= 0. Fuzz factor. If `None`, defaults to `K.epsilon()`. 15 | decay: float >= 0. Learning rate decay over each update. 16 | amsgrad: boolean. Whether to apply the AMSGrad variant of this 17 | algorithm from the paper "On the Convergence of Adam and 18 | Beyond". 19 | # References 20 | - [Adam - A Method for Stochastic Optimization](http://arxiv.org/abs/1412.6980v8) 21 | - [On the Convergence of Adam and Beyond](https://openreview.net/forum?id=ryQu7f-RZ) 22 | 23 | AUTHOR: Erik Brorson 24 | """ 25 | 26 | def __init__(self, lr=0.001, beta_1=0.9, beta_2=0.999, 27 | epsilon=None, decay=0., amsgrad=False, 28 | multipliers=None, debug_verbose=False,**kwargs): 29 | super(Adam_lr_mult, self).__init__(**kwargs) 30 | with K.name_scope(self.__class__.__name__): 31 | self.iterations = K.variable(0, dtype='int64', name='iterations') 32 | self.lr = K.variable(lr, name='lr') 33 | self.beta_1 = K.variable(beta_1, name='beta_1') 34 | self.beta_2 = K.variable(beta_2, name='beta_2') 35 | self.decay = K.variable(decay, name='decay') 36 | if epsilon is None: 37 | epsilon = K.epsilon() 38 | self.epsilon = epsilon 39 | self.initial_decay = decay 40 | self.amsgrad = amsgrad 41 | self.multipliers = multipliers 42 | self.debug_verbose = debug_verbose 43 | 44 | def get_updates(self, loss, params): 45 | grads = self.get_gradients(loss, params) 46 | self.updates = [K.update_add(self.iterations, 1)] 47 | 48 | lr = self.lr 49 | if self.initial_decay > 0: 50 | lr *= (1. / (1. + self.decay * K.cast(self.iterations, 51 | K.dtype(self.decay)))) 52 | 53 | t = K.cast(self.iterations, K.floatx()) + 1 54 | lr_t = lr * (K.sqrt(1. - K.pow(self.beta_2, t)) / 55 | (1. - K.pow(self.beta_1, t))) 56 | 57 | ms = [K.zeros(K.int_shape(p), dtype=K.dtype(p)) for p in params] 58 | vs = [K.zeros(K.int_shape(p), dtype=K.dtype(p)) for p in params] 59 | if self.amsgrad: 60 | vhats = [K.zeros(K.int_shape(p), dtype=K.dtype(p)) for p in params] 61 | else: 62 | vhats = [K.zeros(1) for _ in params] 63 | self.weights = [self.iterations] + ms + vs + vhats 64 | 65 | for p, g, m, v, vhat in zip(params, grads, ms, vs, vhats): 66 | 67 | # Learning rate multipliers 68 | if self.multipliers: 69 | multiplier = [mult for mult in self.multipliers if mult in p.name] 70 | else: 71 | multiplier = None 72 | if multiplier: 73 | new_lr_t = lr_t * self.multipliers[multiplier[0]] 74 | if self.debug_verbose: 75 | print('Setting {} to learning rate {}'.format(multiplier[0], new_lr_t)) 76 | print(K.get_value(new_lr_t)) 77 | else: 78 | new_lr_t = lr_t 79 | if self.debug_verbose: 80 | print('No change in learning rate {}'.format(p.name)) 81 | print(K.get_value(new_lr_t)) 82 | m_t = (self.beta_1 * m) + (1. - self.beta_1) * g 83 | v_t = (self.beta_2 * v) + (1. - self.beta_2) * K.square(g) 84 | if self.amsgrad: 85 | vhat_t = K.maximum(vhat, v_t) 86 | p_t = p - new_lr_t * m_t / (K.sqrt(vhat_t) + self.epsilon) 87 | self.updates.append(K.update(vhat, vhat_t)) 88 | else: 89 | p_t = p - new_lr_t * m_t / (K.sqrt(v_t) + self.epsilon) 90 | 91 | self.updates.append(K.update(m, m_t)) 92 | self.updates.append(K.update(v, v_t)) 93 | new_p = p_t 94 | 95 | # Apply constraints. 96 | if getattr(p, 'constraint', None) is not None: 97 | new_p = p.constraint(new_p) 98 | 99 | self.updates.append(K.update(p, new_p)) 100 | return self.updates 101 | 102 | def get_config(self): 103 | config = {'lr': float(K.get_value(self.lr)), 104 | 'beta_1': float(K.get_value(self.beta_1)), 105 | 'beta_2': float(K.get_value(self.beta_2)), 106 | 'decay': float(K.get_value(self.decay)), 107 | 'epsilon': self.epsilon, 108 | 'amsgrad': self.amsgrad, 109 | 'multipliers':self.multipliers} 110 | base_config = super(Adam_lr_mult, self).get_config() 111 | return dict(list(base_config.items()) + list(config.items())) 112 | -------------------------------------------------------------------------------- /data/Earth-256/im (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/data/Earth-256/im (1).jpg -------------------------------------------------------------------------------- /data/Earth-256/im (2).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/data/Earth-256/im (2).jpg -------------------------------------------------------------------------------- /data/Flowers/im (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/data/Flowers/im (1).jpg -------------------------------------------------------------------------------- /data/Flowers/im (2).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manicman1999/StyleGAN-Keras/6c51df2945cddd2ff1e5ef97388da5c228277f67/data/Flowers/im (2).jpg -------------------------------------------------------------------------------- /mixed-stylegan.py: -------------------------------------------------------------------------------- 1 | #Imports 2 | from PIL import Image 3 | from math import floor 4 | import numpy as np 5 | import time 6 | from functools import partial 7 | from random import random 8 | 9 | #Config Stuff 10 | im_size = 256 11 | latent_size = 512 12 | BATCH_SIZE = 4 13 | directory = "Rooms" 14 | n_images = 2686 15 | suff = 'jpg' 16 | cmode = 'YCbCr' 17 | 18 | """ For testing color space ranges 19 | temp = Image.open("data/Earth/im (2).jpg").convert(cmode) 20 | temp1 = np.array(temp, dtype='float32') 21 | 22 | print(np.max(temp1[...,0])) 23 | print(np.min(temp1[...,0])) 24 | print(np.max(temp1[...,1])) 25 | print(np.min(temp1[...,1])) 26 | print(np.max(temp1[...,2])) 27 | print(np.min(temp1[...,2])) 28 | """ 29 | 30 | #Style Z 31 | def noise(n): 32 | return np.random.normal(0.0, 1.0, size = [n, latent_size]) 33 | 34 | #Noise Sample 35 | def noiseImage(n): 36 | return np.random.uniform(0.0, 1.0, size = [n, im_size, im_size, 1]) 37 | 38 | #Get random samples from an array 39 | def get_rand(array, amount): 40 | 41 | idx = np.random.randint(0, array.shape[0], amount) 42 | return array[idx] 43 | 44 | #Import Images Function 45 | def import_images(loc, flip = True, suffix = 'png'): 46 | 47 | out = [] 48 | cont = True 49 | i = 1 50 | print("Importing Images...") 51 | 52 | while(cont): 53 | try: 54 | temp = Image.open("data/"+loc+"/im ("+str(i)+")."+suffix+"").convert(cmode) 55 | temp = temp.resize((im_size, im_size), Image.BICUBIC) 56 | temp1 = np.array(temp, dtype='float32') / 255 57 | out.append(temp1) 58 | if flip: 59 | out.append(np.flip(out[-1], 1)) 60 | 61 | i = i + 1 62 | except: 63 | cont = False 64 | 65 | print(str(i-1) + " images imported.") 66 | 67 | return np.array(out) 68 | 69 | #This is the REAL data generator, which can take images from disk and temporarily use them in your program. 70 | #Probably could/should get optimized at some point 71 | class dataGenerator(object): 72 | 73 | def __init__(self, loc, n, flip = True, suffix = 'png'): 74 | self.loc = "data/"+loc 75 | self.flip = flip 76 | self.suffix = suffix 77 | self.n = n 78 | 79 | def get_batch(self, amount): 80 | 81 | idx = np.random.randint(0, self.n - 1, amount) + 1 82 | out = [] 83 | 84 | for i in idx: 85 | temp = Image.open(self.loc+"/im ("+str(i)+")."+self.suffix+"").convert(cmode) 86 | temp1 = np.array(temp, dtype='float32') / 255 87 | if self.flip and random() > 0.5: 88 | temp1 = np.flip(temp1, 1) 89 | 90 | out.append(temp1) 91 | 92 | 93 | return np.array(out) 94 | 95 | 96 | 97 | 98 | #Imports for layers and models 99 | from keras.layers import Conv2D, Dense, AveragePooling2D, LeakyReLU, Activation 100 | from keras.layers import Reshape, UpSampling2D, Dropout, Flatten, Input, add, Cropping2D 101 | from keras.models import model_from_json, Model 102 | from keras.optimizers import Adam 103 | from adamlr import Adam_lr_mult 104 | import keras.backend as K 105 | 106 | from AdaIN import AdaInstanceNormalization 107 | 108 | 109 | #r1/r2 gradient penalty 110 | def gradient_penalty_loss(y_true, y_pred, averaged_samples, weight): 111 | gradients = K.gradients(y_pred, averaged_samples)[0] 112 | gradients_sqr = K.square(gradients) 113 | gradient_penalty = K.sum(gradients_sqr, 114 | axis=np.arange(1, len(gradients_sqr.shape))) 115 | 116 | # weight * ||grad||^2 117 | # Penalize the gradient norm 118 | return K.mean(gradient_penalty * weight) 119 | 120 | #Upsample, Convolution, AdaIN, Noise, Activation, Convolution, AdaIN, Noise, Activation 121 | def g_block(inp, style, noise, fil, u = True): 122 | 123 | b = Dense(fil, kernel_initializer = 'he_normal', bias_initializer = 'ones')(style) 124 | b = Reshape([1, 1, fil])(b) 125 | g = Dense(fil, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(style) 126 | g = Reshape([1, 1, fil])(g) 127 | 128 | n = Conv2D(filters = fil, kernel_size = 1, padding = 'same', kernel_initializer = 'zeros', bias_initializer = 'zeros')(noise) 129 | 130 | if u: 131 | out = UpSampling2D(interpolation = 'bilinear')(inp) 132 | out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal', bias_initializer = 'zeros')(out) 133 | else: 134 | out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal', bias_initializer = 'zeros')(inp) 135 | 136 | out = add([out, n]) 137 | out = AdaInstanceNormalization()([out, b, g]) 138 | out = LeakyReLU(0.01)(out) 139 | 140 | b = Dense(fil, kernel_initializer = 'he_normal', bias_initializer = 'ones')(style) 141 | b = Reshape([1, 1, fil])(b) 142 | g = Dense(fil, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(style) 143 | g = Reshape([1, 1, fil])(g) 144 | 145 | n = Conv2D(filters = fil, kernel_size = 1, padding = 'same', kernel_initializer = 'zeros', bias_initializer = 'zeros')(noise) 146 | 147 | out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal', bias_initializer = 'zeros')(out) 148 | out = add([out, n]) 149 | out = AdaInstanceNormalization()([out, b, g]) 150 | out = LeakyReLU(0.01)(out) 151 | 152 | return out 153 | 154 | #Convolution, Activation, Pooling, Convolution, Activation 155 | def d_block(inp, fil, p = True): 156 | 157 | route2 = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal', bias_initializer = 'zeros')(inp) 158 | route2 = LeakyReLU(0.01)(route2) 159 | if p: 160 | route2 = AveragePooling2D()(route2) 161 | route2 = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal', bias_initializer = 'zeros')(route2) 162 | out = LeakyReLU(0.01)(route2) 163 | 164 | return out 165 | 166 | #This object holds the models 167 | class GAN(object): 168 | 169 | def __init__(self, steps = 1, lr = 0.0001, decay = 0.00001): 170 | 171 | #Models 172 | self.D = None 173 | self.G = None 174 | self.S = None 175 | 176 | self.DM = None 177 | self.DMM = None 178 | self.AM = None 179 | self.MM = None 180 | 181 | #Config 182 | #Automatic Decay 183 | temp = (1 - decay) ** steps 184 | self.LR = lr * temp 185 | self.steps = steps 186 | 187 | #Calculate number of layers needed 188 | self.style_layers = 0 189 | 190 | #Init Models 191 | self.discriminator() 192 | self.generator() 193 | self.stylist() 194 | 195 | def discriminator(self): 196 | 197 | if self.D: 198 | return self.D 199 | 200 | inp = Input(shape = [im_size, im_size, 3]) 201 | 202 | # Size 203 | x = d_block(inp, 16) #Size / 2 204 | x = d_block(x, 32) #Size / 4 205 | x = d_block(x, 64) #Size / 8 206 | 207 | if (im_size > 32): 208 | x = d_block(x, 128) #Size / 16 209 | 210 | if (im_size > 64): 211 | x = d_block(x, 192) #Size / 32 212 | 213 | if (im_size > 128): 214 | x = d_block(x, 256) #Size / 64 215 | 216 | if (im_size > 256): 217 | x = d_block(x, 384) #Size / 128 218 | 219 | if (im_size > 512): 220 | x = d_block(x, 512) #Size / 256 221 | 222 | 223 | x = Flatten()(x) 224 | 225 | x = Dense(128, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(x) 226 | x = LeakyReLU(0.01)(x) 227 | 228 | x = Dropout(0.2)(x) 229 | x = Dense(1, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(x) 230 | 231 | self.D = Model(inputs = inp, outputs = x) 232 | 233 | return self.D 234 | 235 | def generator(self): 236 | 237 | if self.G: 238 | return self.G 239 | 240 | inp_s = [] 241 | ss = im_size 242 | while ss >= 4: 243 | inp_s.append(Input(shape = [512])) 244 | ss = int(ss / 2) 245 | 246 | self.style_layers = len(inp_s) 247 | 248 | #Get the noise image and crop for each size 249 | inp_n = Input(shape = [im_size, im_size, 1]) 250 | noi = [Activation('linear')(inp_n)] 251 | curr_size = im_size 252 | while curr_size > 4: 253 | curr_size = int(curr_size / 2) 254 | noi.append(Cropping2D(int(curr_size/2))(noi[-1])) 255 | 256 | #Here do the actual generation stuff 257 | inp = Input(shape = [1]) 258 | x = Dense(4 * 4 * im_size, kernel_initializer = 'ones', bias_initializer = 'zeros')(inp) 259 | x = Reshape([4, 4, im_size])(x) 260 | x = g_block(x, inp_s[0], noi[-1], im_size, u=False) 261 | 262 | if(im_size >= 1024): 263 | x = g_block(x, inp_s[-8], noi[7], 512) # Size / 64 264 | if(im_size >= 512): 265 | x = g_block(x, inp_s[-7], noi[6], 384) # Size / 64 266 | if(im_size >= 256): 267 | x = g_block(x, inp_s[-6], noi[5], 256) # Size / 32 268 | if(im_size >= 128): 269 | x = g_block(x, inp_s[-5], noi[4], 192) # Size / 16 270 | if(im_size >= 64): 271 | x = g_block(x, inp_s[-4], noi[3], 128) # Size / 8 272 | 273 | x = g_block(x, inp_s[-3], noi[2], 64) # Size / 4 274 | x = g_block(x, inp_s[-2], noi[1], 32) # Size / 2 275 | x = g_block(x, inp_s[-1], noi[0], 16) # Size 276 | 277 | x = Conv2D(filters = 3, kernel_size = 1, padding = 'same', activation = 'sigmoid', bias_initializer = 'zeros')(x) 278 | 279 | self.G = Model(inputs = inp_s + [inp_n, inp], outputs = x) 280 | 281 | return self.G 282 | 283 | def stylist(self): 284 | 285 | if self.S: 286 | return self.S 287 | 288 | #Mapping FC, I only used 5 fully connected layers instead of 8 for faster training 289 | inp_s = Input(shape = [latent_size]) 290 | sty = Dense(512, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(inp_s) 291 | sty = LeakyReLU(0.01)(sty) 292 | sty = Dense(512, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(sty) 293 | sty = LeakyReLU(0.01)(sty) 294 | sty = Dense(512, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(sty) 295 | sty = LeakyReLU(0.01)(sty) 296 | sty = Dense(512, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(sty) 297 | 298 | self.S = Model(inputs = inp_s, outputs = sty) 299 | 300 | return self.S 301 | 302 | def AdModel(self): 303 | 304 | #D does not update 305 | self.D.trainable = False 306 | for layer in self.D.layers: 307 | layer.trainable = False 308 | 309 | #G does update 310 | self.G.trainable = True 311 | for layer in self.G.layers: 312 | layer.trainable = True 313 | 314 | #S does update 315 | self.S.trainable = True 316 | for layer in self.S.layers: 317 | layer.trainable = True 318 | 319 | #This model is simple sequential one with inputs and outputs 320 | gi = Input(shape = [latent_size]) 321 | gs = self.S(gi) 322 | gi2 = Input(shape = [im_size, im_size, 1]) 323 | gi3 = Input(shape = [1]) 324 | 325 | gf = self.G(([gs] * self.style_layers) + [gi2, gi3]) 326 | df = self.D(gf) 327 | 328 | self.AM = Model(inputs = [gi, gi2, gi3], outputs = df) 329 | 330 | learning_rate_multipliers = {} 331 | learning_rate_multipliers['model_3'] = 0.1 332 | 333 | self.AM.compile(optimizer = Adam_lr_mult(self.LR, beta_1 = 0, beta_2 = 0.99, decay = 0.00001, multipliers = learning_rate_multipliers), loss = 'mse') 334 | 335 | return self.AM 336 | 337 | def MixModel(self): 338 | 339 | #D does not update 340 | self.D.trainable = False 341 | for layer in self.D.layers: 342 | layer.trainable = False 343 | 344 | #G does update 345 | self.G.trainable = True 346 | for layer in self.G.layers: 347 | layer.trainable = True 348 | 349 | #S does update 350 | self.S.trainable = True 351 | for layer in self.S.layers: 352 | layer.trainable = True 353 | 354 | #This model is simple sequential one with inputs and outputs 355 | inp_s = [] 356 | ss = [] 357 | for _ in range(self.style_layers): 358 | inp_s.append(Input([latent_size])) 359 | ss.append(self.S(inp_s[-1])) 360 | 361 | 362 | gi2 = Input(shape = [im_size, im_size, 1]) 363 | gi3 = Input(shape = [1]) 364 | 365 | gf = self.G(ss + [gi2, gi3]) 366 | df = self.D(gf) 367 | 368 | self.MM = Model(inputs = inp_s + [gi2, gi3], outputs = df) 369 | 370 | learning_rate_multipliers = {} 371 | learning_rate_multipliers['model_3'] = 0.1 372 | 373 | self.MM.compile(optimizer = Adam_lr_mult(self.LR, beta_1 = 0, beta_2 = 0.99, decay = 0.00001, multipliers = learning_rate_multipliers), loss = 'mse') 374 | 375 | return self.MM 376 | 377 | def DisModel(self): 378 | 379 | #D does update 380 | self.D.trainable = True 381 | for layer in self.D.layers: 382 | layer.trainable = True 383 | 384 | #G does not update 385 | self.G.trainable = False 386 | for layer in self.G.layers: 387 | layer.trainable = False 388 | 389 | #S does not update 390 | self.S.trainable = False 391 | for layer in self.S.layers: 392 | layer.trainable = False 393 | 394 | # Real Pipeline 395 | ri = Input(shape = [im_size, im_size, 3]) 396 | dr = self.D(ri) 397 | 398 | # Fake Pipeline 399 | gi = Input(shape = [latent_size]) 400 | gs = self.S(gi) 401 | gi2 = Input(shape = [im_size, im_size, 1]) 402 | gi3 = Input(shape = [1]) 403 | gf = self.G(([gs] * self.style_layers) + [gi2, gi3]) 404 | df = self.D(gf) 405 | 406 | # Samples for gradient penalty 407 | # For r1 use real samples (ri) 408 | # For r2 use fake samples (gf) 409 | #da = self.D(ri) 410 | 411 | # Model With Inputs and Outputs 412 | self.DM = Model(inputs=[ri, gi, gi2, gi3], outputs=[dr, df, dr]) 413 | 414 | # Create partial of gradient penalty loss 415 | # For r1, averaged_samples = ri 416 | # For r2, averaged_samples = gf 417 | # Weight of 10 typically works 418 | partial_gp_loss = partial(gradient_penalty_loss, averaged_samples = ri, weight = 50) 419 | 420 | #Compile With Corresponding Loss Functions 421 | self.DM.compile(optimizer=Adam(self.LR, beta_1 = 0, beta_2 = 0.99, decay = 0.00001), loss=['mse', 'mse', partial_gp_loss]) 422 | 423 | return self.DM 424 | 425 | def MixModelD(self): 426 | 427 | #D does update 428 | self.D.trainable = True 429 | for layer in self.D.layers: 430 | layer.trainable = True 431 | 432 | #G does not update 433 | self.G.trainable = False 434 | for layer in self.G.layers: 435 | layer.trainable = False 436 | 437 | #S does not update 438 | self.S.trainable = False 439 | for layer in self.S.layers: 440 | layer.trainable = False 441 | 442 | #This model is simple sequential one with inputs and outputs 443 | inp_s = [] 444 | ss = [] 445 | for _ in range(self.style_layers): 446 | inp_s.append(Input([latent_size])) 447 | ss.append(self.S(inp_s[-1])) 448 | 449 | 450 | gi2 = Input(shape = [im_size, im_size, 1]) 451 | gi3 = Input(shape = [1]) 452 | 453 | gf = self.G(ss + [gi2, gi3]) 454 | df = self.D(gf) 455 | 456 | ri = Input(shape = [im_size, im_size, 3]) 457 | dr = self.D(ri) 458 | 459 | self.DMM = Model(inputs = [ri] + inp_s + [gi2, gi3], outputs=[dr, df, dr]) 460 | 461 | partial_gp_loss = partial(gradient_penalty_loss, averaged_samples = ri, weight = 50) 462 | 463 | self.DMM.compile(optimizer=Adam(self.LR, beta_1 = 0, beta_2 = 0.99, decay = 0.00001), loss=['mse', 'mse', partial_gp_loss]) 464 | 465 | return self.DMM 466 | 467 | def predict(self, inputs): 468 | 469 | for i in range(len(inputs) - 2): 470 | inputs[i] = self.S.predict(inputs[i]) 471 | 472 | return self.G.predict(inputs, batch_size = 4) 473 | 474 | 475 | from keras.datasets import cifar10 476 | class WGAN(object): 477 | 478 | def __init__(self, steps = 1, lr = 0.0001, decay = 0.00001, silent = True): 479 | 480 | self.GAN = GAN(steps = steps, lr = lr, decay = decay) 481 | self.DisModel = self.GAN.DisModel() 482 | self.AdModel = self.GAN.AdModel() 483 | self.MixModel = self.GAN.MixModel() 484 | self.MixModelD = self.GAN.MixModelD() 485 | self.generator = self.GAN.generator() 486 | 487 | self.lastblip = time.clock() 488 | 489 | self.noise_level = 0 490 | 491 | #self.ImagesA = import_images(directory, True) 492 | self.im = dataGenerator(directory, n_images, suffix = suff, flip = True) 493 | #(self.im, _), (_, _) = cifar10.load_data() 494 | #self.im = np.float32(self.im) / 255 495 | 496 | self.silent = silent 497 | 498 | #Train Generator to be in the middle, not all the way at real. Apparently works better?? 499 | self.ones = np.ones((BATCH_SIZE, 1), dtype=np.float32) 500 | self.zeros = np.zeros((BATCH_SIZE, 1), dtype=np.float32) 501 | self.nones = -self.ones 502 | 503 | self.enoise = noise(8) 504 | self.enoiseImage = noiseImage(8) 505 | 506 | self.t = [[], []] 507 | 508 | def train(self): 509 | 510 | #Train Alternating 511 | t1 = time.clock() 512 | if self.GAN.steps % 10 <= 5: 513 | a = self.train_dis() 514 | t2 = time.clock() 515 | b = self.train_gen() 516 | t3 = time.clock() 517 | else: 518 | a = self.train_mix_d() 519 | t2 = time.clock() 520 | b = self.train_mix_g() 521 | t3 = time.clock() 522 | 523 | self.t[0].append(t2-t1) 524 | self.t[1].append(t3-t2) 525 | 526 | #Print info 527 | if self.GAN.steps % 20 == 0 and not self.silent: 528 | print("\n\nRound " + str(self.GAN.steps) + ":") 529 | print("D: " + str(a)) 530 | print("G: " + str(b)) 531 | s = round((time.clock() - self.lastblip) * 1000) / 1000 532 | print("T: " + str(s) + " sec") 533 | self.lastblip = time.clock() 534 | 535 | if self.GAN.steps % 100 == 0: 536 | print("TD: " + str(np.sum(self.t[0]))) 537 | print("TG: " + str(np.sum(self.t[1]))) 538 | 539 | self.t = [[], []] 540 | 541 | 542 | #Save Model 543 | if self.GAN.steps % 500 == 0: 544 | self.save(floor(self.GAN.steps / 10000)) 545 | if self.GAN.steps % 1000 == 0: 546 | self.evaluate(floor(self.GAN.steps / 1000)) 547 | self.evalMix(floor(self.GAN.steps / 1000)) 548 | self.evalTrunc(floor(self.GAN.steps / 1000)) 549 | 550 | 551 | self.GAN.steps = self.GAN.steps + 1 552 | 553 | def train_dis(self): 554 | 555 | #Get Data 556 | #self.im.get_batch(BATCH_SIZE) 557 | #get_rand(self.im, BATCH_SIZE) 558 | train_data = [self.im.get_batch(BATCH_SIZE), noise(BATCH_SIZE), noiseImage(BATCH_SIZE), self.ones] 559 | 560 | #Train 561 | d_loss = self.DisModel.train_on_batch(train_data, [self.ones, self.nones, self.ones]) 562 | 563 | return d_loss 564 | 565 | def train_mix_d(self): 566 | 567 | threshold = np.int32(np.random.uniform(0.0, self.GAN.style_layers, size = [BATCH_SIZE])) 568 | n1 = noise(BATCH_SIZE) 569 | n2 = noise(BATCH_SIZE) 570 | 571 | n = [] 572 | 573 | for i in range(self.GAN.style_layers): 574 | n.append([]) 575 | for j in range(BATCH_SIZE): 576 | if i < threshold[j]: 577 | n[i].append(n1[j]) 578 | else: 579 | n[i].append(n2[j]) 580 | n[i] = np.array(n[i]) 581 | 582 | images = self.im.get_batch(BATCH_SIZE) 583 | 584 | #Train 585 | d_loss = self.MixModelD.train_on_batch([images] + n + [noiseImage(BATCH_SIZE), self.ones], [self.ones, self.nones, self.ones]) 586 | 587 | return d_loss 588 | 589 | def train_gen(self): 590 | 591 | #Train 592 | g_loss = self.AdModel.train_on_batch([noise(BATCH_SIZE), noiseImage(BATCH_SIZE), self.ones], self.ones) 593 | 594 | return g_loss 595 | 596 | def train_mix_g(self): 597 | 598 | threshold = np.int32(np.random.uniform(0.0, self.GAN.style_layers, size = [BATCH_SIZE])) 599 | n1 = noise(BATCH_SIZE) 600 | n2 = noise(BATCH_SIZE) 601 | 602 | n = [] 603 | 604 | for i in range(self.GAN.style_layers): 605 | n.append([]) 606 | for j in range(BATCH_SIZE): 607 | if i < threshold[j]: 608 | n[i].append(n1[j]) 609 | else: 610 | n[i].append(n2[j]) 611 | n[i] = np.array(n[i]) 612 | 613 | 614 | #Train 615 | g_loss = self.MixModel.train_on_batch(n + [noiseImage(BATCH_SIZE), self.ones], self.ones) 616 | 617 | return g_loss 618 | 619 | def evaluate(self, num = 0): #8x8 images, bottom row is constant 620 | 621 | n = noise(56) 622 | n2 = noiseImage(56) 623 | 624 | im = self.GAN.predict(([n] * self.GAN.style_layers) + [n2, np.ones([56, 1])]) 625 | im3 = self.GAN.predict(([self.enoise] * self.GAN.style_layers) + [self.enoiseImage, np.ones([8, 1])]) 626 | 627 | r = [] 628 | r.append(np.concatenate(im[:8], axis = 1)) 629 | r.append(np.concatenate(im[8:16], axis = 1)) 630 | r.append(np.concatenate(im[16:24], axis = 1)) 631 | r.append(np.concatenate(im[24:32], axis = 1)) 632 | r.append(np.concatenate(im[32:40], axis = 1)) 633 | r.append(np.concatenate(im[40:48], axis = 1)) 634 | r.append(np.concatenate(im[48:56], axis = 1)) 635 | r.append(np.concatenate(im3[:8], axis = 1)) 636 | 637 | c1 = np.concatenate(r, axis = 0) 638 | 639 | x = Image.fromarray(np.uint8(c1*255), mode = cmode) 640 | 641 | x.save("Results/i"+str(num)+"ii.jpg") 642 | 643 | 644 | def evalMix(self, num = 0): 645 | 646 | bn = noise(8) 647 | sn = noise(8) 648 | 649 | n = [] 650 | for i in range(self.GAN.style_layers): 651 | n.append([]) 652 | 653 | for i in range(8): 654 | for j in range(8): 655 | for l in range(0, int(self.GAN.style_layers/2)): 656 | n[l].append(bn[i]) 657 | for l in range(int(self.GAN.style_layers/2), self.GAN.style_layers): 658 | n[l].append(sn[j]) 659 | 660 | for i in range(self.GAN.style_layers): 661 | n[i] = np.array(n[i]) 662 | 663 | 664 | im = self.GAN.predict(n + [noiseImage(64), np.ones([64, 1])]) 665 | 666 | r = [] 667 | r.append(np.concatenate(im[:8], axis = 1)) 668 | r.append(np.concatenate(im[8:16], axis = 1)) 669 | r.append(np.concatenate(im[16:24], axis = 1)) 670 | r.append(np.concatenate(im[24:32], axis = 1)) 671 | r.append(np.concatenate(im[32:40], axis = 1)) 672 | r.append(np.concatenate(im[40:48], axis = 1)) 673 | r.append(np.concatenate(im[48:56], axis = 1)) 674 | r.append(np.concatenate(im[56:], axis = 1)) 675 | c = np.concatenate(r, axis = 0) 676 | 677 | x = Image.fromarray(np.uint8(c*255), mode = cmode) 678 | 679 | x.save("Results/i"+str(num)+"mm.jpg") 680 | 681 | def evalTrunc(self, num = 0, trunc = 2.0, scale = 1, nscale = 0.8, custom_noise = np.array([0])): 682 | 683 | ss = self.GAN.S.predict(noise(2048), batch_size = 128) 684 | mean = np.mean(ss, axis = 0) 685 | std = np.std(ss, axis = 0) 686 | 687 | if custom_noise.shape[0] != 16: 688 | noi = noise(16) 689 | else: 690 | noi = custom_noise 691 | 692 | n = self.GAN.S.predict(noi) 693 | n2 = noiseImage(16) * nscale 694 | 695 | for i in range(n.shape[0]): 696 | n[i] = np.clip(n[i], mean - (std*trunc), mean + (std * trunc)) 697 | 698 | if scale != 1: 699 | n[i] = (n[i] - mean) * scale + mean 700 | 701 | im = self.GAN.G.predict(([n] * self.GAN.style_layers) + [n2, np.ones([16, 1])]) 702 | 703 | r = [] 704 | r.append(np.concatenate(im[:4], axis = 1)) 705 | r.append(np.concatenate(im[4:8], axis = 1)) 706 | r.append(np.concatenate(im[8:12], axis = 1)) 707 | r.append(np.concatenate(im[12:16], axis = 1)) 708 | 709 | c1 = np.concatenate(r, axis = 0) 710 | 711 | x = Image.fromarray(np.uint8(c1*255), mode = cmode) 712 | 713 | x.save("Results/i"+str(num)+"tt.jpg") 714 | 715 | def saveModel(self, model, name, num): #Save a Model 716 | json = model.to_json() 717 | with open("Models/"+name+".json", "w") as json_file: 718 | json_file.write(json) 719 | 720 | model.save_weights("Models/"+name+"_"+str(num)+".h5") 721 | 722 | def loadModel(self, name, num): #Load a Model 723 | 724 | file = open("Models/"+name+".json", 'r') 725 | json = file.read() 726 | file.close() 727 | 728 | mod = model_from_json(json, custom_objects = {'AdaInstanceNormalization': AdaInstanceNormalization}) 729 | mod.load_weights("Models/"+name+"_"+str(num)+".h5") 730 | 731 | return mod 732 | 733 | def save(self, num): #Save JSON and Weights into /Models/ 734 | self.saveModel(self.GAN.S, "sty", num) 735 | self.saveModel(self.GAN.G, "gen", num) 736 | self.saveModel(self.GAN.D, "dis", num) 737 | 738 | 739 | def load(self, num): #Load JSON and Weights from /Models/ 740 | steps1 = self.GAN.steps 741 | 742 | self.GAN = None 743 | self.GAN = GAN() 744 | 745 | #Load Models 746 | self.GAN.S = self.loadModel("sty", num) 747 | self.GAN.G = self.loadModel("gen", num) 748 | self.GAN.D = self.loadModel("dis", num) 749 | 750 | self.GAN.steps = steps1 751 | 752 | self.generator = self.GAN.generator() 753 | self.DisModel = self.GAN.DisModel() 754 | self.AdModel = self.GAN.AdModel() 755 | self.MixModel = self.GAN.MixModel() 756 | self.MixModelD = self.GAN.MixModelD() 757 | 758 | 759 | 760 | if __name__ == "__main__": 761 | model = WGAN(lr = 0.0001, silent = False) 762 | 763 | while(True): 764 | model.train() 765 | 766 | 767 | -------------------------------------------------------------------------------- /stylegan.py: -------------------------------------------------------------------------------- 1 | 2 | #import numpy as np 3 | from PIL import Image 4 | from math import floor 5 | import numpy as np 6 | import time 7 | from functools import partial 8 | from random import random 9 | 10 | #Config Stuff 11 | im_size = 256 12 | latent_size = 512 13 | BATCH_SIZE = 4 14 | directory = "Flowers" 15 | n_images = 8189 16 | suff = 'jpg' 17 | 18 | #Style Z 19 | def noise(n): 20 | return np.random.normal(0.0, 1.0, size = [n, latent_size]) 21 | 22 | #Noise Sample 23 | def noiseImage(n): 24 | return np.random.uniform(0.0, 1.0, size = [n, im_size, im_size, 1]) 25 | 26 | #Get random samples from an array 27 | def get_rand(array, amount): 28 | 29 | idx = np.random.randint(0, array.shape[0], amount) 30 | return array[idx] 31 | 32 | #Import Images Function 33 | def import_images(loc, flip = True, suffix = 'png'): 34 | 35 | out = [] 36 | cont = True 37 | i = 1 38 | print("Importing Images...") 39 | 40 | while(cont): 41 | try: 42 | temp = Image.open("data/"+loc+"/im ("+str(i)+")."+suffix+"").convert('RGB') 43 | temp = temp.resize((im_size, im_size), Image.BICUBIC) 44 | temp1 = np.array(temp.convert('RGB'), dtype='float32') / 255 45 | out.append(temp1) 46 | if flip: 47 | out.append(np.flip(out[-1], 1)) 48 | 49 | i = i + 1 50 | except: 51 | cont = False 52 | 53 | print(str(i-1) + " images imported.") 54 | 55 | return np.array(out) 56 | 57 | def normalize(arr): 58 | return (arr - np.mean(arr)) / (np.std(arr) + 1e-7) 59 | 60 | #This is the REAL data generator, which can take images from disk and temporarily use them in your program. 61 | #Probably could/should get optimized at some point 62 | class dataGenerator(object): 63 | 64 | def __init__(self, loc, n, flip = True, suffix = 'png'): 65 | self.loc = "data/"+loc 66 | self.flip = flip 67 | self.suffix = suffix 68 | self.n = n 69 | 70 | def get_batch(self, amount): 71 | 72 | idx = np.random.randint(0, self.n - 1, amount) + 1 73 | out = [] 74 | 75 | for i in idx: 76 | temp = Image.open(self.loc+"/im ("+str(i)+")."+self.suffix+"").convert('RGB') 77 | temp1 = np.array(temp.convert('RGB'), dtype='float32') / 255 78 | if self.flip and random() > 0.5: 79 | temp1 = np.flip(temp1, 1) 80 | 81 | out.append(temp1) 82 | 83 | 84 | return np.array(out) 85 | 86 | 87 | 88 | 89 | #Imports for layers and models 90 | from keras.layers import Conv2D, Dense, AveragePooling2D, LeakyReLU, Activation 91 | from keras.layers import Reshape, UpSampling2D, Dropout, Flatten, Input, add, Cropping2D 92 | from keras.models import model_from_json, Model 93 | from keras.optimizers import Adam 94 | import keras.backend as K 95 | 96 | from AdaIN import AdaInstanceNormalization 97 | 98 | 99 | #r1/r2 gradient penalty 100 | def gradient_penalty_loss(y_true, y_pred, averaged_samples, weight): 101 | gradients = K.gradients(y_pred, averaged_samples)[0] 102 | gradients_sqr = K.square(gradients) 103 | gradient_penalty = K.sum(gradients_sqr, 104 | axis=np.arange(1, len(gradients_sqr.shape))) 105 | 106 | # weight * ||grad||^2 107 | # Penalize the gradient norm 108 | return K.mean(gradient_penalty * weight) 109 | 110 | #Upsample, Convolution, AdaIN, Noise, Activation, Convolution, AdaIN, Noise, Activation 111 | def g_block(inp, style, noise, fil, u = True): 112 | 113 | b = Dense(fil)(style) 114 | b = Reshape([1, 1, fil])(b) 115 | g = Dense(fil)(style) 116 | g = Reshape([1, 1, fil])(g) 117 | 118 | n = Conv2D(filters = fil, kernel_size = 1, padding = 'same', kernel_initializer = 'he_normal')(noise) 119 | 120 | if u: 121 | out = UpSampling2D(interpolation = 'bilinear')(inp) 122 | out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal')(out) 123 | else: 124 | out = Activation('linear')(inp) 125 | 126 | out = AdaInstanceNormalization()([out, b, g]) 127 | out = add([out, n]) 128 | out = LeakyReLU(0.01)(out) 129 | 130 | b = Dense(fil)(style) 131 | b = Reshape([1, 1, fil])(b) 132 | g = Dense(fil)(style) 133 | g = Reshape([1, 1, fil])(g) 134 | 135 | n = Conv2D(filters = fil, kernel_size = 1, padding = 'same', kernel_initializer = 'he_normal')(noise) 136 | 137 | out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal')(out) 138 | out = AdaInstanceNormalization()([out, b, g]) 139 | out = add([out, n]) 140 | out = LeakyReLU(0.01)(out) 141 | 142 | return out 143 | 144 | #Convolution, Activation, Pooling, Convolution, Activation 145 | def d_block(inp, fil, p = True): 146 | 147 | route2 = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal')(inp) 148 | route2 = LeakyReLU(0.01)(route2) 149 | if p: 150 | route2 = AveragePooling2D()(route2) 151 | route2 = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal')(route2) 152 | out = LeakyReLU(0.01)(route2) 153 | 154 | return out 155 | 156 | #This object holds the models 157 | class GAN(object): 158 | 159 | def __init__(self, lr = 0.0001): 160 | 161 | #Models 162 | self.D = None 163 | self.G = None 164 | 165 | self.DM = None 166 | self.AM = None 167 | 168 | #Config 169 | self.LR = lr 170 | self.steps = 1 171 | 172 | #Init Models 173 | self.discriminator() 174 | self.generator() 175 | 176 | def discriminator(self): 177 | 178 | if self.D: 179 | return self.D 180 | 181 | inp = Input(shape = [im_size, im_size, 3]) 182 | 183 | # Size 184 | x = d_block(inp, 16) #Size / 2 185 | x = d_block(x, 32) #Size / 4 186 | x = d_block(x, 64) #Size / 8 187 | 188 | if (im_size > 32): 189 | x = d_block(x, 128) #Size / 16 190 | 191 | if (im_size > 64): 192 | x = d_block(x, 192) #Size / 32 193 | 194 | if (im_size > 128): 195 | x = d_block(x, 256) #Size / 64 196 | 197 | if (im_size > 256): 198 | x = d_block(x, 384) #Size / 128 199 | 200 | if (im_size > 512): 201 | x = d_block(x, 512) #Size / 256 202 | 203 | 204 | x = Flatten()(x) 205 | 206 | x = Dense(128)(x) 207 | x = Activation('relu')(x) 208 | 209 | x = Dropout(0.6)(x) 210 | x = Dense(1)(x) 211 | 212 | self.D = Model(inputs = inp, outputs = x) 213 | 214 | return self.D 215 | 216 | def generator(self): 217 | 218 | if self.G: 219 | return self.G 220 | 221 | #Style FC, I only used 2 fully connected layers instead of 8 for faster training 222 | inp_s = Input(shape = [latent_size]) 223 | sty = Dense(512, kernel_initializer = 'he_normal')(inp_s) 224 | sty = LeakyReLU(0.1)(sty) 225 | sty = Dense(512, kernel_initializer = 'he_normal')(sty) 226 | sty = LeakyReLU(0.1)(sty) 227 | 228 | #Get the noise image and crop for each size 229 | inp_n = Input(shape = [im_size, im_size, 1]) 230 | noi = [Activation('linear')(inp_n)] 231 | curr_size = im_size 232 | while curr_size > 4: 233 | curr_size = int(curr_size / 2) 234 | noi.append(Cropping2D(int(curr_size/2))(noi[-1])) 235 | 236 | #Here do the actual generation stuff 237 | inp = Input(shape = [1]) 238 | x = Dense(4 * 4 * 512, kernel_initializer = 'he_normal')(inp) 239 | x = Reshape([4, 4, 512])(x) 240 | x = g_block(x, sty, noi[-1], 512, u=False) 241 | 242 | if(im_size >= 1024): 243 | x = g_block(x, sty, noi[7], 512) # Size / 64 244 | if(im_size >= 512): 245 | x = g_block(x, sty, noi[6], 384) # Size / 64 246 | if(im_size >= 256): 247 | x = g_block(x, sty, noi[5], 256) # Size / 32 248 | if(im_size >= 128): 249 | x = g_block(x, sty, noi[4], 192) # Size / 16 250 | if(im_size >= 64): 251 | x = g_block(x, sty, noi[3], 128) # Size / 8 252 | 253 | x = g_block(x, sty, noi[2], 64) # Size / 4 254 | x = g_block(x, sty, noi[1], 32) # Size / 2 255 | x = g_block(x, sty, noi[0], 16) # Size 256 | 257 | x = Conv2D(filters = 3, kernel_size = 1, padding = 'same', activation = 'sigmoid')(x) 258 | 259 | self.G = Model(inputs = [inp_s, inp_n, inp], outputs = x) 260 | 261 | return self.G 262 | 263 | def AdModel(self): 264 | 265 | #D does not update 266 | self.D.trainable = False 267 | for layer in self.D.layers: 268 | layer.trainable = False 269 | 270 | #G does update 271 | self.G.trainable = True 272 | for layer in self.G.layers: 273 | layer.trainable = True 274 | 275 | #This model is simple sequential one with inputs and outputs 276 | gi = Input(shape = [latent_size]) 277 | gi2 = Input(shape = [im_size, im_size, 1]) 278 | gi3 = Input(shape = [1]) 279 | 280 | gf = self.G([gi, gi2, gi3]) 281 | df = self.D(gf) 282 | 283 | self.AM = Model(inputs = [gi, gi2, gi3], outputs = df) 284 | 285 | self.AM.compile(optimizer = Adam(self.LR, beta_1 = 0, beta_2 = 0.99, decay = 0.00001), loss = 'mse') 286 | 287 | return self.AM 288 | 289 | def DisModel(self): 290 | 291 | #D does update 292 | self.D.trainable = True 293 | for layer in self.D.layers: 294 | layer.trainable = True 295 | 296 | #G does not update 297 | self.G.trainable = False 298 | for layer in self.G.layers: 299 | layer.trainable = False 300 | 301 | # Real Pipeline 302 | ri = Input(shape = [im_size, im_size, 3]) 303 | dr = self.D(ri) 304 | 305 | # Fake Pipeline 306 | gi = Input(shape = [latent_size]) 307 | gi2 = Input(shape = [im_size, im_size, 1]) 308 | gi3 = Input(shape = [1]) 309 | gf = self.G([gi, gi2, gi3]) 310 | df = self.D(gf) 311 | 312 | # Samples for gradient penalty 313 | # For r1 use real samples (ri) 314 | # For r2 use fake samples (gf) 315 | da = self.D(ri) 316 | 317 | # Model With Inputs and Outputs 318 | self.DM = Model(inputs=[ri, gi, gi2, gi3], outputs=[dr, df, da]) 319 | 320 | # Create partial of gradient penalty loss 321 | # For r1, averaged_samples = ri 322 | # For r2, averaged_samples = gf 323 | # Weight of 10 typically works 324 | partial_gp_loss = partial(gradient_penalty_loss, averaged_samples = ri, weight = 5) 325 | 326 | #Compile With Corresponding Loss Functions 327 | self.DM.compile(optimizer=Adam(self.LR, beta_1 = 0, beta_2 = 0.99, decay = 0.00001), loss=['mse', 'mse', partial_gp_loss]) 328 | 329 | return self.DM 330 | 331 | 332 | 333 | class WGAN(object): 334 | 335 | def __init__(self, steps = -1, lr = 0.0001, silent = True): 336 | 337 | self.GAN = GAN(lr = lr) 338 | self.DisModel = self.GAN.DisModel() 339 | self.AdModel = self.GAN.AdModel() 340 | self.generator = self.GAN.generator() 341 | 342 | if steps >= 0: 343 | self.GAN.steps = steps 344 | 345 | self.lastblip = time.clock() 346 | 347 | self.noise_level = 0 348 | 349 | #self.ImagesA = import_images(directory, True) 350 | self.im = dataGenerator(directory, n_images, suffix = suff, flip = True) 351 | #(self.im, _), (_, _) = cifar10.load_data() 352 | #self.im = np.float32(self.im) / 255 353 | 354 | self.silent = silent 355 | 356 | #Train Generator to be in the middle, not all the way at real. Apparently works better?? 357 | self.ones = np.ones((BATCH_SIZE, 1), dtype=np.float32) 358 | self.zeros = np.zeros((BATCH_SIZE, 1), dtype=np.float32) 359 | self.nones = -self.ones 360 | 361 | self.enoise = noise(8) 362 | self.enoiseImage = noiseImage(8) 363 | 364 | def train(self): 365 | 366 | #Train Alternating 367 | a = self.train_dis() 368 | b = self.train_gen() 369 | 370 | #Print info 371 | if self.GAN.steps % 20 == 0 and not self.silent: 372 | print("\n\nRound " + str(self.GAN.steps) + ":") 373 | print("D: " + str(a)) 374 | print("G: " + str(b)) 375 | s = round((time.clock() - self.lastblip) * 1000) / 1000 376 | print("T: " + str(s) + " sec") 377 | self.lastblip = time.clock() 378 | 379 | #Save Model 380 | if self.GAN.steps % 500 == 0: 381 | self.save(floor(self.GAN.steps / 10000)) 382 | if self.GAN.steps % 1000 == 0: 383 | self.evaluate(floor(self.GAN.steps / 1000)) 384 | 385 | 386 | self.GAN.steps = self.GAN.steps + 1 387 | 388 | def train_dis(self): 389 | 390 | #Get Data 391 | train_data = [self.im.get_batch(BATCH_SIZE), noise(BATCH_SIZE), noiseImage(BATCH_SIZE), self.ones] 392 | 393 | #Train 394 | d_loss = self.DisModel.train_on_batch(train_data, [self.ones, self.nones, self.ones]) 395 | 396 | return d_loss 397 | 398 | def train_gen(self): 399 | 400 | #Train 401 | g_loss = self.AdModel.train_on_batch([noise(BATCH_SIZE), noiseImage(BATCH_SIZE), self.ones], self.zeros) 402 | 403 | return g_loss 404 | 405 | def evaluate(self, num = 0, trunc = 2.0): #8x4 images, bottom row is constant 406 | 407 | n = noise(32) 408 | n2 = noiseImage(32) 409 | 410 | im2 = self.generator.predict([n, n2, np.ones([32, 1])]) 411 | im3 = self.generator.predict([self.enoise, self.enoiseImage, np.ones([8, 1])]) 412 | 413 | r12 = np.concatenate(im2[:8], axis = 1) 414 | r22 = np.concatenate(im2[8:16], axis = 1) 415 | r32 = np.concatenate(im2[16:24], axis = 1) 416 | r43 = np.concatenate(im3[:8], axis = 1) 417 | 418 | c1 = np.concatenate([r12, r22, r32, r43], axis = 0) 419 | 420 | x = Image.fromarray(np.uint8(c1*255)) 421 | 422 | x.save("Results/i"+str(num)+".jpg") 423 | 424 | def evaluate2(self, s1, s2, n1, n2, num = 0, weight = 0.5): 425 | 426 | s = normalize((s2 * weight) + (s1 * (1 - weight))) 427 | n = (n2 * weight) + (n1 * (1 - weight)) 428 | 429 | im2 = self.generator.predict([s, n, np.ones([32, 1])]) 430 | 431 | r12 = np.concatenate(im2[:8], axis = 1) 432 | r22 = np.concatenate(im2[8:16], axis = 1) 433 | r32 = np.concatenate(im2[16:24], axis = 1) 434 | r43 = np.concatenate(im2[24:], axis = 1) 435 | 436 | c1 = np.concatenate([r12, r22, r32, r43], axis = 0) 437 | 438 | x = Image.fromarray(np.uint8(c1*255)) 439 | 440 | x.save("Results/i"+str(num)+".jpg") 441 | 442 | def evalTrunc(self, num = 0, trunc = 1.8): 443 | 444 | n = np.clip(noise(16), -trunc, trunc) 445 | n2 = noiseImage(16) 446 | 447 | im2 = self.generator.predict([n, n2, np.ones([16, 1])]) 448 | 449 | r12 = np.concatenate(im2[:4], axis = 1) 450 | r22 = np.concatenate(im2[4:8], axis = 1) 451 | r32 = np.concatenate(im2[8:12], axis = 1) 452 | r43 = np.concatenate(im2[12:], axis = 1) 453 | 454 | c1 = np.concatenate([r12, r22, r32, r43], axis = 0) 455 | 456 | x = Image.fromarray(np.uint8(c1*255)) 457 | 458 | x.save("Results/t"+str(num)+".jpg") 459 | 460 | 461 | def saveModel(self, model, name, num): #Save a Model 462 | json = model.to_json() 463 | with open("Models/"+name+".json", "w") as json_file: 464 | json_file.write(json) 465 | 466 | model.save_weights("Models/"+name+"_"+str(num)+".h5") 467 | 468 | def loadModel(self, name, num): #Load a Model 469 | 470 | file = open("Models/"+name+".json", 'r') 471 | json = file.read() 472 | file.close() 473 | 474 | mod = model_from_json(json, custom_objects = {'AdaInstanceNormalization': AdaInstanceNormalization}) 475 | mod.load_weights("Models/"+name+"_"+str(num)+".h5") 476 | 477 | return mod 478 | 479 | def save(self, num): #Save JSON and Weights into /Models/ 480 | self.saveModel(self.GAN.G, "gen", num) 481 | self.saveModel(self.GAN.D, "dis", num) 482 | 483 | 484 | def load(self, num): #Load JSON and Weights from /Models/ 485 | steps1 = self.GAN.steps 486 | 487 | self.GAN = None 488 | self.GAN = GAN() 489 | 490 | #Load Models 491 | self.GAN.G = self.loadModel("gen", num) 492 | self.GAN.D = self.loadModel("dis", num) 493 | 494 | self.GAN.steps = steps1 495 | 496 | self.generator = self.GAN.generator() 497 | self.DisModel = self.GAN.DisModel() 498 | self.AdModel = self.GAN.AdModel() 499 | 500 | 501 | 502 | 503 | if __name__ == "__main__": 504 | model = WGAN(lr = 0.0003, silent = False) 505 | model.load(219) 506 | 507 | for i in range(1000): 508 | model.evalTrunc(i) 509 | 510 | while(False): 511 | model.train() 512 | 513 | 514 | --------------------------------------------------------------------------------