2D Convolution on sequential input

조회 수: 4 (최근 30일)
Patrick Wais
Patrick Wais 2022년 2월 10일
댓글: Xie Shipley 2023년 10월 24일
Hi all!
I have the following problem:
I have a dataset of 1000 matrices which have the following form: 8x10 (8 Sensor Values at 10 Time Steps)
My response dataset is a categorical vector of 1000 values (0,1 or 2) classifying each of the 1000 time series.
Using a CNN I want to make a 2D convolution so I get 50 Feature maps in the form of 1 by 10 (1 represents convoluted sensors, and 10 a value for each time step. Afterwards I want to add a LSTM layer to get information about the time domain of the signal.
However I can only use a 1D CNN when I use the sequence input layer.
And I dont want to transform the matrix into an image to apply a 2D conv.
Here is my sample code:
Input is the time series of length 10 with 8 features
layers = [ ...
sequenceInputLayer(8,"MinLength",10)
convolution2dLayer([8,1],50,"Padding","same")
reluLayer
layerNormalizationLayer
lstmLayer(50,"OutputMode","last")
flattenLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer("Classes",classes,"ClassWeights",classweights)
];
And the error I get:
Error using trainNetwork (line 184)
Invalid network.
Caused by:
Layer 2: Input size mismatch. Size of input to this layer is different from the expected input size.
Inputs to this layer:
from layer 1 (size 8(C) × 1(B) × 10(T))
Is there a way to solve this problem? In Python it is no problem to use 2D Conv on sequential input data.
  댓글 수: 2
Yu
Yu 2023년 6월 7일
Hello, Patrick.
How did you solve this problem?
Sotudeh Hoseini Ghafari
Sotudeh Hoseini Ghafari 2023년 7월 26일
편집: Sotudeh Hoseini Ghafari 2023년 7월 26일
I have exactly the same problem. How did you deal with this issue @Patrick Wais?

댓글을 달려면 로그인하십시오.

답변 (2개)

yanqi liu
yanqi liu 2022년 2월 18일
편집: yanqi liu 2022년 2월 18일

Md Zahidul Islam
Md Zahidul Islam 2022년 2월 18일
I have faced similar problem recently.
For using 2D Conv you need input sequence in the form of (size (S) × (S) × (C)), But the size has given in the model is: sequenceInputLayer(8,"MinLength",10), which means size 8(C) × (B) × (T). Thus, you are getting an error.
Note that, sequenceInputLayer(8) means the input has (8 features * T time steps). Matlab read T time steps from the input data during training.
Therefore, If want to use 2D Conv with time series, one may try as below. Otherwise, try 1D Conv as @yanqi liu attached.
layers = [ ...
sequenceInputLayer([8 10 1],"MinLength",10)
sequenceFoldingLayer('Name','fold')
convolution2dLayer([3,3],50,"Padding","same")
reluLayer
layerNormalizationLayer
sequenceUnfoldingLayer('Name','unfold')
flattenLayer
lstmLayer(50,"OutputMode","last")
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer("Classes",classes,"ClassWeights",classweights)
];
layers = layerGraph(layers);
layers= connectLayers(layers,'fold/miniBatchSize','unfold/miniBatchSize');
  댓글 수: 1
Xie Shipley
Xie Shipley 2023년 10월 24일
@Md Zahidul Islam have you tried sequenceInputLayer([8 10 1],"MinLength",10) on GPU ?
I got CUDNN_STATUS_EXECUTION_FAILED while running on GPU, you can click Here to see more detail

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by