user3851234
user3851234

Reputation: 46

How can high level features be concatenated with low level features in a CNN using keras?

I am trying to pass and concatenate the output of one layer to another layer in a CNN as shown in the following image. 30x30x512 layer is concatenated with 15x15x1024 after reshaping.

enter image description here

Please note that two different models and merging them is not the solution I am looking for. I am want to know how I can use the same model to merge the mentioned layers.

Thank you in advance for your suggestions.

Upvotes: 3

Views: 529

Answers (1)

Marcin Możejko
Marcin Możejko

Reputation: 40516

You need to store the output tensors of both layers you want to merge. Once you have these tensors there are at least two ways to merge them:

  1. Using Reshape layer where you can specify the output shape and the job is done.

  2. By using tf.space_to_depth function and packing it to a Lambda layer (as it's TensorFlow operation). This might be only used when you use TensorFlow backend.

Once you have your output reshaped you can use concatenate layer and merge outputs by channels dimension.

Upvotes: 3

Related Questions