Is possible to create an ANN network using SeriesNetwork?
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I created and trained a simple ANN neural network using "fitnet" and "train" functions.
I need to export this network in .onnx format but "exportONNXNetwork" command does not support Function fitting neural network. So I tried to replicate the topology and the performances using SeriesNetwork, however results are very different.
Can someone help me to find the mistakes in my code or explain to me if this task is feasible or not?
Thanks
% Constant Parameters
A = 9.34e10;
alpha = -4.416;
beta = 1290;
Ton = 2.5e-3;
% Random Input
Tj = randi([125 155],1,500);
DTj = randi([10 60],1,500);
% MODEL
Nf = A * DTj.^alpha.*exp(beta./Tj).*(Ton/1.5)^(-0.3);
%Nf =(5+ Tj.*DTj)/20.*Tj+56./DTj;
% DATASET
% Normalization of data
Tj_n = (Tj - min(Tj))./range(Tj);
DTj_n = (DTj - min(DTj))./range(DTj);
Nf_n = (Nf - min(Nf))./range(Nf);
% creation of dataset
Data = [Tj_n; DTj_n; Nf_n];
Input = Data([1,2],:);
Output = Data(3,:);
% 1st network
% ANN network definition
Neurons_HiddenLayer = 30;
net = fitnet(Neurons_HiddenLayer,'trainbr');
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% ANN train
[net tr] = train(net,Input,Output);
% 2nd network
layers = [
featureInputLayer(2)
fullyConnectedLayer(30)
reluLayer
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions('sgdm', ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.01, ...
'LearnRateDropPeriod',10, ...
'MaxEpochs',2, ...
'MiniBatchSize',5, ...
'Plots','training-progress');
[tempNet info] = trainNetwork(Input(:,tr.trainInd)',Output(tr.trainInd)',layers,options);
0 个评论
回答(1 个)
Hornett
2024-9-4
To replicate the performance of your `fitnet` model using a `SeriesNetwork` and export it to ONNX, consider these key points:
1. Activation Function: Use `tanhLayer` in the `SeriesNetwork` to match the `tansig` activation in `fitnet`.
2. Training Algorithm: Use a similar optimizer for both networks. Consider switching to `adam` for better convergence in the `SeriesNetwork`.
3. Training Duration: Increase the `MaxEpochs` in the `SeriesNetwork` training options to allow sufficient learning time.
4. Normalization: Ensure consistent input normalization for both networks.
5. Export to ONNX: Once trained, export the `SeriesNetwork` using `exportONNXNetwork(tempNet, 'myNetwork.onnx');`.
By aligning these aspects, you should achieve more comparable results between the two models.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!