How to "Add" multiple layers in a CNN architecture?

Hi, I have a question to implement “Add” in DL4J:

In Python, in my CNN model, I use “Add” to add several convolution layers together (same output form), such as:

layer_all_added = add([layer1, layer2, layer3])

then layer_all_added will be used as input for the next convolutional layer.

How can I implement it in DL4J?

Thanks.

@FanDev could you flesh this out a bit? Which API are you using? The ComputationGraph or Samediff? What is the add supposed to do? is that supposed to be an automatic concatneation? An element wise add?

Sure, let me explain it further.

In my neural network, I applied multiple dilation convolutions with different dilation rates, such as:

layer0 = Conv3D(neuron_size, (3,3,3), activation= 'relu', padding = 'same')(inputs)  //regular conv layer

layer1 = Conv3D(neuron_size, (3,3,3), activation='relu', padding='same', dilation_rate=1)(layer0) //dilation conv layer with dilation rate = 1
layer2 = Conv3D(neuron_size, (3,3,3), activation='relu', padding='same', dilation_rate=2)(layer1) //dilation conv layer
layer3 = Conv3D(neuron_size, (3,3,3), activation='relu', padding='same', dilation_rate=4)(layer2) //dilation conv layer
Add_All_Dilation = add([layer1, layer2, layer3])

merge1 = concatenate([UpSampling3D(size=(2,2,2))(Add_All_Dilation),layer0], axis = 4)
...

Since layer1, layer2, layer3 have the same output format, I am able to add their weights together to create a more strong feature map.

SO my questions are:

  1. How to perform “Add” in DL4J? Do I need to consider this as an additional layer?
  2. (extra question) How can I assign the concatenate (in DL4J called “MergeVetax”?) with axis=4 in DL4J?

Thanks.

@FanDev thanks a lot… You’ll want to use the element wise vertex with Op.add:

You would take the output names of those 3 layers as inputs.

1 Like