Training a TCN model to predict a Continuous Variable
Hello there, I am trying to build a TCN model to predict a continuous variable. Similar the the example here: https://www.mathworks.com/help/deeplearning/ug/sequence-to-sequence-classification-using-1-d-convolutions.html#SeqToSeqClassificationUsing1DConvAndModelFunctionExample-11. I have time series data in which I am using 3 input features (accelrometer measuments in x,y,z directions), but instead of classifying an acitivity, I am trying to estimate/predict a continuous variable. My predictors/input features are stored in a 10×1 cell array name "IMUdata" (each cell is one of the 10 trials) with each cell containing a 540×3 double with the acclerometer data from that trial. The target continous varable I am trying to predict is simialrly stored in a 10×1 cell array with each cell contaning a 540×1 double named "Predvar". The code I have been trying so far is:
numfeatures = 3;
numFilters = 64;
filterSize = 5;
droupoutFactor = 0.005;
numBlocks = 4;
net = dlnetwork;
layer = sequenceInputLayer(numFeatures,Normalization="rescale-symmetric",Name="input");
net = addLayers(net,layer);
outputName = layer.Name;
for i = 1:numBlocks
dilationFactor = 2^(i-1);
layers = [
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal",Name="conv1_"+i)
layerNormalizationLayer
spatialDropoutLayer(Name= "spat_drop_"+i,Probability=droupoutFactor)
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal")
layerNormalizationLayer
reluLayer
spatialDropoutLayer(Name="spat_drop2_"+i,Probability=droupoutFactor)
additionLayer(2,Name="add_"+i)];
% Add and connect layers.
net = addLayers(net,layers);
net = connectLayers(net,outputName,"conv1_"+i);
% Skip connection.
if i == 1
% Include convolution in first skip connection.
layer = convolution1dLayer(1,numFilters,Name="convSkip");
net = addLayers(net,layer);
net = connectLayers(net,outputName,"convSkip");
net = connectLayers(net,"convSkip","add_" + i + "/in2");
else
net = connectLayers(net,outputName,"add_" + i + "/in2");
end
% Update layer output name.
outputName = "add_" + i;
end
layers = [
fullyConnectedLayer(1)];
net = addLayers(net,layers);
net = connectLayers(net,outputName,"fc");
options = trainingOptions("adam", …
MaxEpochs=60, …
miniBatchSize=1, …
InputDataFormats="CTB", …
Plots="training-progress", …
Metrics="rmse", …
Verbose=0);
net = trainnet(IMUdata,Predvar,net,"mse",options)
However I am getiting an ERROR with the trainnet function saying that: Error setting data statistics of layer "input".nnet.cnn.layer.SequenceInputLayer>iAssertValidStatistics (line 341)Expected input to be of size 3×1, but it is of size 541×1.
Is this because of the way my input data is stored? Im not sure how to fix this error and if this is the correct way to build a TCN model to predict a continuous variable? Any help is greatly appreciated!Hello there, I am trying to build a TCN model to predict a continuous variable. Similar the the example here: https://www.mathworks.com/help/deeplearning/ug/sequence-to-sequence-classification-using-1-d-convolutions.html#SeqToSeqClassificationUsing1DConvAndModelFunctionExample-11. I have time series data in which I am using 3 input features (accelrometer measuments in x,y,z directions), but instead of classifying an acitivity, I am trying to estimate/predict a continuous variable. My predictors/input features are stored in a 10×1 cell array name "IMUdata" (each cell is one of the 10 trials) with each cell containing a 540×3 double with the acclerometer data from that trial. The target continous varable I am trying to predict is simialrly stored in a 10×1 cell array with each cell contaning a 540×1 double named "Predvar". The code I have been trying so far is:
numfeatures = 3;
numFilters = 64;
filterSize = 5;
droupoutFactor = 0.005;
numBlocks = 4;
net = dlnetwork;
layer = sequenceInputLayer(numFeatures,Normalization="rescale-symmetric",Name="input");
net = addLayers(net,layer);
outputName = layer.Name;
for i = 1:numBlocks
dilationFactor = 2^(i-1);
layers = [
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal",Name="conv1_"+i)
layerNormalizationLayer
spatialDropoutLayer(Name= "spat_drop_"+i,Probability=droupoutFactor)
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal")
layerNormalizationLayer
reluLayer
spatialDropoutLayer(Name="spat_drop2_"+i,Probability=droupoutFactor)
additionLayer(2,Name="add_"+i)];
% Add and connect layers.
net = addLayers(net,layers);
net = connectLayers(net,outputName,"conv1_"+i);
% Skip connection.
if i == 1
% Include convolution in first skip connection.
layer = convolution1dLayer(1,numFilters,Name="convSkip");
net = addLayers(net,layer);
net = connectLayers(net,outputName,"convSkip");
net = connectLayers(net,"convSkip","add_" + i + "/in2");
else
net = connectLayers(net,outputName,"add_" + i + "/in2");
end
% Update layer output name.
outputName = "add_" + i;
end
layers = [
fullyConnectedLayer(1)];
net = addLayers(net,layers);
net = connectLayers(net,outputName,"fc");
options = trainingOptions("adam", …
MaxEpochs=60, …
miniBatchSize=1, …
InputDataFormats="CTB", …
Plots="training-progress", …
Metrics="rmse", …
Verbose=0);
net = trainnet(IMUdata,Predvar,net,"mse",options)
However I am getiting an ERROR with the trainnet function saying that: Error setting data statistics of layer "input".nnet.cnn.layer.SequenceInputLayer>iAssertValidStatistics (line 341)Expected input to be of size 3×1, but it is of size 541×1.
Is this because of the way my input data is stored? Im not sure how to fix this error and if this is the correct way to build a TCN model to predict a continuous variable? Any help is greatly appreciated! Hello there, I am trying to build a TCN model to predict a continuous variable. Similar the the example here: https://www.mathworks.com/help/deeplearning/ug/sequence-to-sequence-classification-using-1-d-convolutions.html#SeqToSeqClassificationUsing1DConvAndModelFunctionExample-11. I have time series data in which I am using 3 input features (accelrometer measuments in x,y,z directions), but instead of classifying an acitivity, I am trying to estimate/predict a continuous variable. My predictors/input features are stored in a 10×1 cell array name "IMUdata" (each cell is one of the 10 trials) with each cell containing a 540×3 double with the acclerometer data from that trial. The target continous varable I am trying to predict is simialrly stored in a 10×1 cell array with each cell contaning a 540×1 double named "Predvar". The code I have been trying so far is:
numfeatures = 3;
numFilters = 64;
filterSize = 5;
droupoutFactor = 0.005;
numBlocks = 4;
net = dlnetwork;
layer = sequenceInputLayer(numFeatures,Normalization="rescale-symmetric",Name="input");
net = addLayers(net,layer);
outputName = layer.Name;
for i = 1:numBlocks
dilationFactor = 2^(i-1);
layers = [
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal",Name="conv1_"+i)
layerNormalizationLayer
spatialDropoutLayer(Name= "spat_drop_"+i,Probability=droupoutFactor)
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal")
layerNormalizationLayer
reluLayer
spatialDropoutLayer(Name="spat_drop2_"+i,Probability=droupoutFactor)
additionLayer(2,Name="add_"+i)];
% Add and connect layers.
net = addLayers(net,layers);
net = connectLayers(net,outputName,"conv1_"+i);
% Skip connection.
if i == 1
% Include convolution in first skip connection.
layer = convolution1dLayer(1,numFilters,Name="convSkip");
net = addLayers(net,layer);
net = connectLayers(net,outputName,"convSkip");
net = connectLayers(net,"convSkip","add_" + i + "/in2");
else
net = connectLayers(net,outputName,"add_" + i + "/in2");
end
% Update layer output name.
outputName = "add_" + i;
end
layers = [
fullyConnectedLayer(1)];
net = addLayers(net,layers);
net = connectLayers(net,outputName,"fc");
options = trainingOptions("adam", …
MaxEpochs=60, …
miniBatchSize=1, …
InputDataFormats="CTB", …
Plots="training-progress", …
Metrics="rmse", …
Verbose=0);
net = trainnet(IMUdata,Predvar,net,"mse",options)
However I am getiting an ERROR with the trainnet function saying that: Error setting data statistics of layer "input".nnet.cnn.layer.SequenceInputLayer>iAssertValidStatistics (line 341)Expected input to be of size 3×1, but it is of size 541×1.
Is this because of the way my input data is stored? Im not sure how to fix this error and if this is the correct way to build a TCN model to predict a continuous variable? Any help is greatly appreciated! tcn model, trainnet function, machine learning, neural networks MATLAB Answers — New Questions