How to create personalized layers

1 回表示 (過去 30 日間)
Fabrizio Bernardi
Fabrizio Bernardi 2020 年 8 月 27 日
編集済み: Fabrizio Bernardi 2020 年 8 月 31 日
Hello everyone
I built a customed regression output layer named mylayer from here https://it.mathworks.com/help/deeplearning/ug/define-custom-regression-output-layer.html and I want to add it to the other layers of the network. I should use trainNetwork but I only found this example of definiton of layers:
layers = [
imageInputLayer([28 28 1])
convolution2dLayer(5,20)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(1)
myLayer('myL')]
My problem however is NOT an image classification, I just want a couple of hidden layers with a number of neurons to be chosen and the usual weight and biases, passing as inputs a some scalar values. How should I define my object layers?
Thanks you in advice for your help!

回答 (1 件)

Anshika Chaurasia
Anshika Chaurasia 2020 年 8 月 31 日
Hi Fabrizio,
It is my understanding that you have successfully created the custom Regression Ouput Layer – ‘myLayer’. You want to have some hidden layers and ‘myLayer’ in layers array. You could consider following codes:
layers = [
imageInputLayer([28 28 1])
fullyConnectedLayer(20)
reluLayer % optional
fullyConnectedLayer(1)
myLayer('myL')]
Refer to fullyConnectedLayer documentation for weight and bias properties of fullyConnectedLayer.
  2 件のコメント
Fabrizio Bernardi
Fabrizio Bernardi 2020 年 8 月 31 日
Thank you for the answer! Is imageInputlayer ok if I don't have to deal with images? Searching I found sequenceInputLayer that could be useful, but trying with a dataset in matlab it gives me this error:
Error using trainNetwork (line 170)
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that
dimension.
Error in test_prova (line 17)
net = trainNetwork(bodyfatInputs,bodyfatTargets,layers,options);
Caused by:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that
dimension.
This is the code I used ( my customed layer is the layer using mae loss function such as in the example here https://it.mathworks.com/help/deeplearning/ug/define-custom-regression-output-layer.html):
layer = maeRegressionLayer('mae');
load bodyfat_dataset
layers = [
sequenceInputLayer(13)
lstmLayer(40)
maeRegressionLayer('mae')];
options = trainingOptions('sgdm');
net = trainNetwork(bodyfatInputs,bodyfatTargets,layers,options);
Thank you for the help!
Fabrizio Bernardi
Fabrizio Bernardi 2020 年 8 月 31 日
編集済み: Fabrizio Bernardi 2020 年 8 月 31 日
Edit: now I tried with
layers = [
sequenceInputLayer(13)
%lstmLayer(40)
fullyConnectedLayer(20)
reluLayer % optional
fullyConnectedLayer(1)
maeRegressionLayer('mae')];
and it gives result! Even if with
YPred = predict(net,bodyfatInputs);
predictionError = YPred - bodyfatTargets;
The erros are very large and the output are almost all the same though...

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

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by