MATLAB Answers

train a neural network

22 views (last 30 days)
Nitai Fingerhut
Nitai Fingerhut on 16 May 2019
Edited: Anouar Yatribi on 2 Aug 2020 at 18:23
I tried to create a new neural network for function approxiamting. I used the neural network designer tool. I generated the code, however it didn't go well.
I tried to use a sequentila input layer -> fc layer, but MATLAB required a unfolding layer in between. later I noticed I need a folding layer after the unfolding layer, but that didn't work as well. the current netwrk has both the above layer, however it doesn't work.
would love to get some help.
the code:
[X1, X2] = meshgrid(-2:.2:2, -2:.2:2);
Y = X1 .* exp(-X1.^2 - X2.^2);
% figure();
% surf(X1, X2, Y)
Ntrain = 500;
X_train = (4 * rand(2, Ntrain) - 2).';
Y_train = X_train(:, 1) .* exp(-X_train(:, 1).^2 - X_train(:, 2).^2);
% tbl = table(X_train, Y_train);
% define network's layers
lgraph = layerGraph();
tempLayers = [
sequenceInputLayer([1 500 2],"Name","sequence")
lgraph = addLayers(lgraph,tempLayers);
lgraph = connectLayers(lgraph,"seqfold/miniBatchSize","sequnfold/miniBatchSize");
clear tempLayers;
% define network's options
options = trainingOptions('sgdm', ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.2, ...
'LearnRateDropPeriod',5, ...
'MaxEpochs',20, ...
'MiniBatchSize',50, ...
% analyzeNetwork(layers)
net = trainNetwork(X_train, Y_train, layers, options);
the error:
Error using trainNetwork (line 165)
Invalid network.
Error in main (line 53)
net = trainNetwork(X_train, Y_train, layers, options);
Caused by:
Layer 'fc_1': Invalid network. Layer does not support sequence input. Try using a sequence folding layer before the layer.

  1 Comment

Anouar Yatribi
Anouar Yatribi on 2 Aug 2020 at 18:21
Hi Nitai,
I have the same issue when trying to implement a custom layer after a sequence input layer. I haven't found any solution to this problem. Can you please tell us if you solved it ?
Thanks in advance.

Sign in to comment.

Answers (0)