Apply non-image data to CNN
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Gadelhag M Omar Mohmed
le 1 Mar 2019
Commenté : HayderMU
le 2 Nov 2022
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 commentaires
Réponse acceptée
Shivam Gupta
le 4 Mar 2019
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 commentaires
Shivam Gupta
le 5 Mar 2019
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.
Plus de réponses (3)
Zia Uddin Ahmed Zihan
le 21 Juin 2019
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 commentaires
Abdullah Bittar
le 25 Mai 2020
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 commentaires
Omar Almasarani
le 20 Avr 2021
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 commentaire
HayderMU
le 2 Nov 2022
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.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!