1D-CNN not sequence input

11 views (last 30 days)
ababa
ababa on 5 Apr 2024
Edited: Fabien SANCHEZ on 30 May 2024
I am trying to learn a 1D-CNN model. I only have sequence input examples, but I want to learn CNN with no sequence input. My data is a one-dimensional vector. When I input a one-dimensional vector as 100x1 as a cell, I failed to train the network because matlab outputs errors. However, I have succeeded in training when I input a one-dimensional vector as 1x100 as a cell. To input it as 1x100, I need to set numFeature as 1. I want to set numFeature to 100. How can I do this with a vector not a sequence of 2d matrix?
related exampled is below:
  1 Comment
ababa
ababa on 5 Apr 2024
The sequence length of the input data (1) must be greater than or equal to the MinLength property of the sequence input layer (100).

Sign in to comment.

Accepted Answer

Ben
Ben on 8 Apr 2024
The convolution1dLayer only supports convolutions over "sequence dimension" or a single "spatial dimension".
If you want to perform 1D convolution over your feature dimension, you can try the following.
Interpret your feature dimension as a spatial or sequence dimension. For example instead of interpreting N observations of 100 features as a 100xN "CB" array, you can interpret it as a 100x1xN "SCB" array. To use this data in dlnetwork you can use the R2023b feature inputLayer. For example
numFeatures = 100;
batchSize = 4;
% create fake data as "CB"
x = dlarray(rand(numFeatures,batchSize),"CB");
% re-label data as "SBC" so 1d conv can be used on the C dimension
x = dlarray(x,"SBC");
% create 1d conv network
filterSize = 3;
numFilters = 8;
layers = [
inputLayer([numFeatures,1,NaN], "SCB")
convolution1dLayer(filterSize,numFilters)];
net = dlnetwork(layers);
% test network
y = predict(net,x);
% If later the "SCB" outputs have a scalar "C" dimension and you want to relabel to "CB" you can use something like:
relabelLayer = functionLayer(@(x) dlarray(squeeze(x),"CB"));
  1 Comment
Fabien SANCHEZ
Fabien SANCHEZ on 30 May 2024
Edited: Fabien SANCHEZ on 30 May 2024
Hi there!
This works with the Matlab interface. If the agent is trained by reinforcement in a Simulink environment via a Simulink.bus that brings observations spaces, how do we force the input to be in "TCB" format? Do you see the lack of support for cell objects or dlarray in Simulink signals?
Every time I try, the output format of the layer is a A(C)x1(B)x1(T), where A is the number of timesteps in the sequence. And I can not use this format to train, due to a crash after the episode reached the 100 batches for obscure reshaping reasons. I would like to have a 1Cx1BxAT but I could not find a good way to force it.
I can provide simulink model/code if needed. It takes place in a context of multi-input model (features and sequences).

Sign in to comment.

More Answers (0)

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!