FanDev
September 15, 2021, 7:57pm
1
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?
FanDev
September 16, 2021, 6:46pm
3
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:
How to perform “Add” in DL4J? Do I need to consider this as an additional layer?
(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:
/*
* ******************************************************************************
* *
* *
* * This program and the accompanying materials are made available under the
* * terms of the Apache License, Version 2.0 which is available at
* * https://www.apache.org/licenses/LICENSE-2.0.
* *
* * See the NOTICE file distributed with this work for additional
* * information regarding copyright ownership.
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* * License for the specific language governing permissions and limitations
* * under the License.
* *
* * SPDX-License-Identifier: Apache-2.0
* *****************************************************************************
*/
This file has been truncated. show original
You would take the output names of those 3 layers as inputs.
1 Like