custom neural network error( About dlfeval )
Afficher commentaires plus anciens
I am running a custom neural network using a low level api ( dlnetwork, dlfeval, adamupdate, dlgradient).
However, while running dlfeval, I get an error.
error is here.
Error using dlfeval (line 43)
First input argument must be a formatted dlarray.
Error in deep (line 639)
[gradient,loss]=dlfeval(@modelGradients,dlnet,dlX);
I think it's an error about dlarray, but if you look at my code, I declare dlarray in the input.
my code is here. (Input feature:8 // Target:1)
clear,clc,close all
data=readmatrix('train.csv');
inputs=data(:,1:8);
targets=data(:,9);
input2=transpose(inputs);
target2=transpose(targets);
inputs2=normalize(input2,2,'range');
layers= [sequenceInputLayer([8],'Name','input')
fullyConnectedLayer(64,'Name','fc1')
tanhLayer('Name','tanh1')
fullyConnectedLayer(32,'Name','fc2')
tanhLayer('Name','tanh2')
fullyConnectedLayer(16,'Name','fc3')
tanhLayer('Name','tanh3')
fullyConnectedLayer(8,'Name','fc4')
tanhLayer('Name','tanh4')
fullyConnectedLayer(1,'Name','fc5')
];
lgraph=layerGraph(layers);
dlnet=dlnetwork(lgraph);
for it=1:5000
dlX=dlarray(inputs2);
[gradient,loss]=dlfeval(@modelGradients,dlnet,dlX);
dlnet=adamupdate(dlnet,gradient);
end
function [gradient,loss]=modelGradients(dlnet,dlx,t)
out=forward(dlnet,dlx);
loss=immse(out,t);
loss=dlarray(loss);
gradient=dlgradient(loss,dlnet.Learnables);
end
Thanks for reading my question!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!