How to train neural network to generate one output using specific input data?
18 次查看(过去 30 天)
显示 更早的评论
Hello esteemed friends, I need help. How to train the neural network using input data (8x4000) and target data (1x4000), and then use the trained neural network using 2 to 3 input data to generate one output? For example using the abalone_dataset.mat, train the neural network using input data (8x4177) which contain length,height, weight, etc, and target data (1x4177) which is the ring size. Then using the trained neural network using 2 to 3 input data which maybe only contain length and height only to generate one output. I'm still new to the neural network and currently using the LSTM for this problem.
load abalone_dataset.mat
[xtrn,ttrn] = abalone_dataset;
numFeatures = 8;
numHiddenUnits = 125;
numResponses = 1;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numResponses)
regressionLayer];
maxEpochs = 70;
miniBatchSize = 27;
options = trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(xtrn,ttrn,layers,options);
I also have problem during the "net = trainNetwork(xtrn,ttrn,layers,options);" command. I really appreciate it if anyone can solve this problem too.
0 个评论
采纳的回答
Himanshu
2023-3-2
Hello Ahmad,
As per my understanding, you are facing an error while running the “net = trainNetwork(xtrn,ttrn,layers,options);” command. The error doesn’t seem to occur due to this command but because of discrepancy in architecture of the network.
The error message specifies that there is a mismatch between the size of network output and size of target values. The network is trying to predict a single value for each sample but the target data has more than one column. You can fix the error by making the following changes to your network architecture:
layers = [
sequenceInputLayer(numFeatures),
lstmLayer(numHiddenUnits,'OutputMode','sequence'),
fullyConnectedLayer(numResponses),
flattenLayer,
fullyConnectedLayer(numResponses),
regressionLayer]
Here, replace the fully connected layer with a sequence-to-sequence LSTM layer. The output will be a sequence of vectors instead of a single value. Then, add a flatten layer and a fully connected layer to map the sequence to a single scalar output value.
After the above changes, the error can be eliminated and output will be as per the below image.
You can refer to the below documentation to understand more about the "LSTM" layer and "flatten" layer.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!