How to prepare imagedatastore for Image to single value regression

14 views (last 30 days)
I would like to train a CNN for image regression using a datastore. The output is a single value. I set the Labels in imagedatastore to a value vector(Y_train). But the debug information show the labels in imagedatastore must be a categorical vetcor. Is it possible to use the imagedatastore for regression problems.
ims_train = imageDatastore('F:\imagestore\train_image224', 'FileExtensions', '.tiff', 'Labels', Y_train, 'ReadSize', 128);
% here I defined my network architecture
% here I defined my training options
[net,Info] = trainNetwork(ims_train,lgraph,options);
  3 Comments
Cris LaPierre
Cris LaPierre on 5 Jan 2021
Edited: Cris LaPierre on 5 Jan 2021
Question from Sho Wright
Hi Qi Lu, I'm also trying to use imds and augimds to preprocess images for an image-to-value regression network, could you share your code if possible?
Cris LaPierre
Cris LaPierre on 5 Jan 2021
Qi lu's reply
Sorry. I don't find any solutions or workaround. It seems it's impossible to use imds to solve regression problems since the he labels in imagedatastore must be a categorical vetcor. But the labels in regression problems are values. Now I just load all image in the RAM and process image.

Sign in to comment.

Answers (1)

Joe Chalfoun
Joe Chalfoun on 12 Aug 2021
Edited: Joe Chalfoun on 12 Aug 2021
This solution worked for me:
Just get the list of files name from the regular imagedatastore and create a table of two columns, the first one is the files name and the second column is the regression response. You can then input that table to trainNetwork function or for the validation option too, like this:
For training:
[net, info] = trainNetwork(table(ims_train.Files,Y_train),lgraph,training_options);
to add validation data:
options = trainingOptions('ValidationData',table(ims_val.Files,Y_val));
Hope this helps.

Community Treasure Hunt

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

Start Hunting!