Apply non-image data to CNN
조회 수: 7 (최근 30일)
이전 댓글 표시
I am trying to train a CNN with a numerical data set. Once the input data is not an image format. Assuming my data has a size of 1850*11 matrix. With a 1850*1 label (for output). In libsvm I can use it directly and in the Neural Network Toolbox (nnstart) as well.
However, in case I want to use a CNN network. The only training function is "trainNetwork" it could only support image as an input. So how could I train the CNN with my data on Matlab?
Any simple example will be appreciated.
Thanks to all of in advance.
Gad
댓글 수: 0
채택된 답변
Shivam Gupta
2019년 3월 4일
You can read in your data using the function "imageDatastore" with a custom read function.
For example,
nonImageData = imageDatastore(pathToDataFiles, 'IncludeSubfolders', true, 'LabelSource', 'foldernames', 'FileExtensions', '', 'ReadFcn', @customreader);
You can then use 'nonImageData' as you would normally use an "imageDatastore" - for example, as input to "splitEachlabel" or "trainNetwork".
Note: Be careful to watch for negative numbers, however, as some layers (ex. ReLULayer) will convert all negative values to zero.
For more information, see:
For more Related MATLAB Answers see:
댓글 수: 9
Shivam Gupta
2019년 3월 5일
Hi Gad,
Have you followed this "Copy Training_F.mat file first 21 columns to new file say 'signal.mat' and change the name of variable to 'data'."
For your training only first 21 columns are required not the 22nd column.
추가 답변 (3개)
Zia Uddin Ahmed Zihan
2019년 6월 21일
Hi Shivam,
I am also struggling with the same. My problem is I want to run the numerical data alongside each image to improve image classification accuracy. I ran my code according to your suggestion. However, how am I supposed to know if MATLAB is taking the image and numerical data correctly simultaneously?
Thanks,
Zia
댓글 수: 0
Abdullah Bittar
2020년 5월 25일
Hi Guys,
I am also trying to train CNN using non image data. I followed the steps that were published by Shivam Gupta but was not seccussful. I am having the following problem.
Error using trainNetwork (line 150)
The training images are of size 1x1x1 but the input layer expects images of size 137x14x1.
Error in save_mat_try (line 22)
trainedNet = trainNetwork(imds,layers,options);
I sparated my input datafrom my output (target data) into two separate mat files. My input data has 14 colunms and 137 rows. Therefore it is the size of [137 14 1].
I have my imageInputLayer as imageInputLayer([137 14 1]
I tried searching for a solution for my probelm but i didnt find any solution. I would truley appreciate the help.
Thank you
댓글 수: 0
Omar Almasarani
2021년 4월 20일
Hi,
I followed the answer of Shivam and it run but this in only input data without target. how do you define the target data?
댓글 수: 1
HayderMU
2022년 11월 2일
Exactly
I followed the code. The code NEVER LOADS THE CLASSES.
So it's training just on the fly. The last column which contains the target classes is comlpetely excluded. THe network is training on itself just to do nothing bcause no target classes are loaded.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!