MATLAB Answers

CNN with data_set

76 views (last 30 days)
Hi,
I want to train CNN with 2 channel data set which is stored in a cell array in a .mat file. have 4 such mat files in 4 folders which are used for labelling. I want to read those cellarray data from the mat files using imageDatastore. I was able to read the entire mat file, but I am having trouble reading the cell array data, which are actually the inputs for my training. Would anyone able to help me regarding this.
Thanks in Advance.
  2 Comments
SRUTHY SKARIA
SRUTHY SKARIA on 21 Feb 2018
I have a function to read the data I want.. function I = customreader(filename) I = load(filename); I = I.data; end And then updated my readFcn by imds.ReadFcn= @customreader. But I think it is not reading the function...that is I is empty even after the program execution.

Sign in to comment.

Accepted Answer

Javier Pinzón
Javier Pinzón on 21 Feb 2018
Edited: Javier Pinzón on 21 Feb 2018
hello Sruthy
I checked your request and problem, lets begin with an example from the call of the data.
location = 'Data/Train';
imds = imageDatastore(location, 'FileExtensions', '.mat', 'IncludeSubfolders',1, ...
'LabelSource','foldernames');
In the folder "Train" i have the 4 subfolders of each category, and in each subfolder, there are 100 .mat file with the data.
Then, parametrize the store variable:
countEachLabel(imds)
trainingDS = imds;
% Convert labels to categoricals
trainingDS.Labels = categorical(trainingDS.Labels);
trainingDS.ReadFcn = @readFcn1;
About the readFcn1, you only have to copy this in your read function:
function I = readFcn1(filename)
% Load data and get matrices from the structure
I = load(filename);
I = I.signaldata;
However, there is an important annotation that need to take into account, If you can see, I save the data in a variable called "I", and then, rewrite the variable with a "I.signaldata". The parameter signaldata is THE NAME OF YOUR VARIABLE IN THE .mat file, so you had to save all data with the same name in the work space, so when you load the mat file, it will have the same name for matlab, for example: I saved my ".mat" files with the name (signal1, signal2, signal3.mat... and so) but the variable in it is called "signaldata", so, all .mat have the same variable name but with different data inside.
If you dont call your variable iside the mat file with the same name, it make complicated to read the data.
you asked for the "filename" variable... no, it keep that name, because is called directly from the function.
Also, i highly recommend you to save the data inside of your variable as an "double array", because the CNN cant read "cell, struct", and so as input data. An also, the CNN only work with 1 or 3 channels, not with 2 or +4. so you would need to reorganize your data in 1 or 3 channels.
Hope it helps
Regards
Javier
  3 Comments
SRUTHY SKARIA
SRUTHY SKARIA on 22 Feb 2018
Thank you Javier,
Your help is much appreciated..!!!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!