I am trying to reproduce the convolution network described in https://arxiv.org/abs/1610.01683 .
Overview of their setup:
However, I seem to run into an obstacle when trying to combine results from different filters. In the paper, the authors have "stacking" layer, where 20 different filtered 1D signals are stacked, to create a sort of spectrogram, which is then fed to another convolutional layer. How does one do a similar thing in matlab? Below is what I have tried, and the error message that I get:
Input:
inputLayer=imageInputLayer([1 6000]);
c1=convolution2dLayer([1 200],20,'stride',1);
p1=maxPooling2dLayer([1 20],'stride',10);
c2=convolution2dLayer([20 30],400,'numChannels',20);
p2=maxPooling2dLayer([1 10],'stride',[1 2]);
f1=fullyConnectedLayer(500);
f2=fullyConnectedLayer(500);
s1=softmaxLayer;
outputLayer=classificationLayer;
convnet=[inputLayer; c1; p1; c2; p2; f1; f2; s1;outputLayer]
opts = trainingOptions('sgdm');
convnet = trainNetwork(allData',labels,convnet,opts);
Output:
convnet =
9x1 Layer array with layers:
1 '' Image Input 1x6000x1 images with 'zerocenter' normalization
2 '' Convolution 20 1x200 convolutions with stride [1 1] and padding [0 0]
3 '' Max Pooling 1x20 max pooling with stride [10 10] and padding [0 0]
4 '' Convolution 400 20x30 convolutions with stride [1 1] and padding [0 0]
5 '' Max Pooling 1x10 max pooling with stride [1 2] and padding [0 0]
6 '' Fully Connected 500 fully connected layer
7 '' Fully Connected 500 fully connected layer
8 '' Softmax softmax
9 '' Classification Output cross-entropy
Error using nnet.cnn.layer.Layer>iInferSize (line 261)
Layer 5 is expected to have a different size.
Error in nnet.cnn.layer.Layer.inferParameters (line 53)
layers = iInferSize(layers, i, inputSize);
Error in trainNetwork (line 61)
layers = nnet.cnn.layer.Layer.inferParameters(layers);
The error message is for layer 5, but I suspect it has to do with layer 4, where the "stacking" takes place. Thoughts?

2 件のコメント

AJAY SHANBHAG
AJAY SHANBHAG 2017 年 6 月 15 日
What is labels in the trainnetwork equation?
keshav kumar
keshav kumar 2020 年 8 月 22 日
How can we implement CNN on iris data?

サインインしてコメントする。

 採用された回答

Joss Knight
Joss Knight 2017 年 3 月 28 日
編集済み: Joss Knight 2017 年 3 月 28 日

7 投票

The 20 filters of c1 are stacked along dim 3, not dim 1. You need to specify a c2 filter size of [1 30], with dim 3 being inferred from the input:
c2 = convolution2dlayer([1 30],400);
Size 20 in dim 3 is inferred here to make the sizes correct, but you can explicitly set 'numChannels' to be certain.
This is the output I got:
9x1 Layer array with layers:
1 'imageinput' Image Input 1x6000x1 images with 'zerocenter' normalization
2 'conv' Convolution 20 1x200x1 convolutions with stride [1 1] and padding [0 0]
3 'maxpool' Max Pooling 1x20 max pooling with stride [10 10] and padding [0 0]
4 'conv_1' Convolution 400 1x30x20 convolutions with stride [1 1] and padding [0 0]
5 'maxpool_1' Max Pooling 1x10 max pooling with stride [1 2] and padding [0 0]
6 'fc' Fully Connected 500 fully connected layer
7 'fc_1' Fully Connected 500 fully connected layer
8 'softmax' Softmax softmax
9 'classoutput' Classification Output cross-entropy with '1', '2', and 498 other classes

2 件のコメント

Edwar Macias
Edwar Macias 2017 年 4 月 25 日
Thank you Joss, but i have some doubts about how to set the input and the fully connected layer.
-I'm working with 1-D signals, I storage all the training data (4990) in a matrix, each row is a signal with length 1600. Is it correcto to store thos data in an array (1600x4990) or should I store them in another way? -The second issue, regarding with the fully connected layers and its output, i have 4 target classes, but in your layer 9 you specifie that there are 500 classes, how can achieve just 4 classes??
Best regards
Joss Knight
Joss Knight 2017 年 4 月 26 日
Okay, so the help text for trainNetwork says
For an image input layer, X is a numeric array of images arranged so
that the first three dimensions are the width, height and channels,
and the last dimension indexes the individual images.
So to treat 1-D data like a stack of colour images, you need to arrange the data along one of the spatial dimensions (rows or columns), and the observations along the 4th dimension.
In other words, your data should be 1600-by-1-by-1-by-4990, or 1-by-1600-by-1-by-4990. You can achieve this using reshape.
The number of classes must match the size of the output of your final layer, which is typically done by having at least one final Fully Connected layer with that many outputs. In your code the last FC layer had 500 outputs, which is what I replicated in my code. It sounds like you want to change that layer to have 4 outputs.
All of this might benefit from reading a few introductory articles on deep learning to help give you some familiarity with the way they work.

サインインしてコメントする。

その他の回答 (6 件)

Kaushik Sardeshpande
Kaushik Sardeshpande 2018 年 5 月 8 日
編集済み: Kaushik Sardeshpande 2018 年 5 月 12 日

7 投票

Dear all,
I have a solution for using 1-D Convoluional Neural Network in Matlab. Well while importing your 1-D data to the network, you need to convert your 1-D data into a 4-D array and then accordingly you need to provide the Labels for your data in the categorical form, as the trainNetwork command accepts data in 4-D array form and can accept the Labels manually, if the dataset doesn't contains the labels, as in imageDatastore labels are imported in the dataset only, but we can input the labels manually also to CNN.
My dataset was an array of [A x 15000], containing A no. of signals with 15000 samples fo each. Which I converted into a 4-D array of size [1 x 15000 x 1 x A] using reshape command. Now you must sure that your label vector must be of size [A x 1]. To create label vector acceptable by trainNetwork, firstly you must create a cell array and then convert it to the categorical using the command categorical.
I'm sharing piece of my code for reference and it worked...!!! Hope it guide you all, who are working on 1-D CNN.
Train_data = reshape(Train_dataset, [1 15000 1 A]); % Dataset is ready %
%Now create the labels %
label(1:(A-30),:) = {'ABC'}; % 1st Label %
label((A-29):A,:) = {'XYZ'}; % 2nd Label %
Train_Labels = categorical(label); % Label vector is ready %
% Now input this data-set and labels to the network %
net = trainNetwork(Train_data, Train_Labels, layers, train_options);

25 件のコメント

xin li
xin li 2018 年 6 月 10 日
I want to imply 1-D Convoluional Neural Network to fault diagnosis in the filed of mechanical system,but without code, can you send me a copy of your code? Thank you very much!!! lixinhun123@gmail.com
Ayomi
Ayomi 2018 年 8 月 9 日
Dear Kaushik, Thank you for sharing this, really appreciated. I would like to ask you , Did the training produced properly functioning CNN serving the purpose of the application your working on ?
SHILPA K
SHILPA K 2019 年 2 月 11 日
編集済み: SHILPA K 2019 年 2 月 11 日
sir
can you provide your data set and copy of your code.
shilpakulangara96@gmail.com
André Tavares
André Tavares 2019 年 7 月 22 日
I am also working with 1-D Convolutional Neural Networks for signal analysis. Could you also send me a copy of your code? Thank you very much!
andregmtavares@gmail.com
Chia Yu Lai
Chia Yu Lai 2019 年 9 月 4 日
Hi ,I am working with 1-D CNN in Matlab now. Could you also send me a copy of your code? Thanks!
aileenuwu@gmail.com
Kalyan Bondalakunta
Kalyan Bondalakunta 2019 年 9 月 11 日
Sir,
I'm also working on the 1D CNN in Matlab.Can u send me your dataset and code for reference.
Thank you,Sir...!!!
kalyan.bondalakunta@gmail.com
Liou Yu-Syuan
Liou Yu-Syuan 2019 年 11 月 16 日
I'm working on the 1D-CNN in Matlab, too. The same error I got is:
"Error using trainNetwork (line 165) Invalid training data. X must be a 4-D array of images, an ImageDatastore, or a table."
But when I change my SignalsTrain dataset (1748x1 cell array) into reshape() function like this: CNN_TrainingData = reshape(SignalsTrain,[height, width, channels, sampleSize]);
, which height = 1, width = 15000, channels = 1, sampleSize = 1748.(my total array like your 'A'.), I got a error message:
"Error using reshape, To RESHAPE the number of elements must not change."
Because my all signal data in 1748x1 cell array are not same length, which means some signal are 1x88001, some are 1x750001.
But I cannot solve this problem when I set 'width' parameter in reshape() function to any fixed integer like 9000, 15000, or even exactly the length of each SignalTrain(88001 or 750001 or others).
How can I solve this problem? Thanks for your response.
Best regards.
bangjiong chen
bangjiong chen 2020 年 2 月 4 日
hi,Sir,
I'm also working on the 1D CNN in Matlab.Can u send me your dataset and code for reference.
Thank you very much,Sir...!!!
1206292278@qq.com
eman mohammad
eman mohammad 2020 年 3 月 10 日
Hi,
can you send me your dataset and code for reference.
Thank you,Sir..!!
harahsheheman234@gmail.com
Sami Ullah
Sami Ullah 2020 年 4 月 19 日
HI,
I am trying to make CNN 1d function kindly help me
Regards
Sami
Shiu Kumar
Shiu Kumar 2020 年 4 月 22 日
編集済み: Shiu Kumar 2020 年 4 月 22 日
Hi
Can you please send me the code for this (shiu748@gmail.com).
Regards
Shiu
Thomas Schmitz
Thomas Schmitz 2020 年 5 月 4 日
Working, thx
Shengjie Ren
Shengjie Ren 2020 年 6 月 13 日
it's work,th
Shengjie Ren
Shengjie Ren 2020 年 7 月 6 日
Works, but why does the loss curve of the validation set rise?
dionisio martins
dionisio martins 2020 年 8 月 8 日
Sir,
I'm also working on the 1D CNN in Matlab.Can you send me your dataset and code for reference.
Thank you,Sir...!!!
dionisiohenrique@ig.com.br
DESTINE MASHAVA
DESTINE MASHAVA 2020 年 8 月 14 日
編集済み: DESTINE MASHAVA 2020 年 8 月 14 日
I am also working on 1D CNN l am kindly asking for the code for reference dmashy@gmail.com
Thank you sir
Amirah Nabilah Azman
Amirah Nabilah Azman 2021 年 4 月 8 日
Hello sir, I am also trying to do 1D CNN. Can you kindly send me the code? (amirahnabilahazman@gmail.com)
muhammad hafez
muhammad hafez 2021 年 7 月 8 日
Sir,
I'm also working on the 1D CNN in Matlab.Can you send me your dataset and code for reference.
el.rouby55@yahoo.com
Fernando Meneses
Fernando Meneses 2021 年 7 月 23 日
Hello Kaushik Sardeshpande, thank you very much for your explanation. Could you please send me the code? (fmeneses@ccny.cuny.edu) I'm trying to build a 1D CNN. Thank you very much.
Parichada Trairat
Parichada Trairat 2021 年 8 月 15 日
Can you pls explain about Train_Labels
Javier Castillo
Javier Castillo 2021 年 9 月 13 日
Sir,
I am also working on a 1D CNN in Matlab may I also get your code as a reference for my project. Thank you very much.
QUAN WANG
QUAN WANG 2021 年 9 月 16 日
@Javier Castillo , Hi JC did you solve you probelm , i am also doing 1D cnn project , I have some problem , maybe we can discuss .
QUAN WANG
QUAN WANG 2021 年 9 月 17 日
@Kaushik Sardeshpande Hi this is quan , i have some problem on 1 DCNN for my project , could you help me ?
Bassem Gehad
Bassem Gehad 2022 年 7 月 17 日
hi,Sir, I'm also working on the 1D CNN in Matlab.Can you send me your dataset and code for reference. Thank you very much,Sir...!!! bassemgog@gmail.com
Nikolas Katsaros
Nikolas Katsaros 2023 年 3 月 11 日
編集済み: Nikolas Katsaros 2023 年 3 月 13 日
@Kaushik Sardeshpande Hi there - thank you very much for posting your solution. Could you please send the full code? I would be incredibly grateful - katsaros38@gmail.com

サインインしてコメントする。

Edwar Macias
Edwar Macias 2017 年 3 月 28 日

0 投票

Dear Kaare, i'm working in something similar, i'm traying to run 1-D CNN but i couldn't done it, Could you do it?
Best regards

2 件のコメント

kaare
kaare 2017 年 3 月 28 日
Dear Edwar
Unfortunately, not. I ended up contacting mathworks, and they gave me the following:
----------------------------------------------------
Hello Kaare,
(...)
I understand that you want to set the input layer of a neural network to be a one dimensional object but received an error. Indeed, the toolbox is expecting a 2-D object (image) as the input, and would not be able to process 1-D object.
In order to feed the data with time series into the Convolutional Neural Networks Toolbox, you can chop the time series into windows, then calculate the spectrogram, This way you turn the 1-D data into an "image". Then you can classify on the 2-D dataset.
We have transferred your feedback to our Development team, and they may consider a future release which contains the expected functionality. Thank you very much for this information.
----------------------------------------------------
I then tried this, but ended up giving up completely, since matlab started making the gpu crash. I have since moved over to python, and am getting acquainted with keras & theano.
SHILPA K
SHILPA K 2019 年 2 月 5 日
can you explain the implementation in python

サインインしてコメントする。

Edwar Macias
Edwar Macias 2017 年 4 月 6 日

0 投票

Dear Kaare,
What a pity! I wanted to try it, anyway i'll try again, if i can find some result i'll tell you! Cheers!

2 件のコメント

Joss Knight
Joss Knight 2017 年 4 月 13 日
Please see my answer, this is a misunderstanding by tech support, support for this network is perfectly possible.
SAM
SAM 2017 年 11 月 21 日
I tried to do it but it only accepts 4D image input

サインインしてコメントする。

Diego Alonso
Diego Alonso 2017 年 9 月 20 日
編集済み: Diego Alonso 2017 年 9 月 20 日

0 投票

Hi everyone!
I am trying to apply deep learning to NILM data following this thesis: http://lemt.ufrj.br/pdf/pedro.pdf
In summmary, I have an aggregated power signal and I want to disaggregate it. I also have the disaggregate consumption of each appliance so I have to use as input the aggregate signal and as target the disaggregated consumption of an appliance. How can I do this with a CNN?
Thanks
Diego
Kaushik Sardeshpande
Kaushik Sardeshpande 2018 年 4 月 25 日

0 投票

Hello Kaare,
I'm facing the same problem while implementing signal(1-D) classification using CNN. Can you please guide me how you created the database which is acceptable by trainNetwork . I'm converting my entire data into a 4-D array and then feeding it to the network with labels, but still its giving me error as X and Y must have same number of observations.
net = trainNetwork(dataset, Labels, layers, train_options);
Invalid training data. X and Y must have the same number of observations.

3 件のコメント

kaare
kaare 2018 年 4 月 25 日
Dear Kaushik As I already wrote above, I ended up abandoning matlab in this project, and learned how to do it in Python instead.
Parisa Yas
Parisa Yas 2021 年 5 月 12 日
Dear Kaushik
Did you solve your problem?
Iget this error like you
QUAN WANG
QUAN WANG 2021 年 9 月 16 日
@Parisa Yas, dear Parisa ,did you solve your problem ? I am also doing a 1D CNN in matlab for my project . some problem with me .

サインインしてコメントする。

prash
prash 2018 年 6 月 28 日

0 投票

Hello Kaushik
I do not understand how you are setting up your 4D array. If you have A signals, each signal has lets say N time history. You have A X N matrix for 1 sample. Like this you will have multiple samples 15000. So you have A X N X 15000 array. Now how did you reshape it? How does you "Train_dataset" array looks? Can you send snapshot?

質問済み:

2017 年 3 月 21 日

編集済み:

2023 年 3 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by