MATLAB Answers

How to handle labels using fileDatastore in a CNN

44 views (last 30 days)
I have a collection of 50x1x12 mat files, that I need to upload into some datastore to subsequently pass into a convolutional neural network, how can I handle the labels of this files?, what datastore should I use?,
I have been trying with file datastore, the filedatastore does not handle the labels in the same way as the imagedatastore does getting them from the folder.
-What datastore can I use
-if I use filedatastore how can I handle the labels after getting them from the foler and in the moment of use net = trainNetwork( ? );
-how the inputlayer should initially set
I really appreacite the help I have been stuck with this for along time.

Accepted Answer

Madhav Thakker
Madhav Thakker on 14 Feb 2021
Hi Mauricio,
You can use two different datastores for reading the .mat files and labels separately. Then, you can use combine on the datastores and feed to the CNN network.
Hope this helps.
  1 Comment
Mauricio Piraquive
Mauricio Piraquive on 18 Feb 2021
Thanks for you answer,
I am doing this following the example
in the target Data I am using this function to get the labels from the folders
function label = readLabel(filename,classNames)
filepath = fileparts(filename);
[~,label] = fileparts(filepath);
label = categorical(string(label),classNames);
and then following the example I am uploading the files into the fileDatastore
classNames = string(1:2)
Should I trasnform before combine the filedatastores? if so, how should my transform function be?
I tried without transforming and i got this error:
"The training images are of size 1x1x1 but the input layer expects images of size 50x1x12"
Thanks for your help

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!