4
$\begingroup$

I want to do a GAN with coloured pictures. This means I need a three dimensional input and therefore I like to use conv3d and conv3d_transpose.

Unfortunately in the TensorFlow documentation, I can't find any formula for the output shape. Can anyone give me a hint on how to find the shape of the function's results?

$\endgroup$
4
$\begingroup$

Although your input data is three dimensional, you have to use Conv2D for your task. I guess Conv3d is used for data with temporal characteristic, yours is just a simple picture. To illustrate why you should Conv2D, suppose your input image is 224 * 224 * 3 and you employ a Conv2D layer with 10 filters. You have to specify stride and padding in order to specify the output shape. You have to specify dimensions to illustrate the height and width of you filters, also known as kernels, filter size will affect the output size if you assign padding to 'valid'. Here, there is a point. Suppose you have specified the filter size a 10 * 10 filter, then if the input shape was 224 * 224 * 1, each filter would be of size 10 * 10 * 1 to fit the input area. Now that the input is of size 224 * 224 * 3 the size of each kernel is 10 * 10 * 3 to fit the input volume. Consider in all cases the output of each convolution operation, better to say cross correlation, is a scalar. For more information take a look at videos here and for your case I encourage you watching Convolution Over Volume.

$\endgroup$
2
$\begingroup$

By convention, in addition to the input feature map - which may be 1D for audio, 2D for a typical image, 3D for a sequence of video frames - for a convolutional network, there are two additional dimensions:

  1. The number of examples in a batch or mini-batch, counting even a single example as a mini-batch of size 1)

  2. The number of feature maps or channels in the current layer, counting even a single grayscale image as an array of 1 channel, or RGB (or other colour space) image as 3 channels

So in your case you will want a conv2d layer to process the image. The precise order of dimensions varies a lot - check your library docs, and also note most libraries allow you to alter the arrangement for cross-compatibility with different toolchains. But a typical layer input or output might be arranged as $\text{BatchSize} \times \text{Height} \times \text{Width} \times \text{Channels}$

The input and output dimensions are the same (but usually with different sizes), so that layers can be chained together naturally.

The documentation you linked does in fact say this (sort of, it could explain the sameness in more detail, since data type and dimensionality are in fact the same and both could vary):

Returns:

A Tensor with the same type as value.

To answer your question in the title:

What is the shape of conv3d and conv3d_transpose?

It is an order 5 tensor, and the dimensions are: $\text{BatchSize} \times \text{Depth} \times \text{Height} \times \text{Width} \times \text{Channels}$

You could in theory use this for your GAN, but you would need to add (a probably useless) depth dimension to the shape.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.