# How can I use the bottleneck layer of the U-net to calculate the similarity between two images?

I would like to use the bottleneck layer of U-Net (the last layer of the encoder) to calculate the similarity between two images. For that, I have to somehow flatten the last layer of the encoder. In my opinion, there are two approaches:

1. Take the last layer which in my case is $$4 \times 4 \times 16$$ and flatten it to 1D

2. Add a dense before the decoder and then reshape the dense 1D layer into 3D

For the second case, I am not sure how this would affect the network. Arbitrarily reshaping a 1D array into a 3D tensor. Could that introduce weird artifacts? Does someone have experience in a similar problem?

• If I understood you correctly it's the same (architecturally). Decoder will reshape dense layer into 3d tensor anyway in U-net Jun 19 '19 at 4:48
• I don't think that's true. In the paper the bottleneck layer is of dimension 30 x 30 x 1024. Jun 19 '19 at 22:33
• Anyway shouldn't be a problem. Dense layer is just 1x1xN convolution layer and however you down/upsample it shouldn't change behavior too much. Jun 20 '19 at 4:50
• I think it only doesn't change things if - when shaped into 3D again - the same pixels end up in the same spot. Otherwise the spatial information gets lost. Jun 20 '19 at 20:18