I am trying to utilize the SubpixelConv2D function
I am training a GAN and wanted to up sample using subpixel instead of interpolation or convolution transpose due to the artifacts they leave behind.
I am using Tensorflow/1.4.0 and Keras/2.2.4
When I try and call the function I receive the following error:
"ValueError: None values not supported."
I call the function using :
import tensorflow as tf
from tensorflow import keras
import Utils
def up_sampling_block(model):
#model = keras.layers.Conv2DTranspose(filters = filters, kernel_size = kernal_size, strides = strides, padding = "same")(model)
model = Utils.SubpixelConv2D(model)(model)
#model = keras.layers.UpSampling2D(size = 2)(model)
#model = keras.layers.Conv2D(filters = filters, kernel_size = kernal_size, strides = strides, padding = "same")(model)
#model = keras.layers.LeakyReLU(alpha = 0.2)(model)
return model
and the function is as follows:
# Subpixel Conv will upsample from (h, w, c) to (h/r, w/r, c/r^2)
def SubpixelConv2D(input_shape, scale=4):
def subpixel_shape(input_shape, scale):
dims = [input_shape[0], input_shape[1] * scale, input_shape[2] * scale, int(input_shape[3] / (scale ** 2))]
output_shape = tuple(dims)
return output_shape
def subpixel(x):
return tf.depth_to_space(x, scale)
return keras.layers.Lambda(subpixel, subpixel_shape)
The size of the input tensor is (?,48,48,64), and I believe the "?" for the batch size is causing the error, but I can't seem to fix the problem.
The second function of the Lambda layer has to be a function of the input shape only:
subpixel_shape(input_shape)but your takes a second argument called scale that default to undefined when only input_shape is passed. Try passinglambda input_shape: subpixel_shape(input_shape, scale)tokeras.layers.Lambdafunction instead. Then scale will default to 4 as the outer function dictates. Or remove thescalefrom thesubpixel_shapefunction arguments: