How to create Multiplication Layer in deep learning toolbox

3 ビュー (過去 30 日間)
Jeong-Won Jeong
Jeong-Won Jeong 2018 年 12 月 19 日
コメント済み: Abdelwahab Afifi 2020 年 7 月 22 日
Dear community,
I am trying to create multiplication layer which multiplies inputs from multiple neural network layers element-wise, something like "additionLayer to add inputs from multiple layers element-wise". Is there any way I can create this layer in Matlab 2018a?
Best Regards,

回答 (1 件)

CARLOS VIDAL
CARLOS VIDAL 2019 年 10 月 3 日
編集済み: CARLOS VIDAL 2019 年 10 月 4 日
Hi,
I don't think matlab already has available the layer you are looking for, but you can create one.
Follow the link below.
I did it quickly, it seems to work, but better if you double check and follow the instruction in the link above to know how to integrate it with your NN structure.
Hope this will help you.
classdef ElementWiseMultiplication < nnet.layer.Layer
% Example custom ElementWiseMultiplication layer.
properties (Learnable)
% Layer learnable parameters
% Scaling coefficients
end
methods
function layer = ElementWiseMultiplication(numInputs,name)
% layer = ElementWiseMultiplication(numInputs,name) creates a
% element wise multiplication and specifies the number of inputs
% and the layer name.
% Set number of inputs.
layer.NumInputs = numInputs;
% Set layer name.
layer.Name = name;
% Set layer description.
layer.Description = "Element Wise Multiplication of " + numInputs + ...
" inputs";
end
function Z = predict(~, X1,X2)
% Z = predict(layer, X1, ..., Xn) forwards the input data X1,
% ..., Xn through the layer and outputs the result Z.
% Element Wise Multiplication
Z = X1 .*X2;
end
end
end
  2 件のコメント
ruo li
ruo li 2020 年 4 月 28 日
Do I need to define a backward function?Thanks.
Abdelwahab Afifi
Abdelwahab Afifi 2020 年 7 月 22 日
Have you get such layer? If yes, please share the code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by