1D-CNN not sequence input

19 次查看(过去 30 天)
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 个评论
ababa
ababa 2024-4-5
The sequence length of the input data (1) must be greater than or equal to the MinLength property of the sequence input layer (100).

请先登录,再进行评论。

采纳的回答

Ben
Ben 2024-4-8
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 个评论
Fabien SANCHEZ
Fabien SANCHEZ 2024-5-30
编辑:Fabien SANCHEZ 2024-5-30
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).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by