Encountered an error while implementing deep learning regression model in MATLAB.

1 次查看(过去 30 天)
Following is the code and the error generated while implementing regression model in MATLAB. input vector(traindata(:,1)) is of size 300 and output vector(traindata(:,2)) size is also 300, still I am getting error of size not same. traindata is a cell of size 769x2 each element of length 1x300 double. what am I doing wrong?
load('traindata.mat')
load('testdata.mat')
layers1 = [
sequenceInputLayer(1,MinLength = 300)
convolution1dLayer(4,3,Padding="same",Stride=1)
convolution1dLayer(64,8,Padding="same",Stride=8)
batchNormalizationLayer()
tanhLayer
maxPooling1dLayer(2,Padding="same")
convolution1dLayer(32,8,Padding="same",Stride=4)
batchNormalizationLayer
tanhLayer
maxPooling1dLayer(2,Padding="same")
transposedConv1dLayer(32,8,Cropping="same",Stride=4)
tanhLayer
transposedConv1dLayer(64,8,Cropping="same",Stride=8)
tanhLayer
bilstmLayer(8)
fullyConnectedLayer(8)
dropoutLayer(0.2)
fullyConnectedLayer(4)
dropoutLayer(0.2)
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions("adam",...
MaxEpochs=600,...
MiniBatchSize=600,...
InitialLearnRate=0.001,...
ValidationData={valdata(:,1),valdata(:,2)},...
ValidationFrequency=100,...
VerboseFrequency=100,...
Verbose=1, ...
Shuffle="every-epoch",...
Plots="none", ...
DispatchInBackground=true);
[net1,info1] = trainNetwork(traindata(:,1),traindata(:,2),layers1,options);
Error using trainNetwork
Invalid network.

Caused by:
Network: Incompatible input and output sequence lengths. The network must return sequences with the same length as the input data or a sequence with length one.

采纳的回答

Sanjana
Sanjana 2023-3-30
Hi,
I understand that you are facing an issue with incompatible input and output sequence lengths,
The above error, is not related to the data as , the input and output data shapes are correct, But if you execute the “analyzeNetwork(layers1)”, from here we can understand the output from the “regressionLayer” has a sequence length of 32 and input layer has a sequence length of 1,this is because of the network architecture you defined. So,I suggest you to try to make changes to the architecture according to your task.
Please refer to the below link for further information,
Hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by