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!