Devin Haslam
Devin Haslam

Reputation: 759

Properly concatenate feature maps in Tensorflow

I am attempting to reproduce a Convolution Neural Network from a research paper using Tensorflow. Image of architecture

There are many times in the diagram where the results of convolutions are concatenated. Currently I am using tf.concat(https://www.tensorflow.org/api_docs/python/tf/concat) along the last axis (representing channels) to concatenate these feature maps. I originally believed that I would want to concatenate along all axes, but this does not seem to be an option in tensorflow. Now I am facing the problem where the paper indicates that tensors(feature maps) of different sizes should be concatenated. tf.concat does not support concatenations of different sizes, so I am wondering if this was the correct command to use in the first place. In summary, what is the correct way to concatenate feature maps(sometimes of different sizes) in tensorflow?

Thank you.

Upvotes: 1

Views: 2842

Answers (3)

Deniz Beker
Deniz Beker

Reputation: 2194

The problem that you encounter for inception network may be resolved by using padding in convolutional layers to keep the size same. For inception blocks, instead of using "VALID" padding, change it to "SAME" one. So, without requiring any resizing, you can concatenate the outputs.

Alternatively, you can append padding to the feature maps that are going to be concatenated. You can do that by using tf.pad().

If you don't prefer to do this one, you can use tf.image.resize_images function to resize them to same values. However, this is a dirty and computationally expensive approach.

Upvotes: 1

nessuno
nessuno

Reputation: 27050

It's impossible and meaningless to concatenate features maps with different sizes.

If you want to concatenate 2 tensors, every dimension except the concatenation one must be equal.

From the image you posted, in fact, you can see that every feature map that gets concatenated, has the same spatial extent (but different depth) of the other one. If you can't concatenate in that way, probabily that's something wrong in your code, and probably the problem is the lack of padding = valid in the convolution operation.

Upvotes: 2

Devin Haslam
Devin Haslam

Reputation: 759

Tensors can only be concatenated along one axis. If you need to concatenate feature maps of different sizes, you must somehow manipulate the sizes of the original tensors.

Upvotes: 0

Related Questions