Problems with input vs output for my 1D Vnet
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I have some issues with my input and output (i think) for my neural network. I have created a 1D version of the Volumentric network. The input is supposed to be 32-second (fs = 100) windows with 9 different time-series and features, i.e. matrices of the size [3200,9].
For my output (what i want to predict) is the difference between a scaled signal and the ground truth, a vector of size [3200,1].
The input layer I have chosen is a sequence input layer using the matlab deep learning toolbox as follows:
inputLayer = sequenceInputLayer([3200,9]);
For the output I have created a mse-function (loss function):
classdef mseRegressionLayer < nnet.layer.RegressionLayer ...
& nnet.layer.Acceleratable
% Example custom regression layer with mean-absolute-error loss.
methods
function layer = mseRegressionLayer(name)
% layer = maeRegressionLayer(name) creates a
% mean-absolute-error regression layer and specifies the layer
% name.
% Set layer name.
layer.Name = name;
% Set layer description.
layer.Description = 'Mean squared error';
end
function loss = forwardLoss(layer, Y, T)
% loss = forwardLoss(layer, Y, T) returns the MAE loss between
% the predictions Y and the training targets T.
% Calculate MAE.
R = size(Y,1); % 3200
meanSquaredError = sum((Y-T).^2,2)/R;
% Take mean over mini-batch.
N = size(Y,3); % batch
loss = sum(meanSquaredError)/N;
end
function dLdY = backwardLoss(layer, Y, T)
% dLdY = backwardLoss(layer, Y, T) returns the derivatives of
% the SSE loss with respect to the preditions Y.
R = size(Y,1); % 3200
N = size(Y,3); % batch
dLdY = ((2*(Y-T))./R)./N;
end
end
end
When I (try to) use the network I have defined the following trainingoptions:
options = trainingOptions("adam",...
MiniBatchSize=32, ...
Epsilon=1e-07,...
MaxEpochs=8, ...
InitialLearnRate=0.001, ...
SquaredGradientDecayFactor=0.004,...
L2Regularization=0.0005, ...
Plots="training-progress", ...
ExecutionEnvironment="cpu");
net = trainNetwork(inputtraine,outputtraine, Vnet(3200,9),options);
I get the following error when trying the network with data. The data I'm using looks like:
Input: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1017300/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1017300/image.png)
Output: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1017305/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1017305/image.png)
Warning: Error while calling message/getString:
In 'nnet_cnn:internal:cnn:util:TrainingDataErrorThrower:YIsNotValidSequenceResponseSize',
parameter {0} must be a real scalar.
Error in nnet.internal.cnn.util.TrainingDataErrorThrower>iCreateExceptionFromErrorID (line
292)
exception = MException(message(errorID, varargin{:}));
Error in
nnet.internal.cnn.util.TrainingDataErrorThrower/throwYIsNotValidSequenceResponseSize (line
209)
exception =
iCreateExceptionFromErrorID('nnet_cnn:internal:cnn:util:TrainingDataErrorThrower:YIsNotValidSequenceResponseSize',
OutputLayerSize);
Error in
nnet.internal.cnn.data.RegressionOutputDataValidator/assertValidRegressionSequenceResponse
(line 92)
errorStrategy.throwYIsNotValidSequenceResponseSize(outputSize)
Error in nnet.internal.cnn.data.RegressionOutputDataValidator/validateArrayOrCell (line
77)
this.assertValidRegressionSequenceResponse(Y,networkOutputSize,errorStrategy);
Error in nnet.internal.cnn.data.RegressionOutputDataValidator/validateCell (line 22)
this.validateArrayOrCell(Y,errorStrategy);
Error in nnet.internal.cnn.data.CellValidator/validateInputOutputDataAndNetwork (line 25)
outputLayerValidator{1}.validateCell(Y,this.ErrorStrategy);
Error in nnet.internal.cnn.trainNetwork.DLTDataPreprocessor/validateDataForProblem (line
100)
dataValidator.validateInputOutputDataAndNetwork(X, Y, inputLayerValidator,
outputLayerValidator);
Error in nnet.internal.cnn.trainNetwork.DLTDataPreprocessor/validateDataAndNetwork (line
90)
this.validateDataForProblem(X, Y, inputLayerValidator, outputLayerValidator,
dataValidator);
Error in nnet.internal.cnn.trainNetwork.DLTDataPreprocessor/validateTrainingDataAndNetwork
(line 20)
this.validateDataAndNetwork(X, Y, dataValidator,...
Error in nnet.internal.cnn.trainNetwork.doTrainNetwork (line 53)
[X,Y] = dataProcessor.validateTrainingDataAndNetwork(X,Y,...
Error in trainNetwork (line 182)
[trainedNet, info] =
nnet.internal.cnn.trainNetwork.doTrainNetwork(factory,varargin{:});
Error in LiveEditorEvaluationHelperE1893827601 (line 172)
net = trainNetwork(inputtraine,outputtraine, Vnet(3200,9),options);
Error using trainNetwork
Error in NetworkTest (line 172)
net = trainNetwork(inputtraine,outputtraine, Vnet(3200,9),options);
When i use the Network Analyze function in the deep learning toolbox there are no errors, so I don't understand why it is wrong.
I hope you can help me! Thanks in advance.
댓글 수: 0
답변 (1개)
Himanshu
2023년 9월 29일
Hello Mette,
I understand that you are facing an error when trying to train your 1D Volumetric Network. The error occurred because the output size of your network does not match the expected output size for sequence responses.
The sequence network in MATLAB expects the output to be of size [numResponses, numObservations], where "numResponses" is the number of output features and "numObservations" is the number of samples. In your case, since you are predicting a single feature, "numResponses" should be 1. However, your output is of size [3200, 1] per observation, which does not match the expected format.
You can fix the issue by reshaping the output data. Instead of having the output as [3200, 1] per observation, you can reshape it to [1, 3200]. This would make the output size to be [1, numObservations], which is the expected format.
output_train = cellfun(@(x) reshape(x, [1, numel(x)]), output_train, 'UniformOutput', false);
Ensure that the final layer of your network matches the format of your output data. If your final layer outputs a vector of size [1, 3200] per observation, your output data should also be in the same format.
You can refer to the below documentation to understand more about "cellfun" function and creating function handles in MATLAB.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!