I'm trying to implement a CycleGAN in Keras and when trying to translate a base image without training I get this error, which adds a None to the Input shape of my Generator. I get the same results with generatorAtoB.predict(), so that isn't the problem. Here's the code for the architecture I'm trying to implement. X2[0] is just a numpy array with shapes (256, 256, 3), which is mentioned in the input shape of my function. Here's the error log and the code I'm using.
EDIT
I found the error, keras expects a batch size as the first dimension, so reshaping my array to (1, 256, 256, 3) solves it.
Error Log
ValueError: Input 0 is incompatible with layer model_7: expected shape=(None, 256, 256, 3), found shape=(256, 256, 3)
Model architecture
# residual block for the generator
def res_block(filters, inputs):
# kernel weights initializer
init = RandomNormal(stddev=0.02)
x = Conv2D(filters, 3, padding='same', kernel_initializer=init)(inputs)
x = InstanceNormalization(axis=-1)(x)
x = Activation('selu')(x)
x = Conv2D(filters, 3, padding='same', kernel_initializer=init)(x)
x = InstanceNormalization(axis=-1)(x)
# concatenate second conv layer with the inputs
x = Concatenate()([x, inputs])
return x
# generator function
def generator(img_shape = (256, 256, 3), n_blocks = 6):
# weight initialization
init = RandomNormal(stddev=0.02)
inputs = Input(shape = img_shape)
x = Conv2D(16, 5, padding='same', kernel_initializer=init)(inputs)
x = InstanceNormalization(axis=-1)(x)
x = Activation('selu')(x)
x = Conv2D(32, 3, 2, padding='same', kernel_initializer=init)(x)
x = InstanceNormalization(axis=-1)(x)
x = Activation('selu')(x)
x = Conv2D(64, 3, 2, padding='same', kernel_initializer=init)(x)
x = InstanceNormalization(axis=-1)(x)
x = Activation('selu')(x)
# add residual blocks to our generator
for _ in range(n_blocks):
x = res_block(128, x)
# transpose convolutions
x = Conv2DTranspose(32, 3, strides = 2, padding='same', kernel_initializer=init)(x)
x = InstanceNormalization(axis=-1)(x)
x = Activation('selu')(x)
x = Conv2DTranspose(64, 3, 2, padding='same', kernel_initializer=init)(x)
x = InstanceNormalization(axis=-1)(x)
x = Activation('selu')(x)
# output layer
x = Conv2D(3, 7, padding='same', kernel_initializer=init)(x)
x = InstanceNormalization(axis=-1)(x)
outputs = Activation('tanh')(x)
# create the model
model = Model(inputs, outputs)
return model
# predicting the target to a base image
IMG_SHAPE = (256, 256, 3)
generator_AtoB = generator(IMG_SHAPE)
generator_AtoB(X2[0])