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 件のコメント

KSSV
KSSV 2018 年 2 月 21 日
What problem you face for reading cells?
SRUTHY SKARIA
SRUTHY SKARIA 2018 年 2 月 21 日
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.

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

 採用された回答

Javier Pinzón
Javier Pinzón 2018 年 2 月 21 日
編集済み: Javier Pinzón 2018 年 2 月 21 日

3 投票

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

4 件のコメント

SRUTHY SKARIA
SRUTHY SKARIA 2018 年 2 月 21 日
Thank you soo much Javier, It helped a lot. I just wanted to check if CNN can work on 2 channels, so I wanted to input the data. There is another small doubt, so if I have 50 samples of one class, should I save it in 50 mat files? I have one mat file with 50 cells of data. I was wondering if it is possible to read 50 samples from a one mat file. Eg: my mat file it Class1 and inside matfile is 1x50 cell array of 60x60x2 samples. Hope I dont trouble you. Thanks in Advance. Sruthy
Javier Pinzón
Javier Pinzón 2018 年 2 月 22 日
編集済み: Javier Pinzón 2018 年 2 月 22 日
Due to the condition that matlab read the samples 1 by 1, you cannot enter the entire samples in a single array, so, you need to have a .mat file for each sample for the training, also for the validation if used. In other words, in your category subfolder, you need to have 50 mat files of 60x60x(1 - 3) samples, and also, each variable of 60x60x(1-3) MUST HAVE the same name ( not necessary the .mat file), because in your read function you need to call it by its name as i explained above.
Hope it helps, and if my answer was what you needed, I appreciate that you accept it.
Regards
Javier
SRUTHY SKARIA
SRUTHY SKARIA 2018 年 2 月 22 日
Thank you Javier,
Your help is much appreciated..!!!
Nazmun Nahar Khan
Nazmun Nahar Khan 2021 年 9 月 3 日
Hi,
So I am also facing same issues. I also tried to use readfc1 as you mentioned above. Unfortunately, I am getting an error.
Error using trainNetwork (line 170)
Reference to non-existent field 'signaldata'.
Error in trainingCNN (line 70)
trainedNet = trainNetwork(imdsTrain,layers ,options);
Caused by:
Error using matlab.io.datastore.ImageDatastore/read (line 77)
Error using ReadFcn @readFcn1 for file:
C:\Users\data analysis\100\High\Data100_102.mat
Reference to non-existent field 'signaldata'.
Error in trainingCNN>readFcn1 (line 88)
I = I.signaldata;
So how can I fix it?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by