0

What I need to do is I have a final layer in my model as (None,512,512,64) , I want to add all these 64 images element wise and give output from my model. So How can I add all the images present in a single layer leading to 1 output.

enter image description here

Harsh Vardhan
  • 31
  • 1
  • 4

1 Answers1

2

Say your current network has the following layer:

layer = Conv2D(64, kernel_size=(9, 9), input_shape=(512, 512, 1), padding='same',name = 'conv1')(input)

Now your feature has dimension [None, 512, 512, 64]. You can follow it up with

layer = Conv2D(1, kernel_size=(9, 9), input_shape=(512, 512, 1), padding='same',name = 'conv2')(input)

I assume you are using Conv2D, so your output will be a grayscale image of shape [None, 512, 512, 1]. If this is not what you want and you simply want to add the tensors, you can use tf.math.reduce_sum across axis = 3, just feed it the tensor output of first layer.

momo
  • 1,052
  • 5
  • 16
  • 34