0

I'm trying to build an autoencoder like network but I don't know how to specify the output shape of the network. I have an input of size mxn and a paired expected output of size pxq. I've seen

Calculate the Output size in Convolution layer

Getting the output shape of deconvolution layer using tf.nn.conv2d_transpose in tensorflow

but is there a way force an output shape without having to work out a bunch of math for every input shape?

vnal
  • 53
  • 7

1 Answers1

1

I really don't think there is a way to do this (tough I will be happy to learn otherwise), since this output shape of a conv layer of any kind is the result of a mathematical operation (convolution) with several parameters. because of that, the resulting shape has to be one of the possible shapes, based on the input tensor and the parameters (stride, kernel size and so on).

this is in contrast to a dense (fully-connected layer), where you can get any shape you want as long as its a single number (4, 60 or 5000 - but not (60,60)).

one small trick that can help you in this kind of situations sometimes is to get the shape of the previous layer print it so you know what parameters you need for the next layer and make sure your calculations are correct:

import keras.backend as K 
x = Conv2D()(x) # or any other layer
shape = K.int_shape(x)
print(shape)
x = Conv2D()(x) 
Moran Reznik
  • 1,201
  • 2
  • 11
  • 28