Invalid training data. Sequence responses must have the same sequence length as the corresponding predictors.

Hi , I have a simple regression NN for time sequences .
Got an error when training the network : "Invalid training data. Sequence responses must have the same sequence length as the corresponding predictors. " . While my XTrain data is a cell array dim(Nx1) of sequences dim(1x10) and YTrain data is cell array dim(Nx1) of sequences sim(1x1) ...Please advise why the response sequences need to be the same length as the predictors ?
Architecture of the network :

 Réponse acceptée

yes,sir,may be set sequenceInputLayer to
sequenceInputLayer(10, ……)
to match the input data,1*10 dimension

6 commentaires

Hi , while changing what you adviced i am getting the error below
yes,sir,may be upload the data mat file,we can debug
Hi , i attached the neaural network creation and training flow , as well the data set ...You need only to change the path of the "load()" function in the script to the data set path in your computer .
Thanks a lot for help
close all; clc;
%% load data
data=load('tx2rx_connection_rx_pow_minus10dBm__21_12_2021.mat');
x_org=data.in_tx;
y_org=data.tx2rx;
%% normalize data
x=((real(x_org)-mean(real(x_org)))/std(real(x_org))) +1j*(imag(x_org)-mean(imag(x_org)))/std(imag(x_org));
y=((real(y_org)-mean(real(y_org)))/std(real(y_org))) +1j*(imag(y_org)-mean(imag(y_org)))/std(imag(y_org));
%% figure #1 - Input/Output Time Domain
figure
ax1=subplot(2,1,1);plot(real(x));hold on;plot(real(y));hold off;
title('Time Domain - Real Parts');ylabel('[V]');xlabel('[sec]');legend('x','y');
ax2=subplot(2,1,2);plot(imag(x));hold on;plot(imag(y));hold off;
title('Imaginary Parts');xlabel('[sec]');ylabel('[V]');legend('x','y');
linkaxes([ax1,ax2],'xy');
%% figure #2 -Input/Output Frequency Domain
figure
%FFT PSD
% nfft=1024;
% psd_x_real=fftshift(fft(real(x),nfft)).*conj(fftshift(fft(real(x),nfft)))/(length(x)*fs);
% psd_x_imag=fftshift(fft(imag(x),nfft)).*conj(fftshift(fft(imag(x),nfft)))/(length(x)*fs);
% psd_y_real=fftshift(fft(real(y),nfft)).*conj(fftshift(fft(real(y),nfft)))/(length(x)*fs);
% psd_y_imag=fftshift(fft(imag(y),nfft)).*conj(fftshift(fft(imag(y),nfft)))/(length(x)*fs);
%Welch PSD
segment_size=1024;
nfft=2048;
noverlap=segment_size-2;
fs=128e6;
[pwelch_x,f_x]=pwelch(real(x),segment_size,[],nfft,fs,'centered','power');
[pwelch_y,f_y]=pwelch(real(y),segment_size,[],nfft,fs,'centered','power');
ax3=subplot(2,1,1);plot(f_x,10*log10(pwelch_x/1e-3));hold on;plot(f_y,10*log10(pwelch_y/1e-3));hold off;
title('Power Spectrum');xlabel('[Hz]');ylabel('[dBm]');legend('x','y')
ax4=subplot(2,1,2);plot(f_x,10*log10(pwelch_x/1e-3));hold on;plot(f_y,10*log10(pwelch_y/1e-3));hold off
xlabel('[Hz]');ylabel('[dBm]');ylim([-5,15]);legend('x','y')
grid on;
%% NN data preparation %%
train_ratio=0.9;
channel_length=5;
feature_dim=1;
%Divide into train/test arrays
x_train_len=floor(train_ratio*length(x));
y_train_len=floor(train_ratio*length(y));
x_train=[zeros(1,channel_length-1),(x(1:x_train_len))'];
x_test=[zeros(1,channel_length-1),(x(x_train_len+1:end))'];
y_train=y(1:y_train_len);
y_test=y(y_train_len+1:end);
% NN training/validation inputs definition
XTrain=cell(length(y_train),1);
XTest=cell(length(y_test),1);
YTrain=cell(length(y_train),1);
YTest=cell(length(y_test),1);
x_train_sample=zeros(1,2*channel_length);
y_train_sample=zeros(1,1);
XTrain = [];
YTrain = [];
for i=1:length(y_train)
x_train_sample(1,1:channel_length)=real(x_train(i:i+channel_length-1));
x_train_sample(1,channel_length+1:end)=imag(x_train(i:i+channel_length-1));
y_train_sample(1,1)=real(y_train(i));
XTrain(:,:,1,i)= x_train_sample(:);
YTrain(i,1)= y_train_sample;
end
x_test_sample=zeros(1,2*channel_length);
y_test_sample=zeros(1,1);
XTest = [];
YTest = [];
for i=1:length(y_test)
x_test_sample(1,1:channel_length)=real(x_test(i:i+channel_length-1));
x_test_sample(1,channel_length+1:end)=imag(x_test(i:i+channel_length-1));
y_test_sample(1,1)=real(y_test(i));
XTest(:,:,1,i)= x_test_sample(:);
YTest(i,1)= y_test_sample;
end
%% NN Architecture %%
hidden_neuron=8;
layers = [ ...
imageInputLayer([10 1 1],'Name','Sequence Input Layer')
convolution2dLayer(3,hidden_neuron,'Padding','same','Name','CNN 2d Layer')
reluLayer('Name','ReluLayer Hidden Layer')
fullyConnectedLayer(1,'Name','CNN 2d Output Layer')
reluLayer('Name','ReluLayer Output Layer')
regressionLayer('Name','Regression NN')];
lgraph = layerGraph(layers);
analyzeNetwork(lgraph)
epochs=50;
learnign_r=0.0005;
batch_size=128;
drop_out_r=0;
options = trainingOptions('adam', ...
'MaxEpochs',epochs, ...
'ValidationData',{XTest,YTest}, ...
'InitialLearnRate',0.0005, ...
'MiniBatchSize',32, ...
'Plots','training-progress',...
'LearnRateDropFactor',drop_out_r);
%% NN Training %%
[net,info] = trainNetwork(XTrain,YTrain,layers,options);
Hi @yanqi liu sorry for late reply ....Thanks a lot , it worked for me , appriciate your help

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by