Image Regression using .mat Files and a datastore

150 views (last 30 days)
Matthew Fall
Matthew Fall on 29 Apr 2019
Commented: luisa di monaco on 6 Jan 2022 at 12:58
I would like to train a CNN for image regression using a datastore. My images are stored in .mat files (not png or jpeg). This is not image-to-image regression, rather an image to single regression label problem. Is it possible to do this using a datastore, or at least some other out-of-memory approach?

Accepted Answer

luisa di monaco
luisa di monaco on 7 Dec 2019
Edited: luisa di monaco on 2 Jan 2020
I have solved something similar.
I'm trying to train a CNN for regression. My inputs are numeric matrices of size 32x32x2 (each input includes 2 grayscale images as two channels). My outputs are numeric vectors of length 6.
500 000 is the total amount of data.
I created 500 000 .mat file for inputs in folder 'inputData' and 500 000 .mat file for target in folder 'targetData'. Each .mat file contains only 1 variable of type double called 'C'.
The size of C is 32x32x2 (if input) or 1x6 (if target).
inputDatat = transform(inputData,@(data) rearrange_datastore(data));
targetDatat = transform(targetData,@(data) rearrange_datastore(data));
% here I defined my network architecture
% here I defined my training options
net=trainNetwork(trainData, Layers, options);
function image = rearrange_datastore(data)
image= {image};
luisa di monaco
luisa di monaco on 6 Jan 2022 at 12:58
the creation process was part of my thesis work. Here you can download my thesis: . Dataset creation is described in chapter 4 (4.2, 4.3 and 4.5) .
Here you can find some Matlab code:
I hope this can help.

Sign in to comment.

More Answers (2)

Johanna Pingel
Johanna Pingel on 29 Apr 2019
Edited: Johanna Pingel on 29 Apr 2019
I've used a .mat to imagedatastore conversion here:
imds = imageDatastore(ImagesDir,'FileExtensions','.mat','ReadFcn',@matRead);
function data = matRead(filename)
inp = load(filename);
f = fields(inp);
data = inp.(f{1});
tianliang wang
tianliang wang on 28 Apr 2021
Is it more convenient to use mat files as the training set for the images to vectors regression ?

Sign in to comment.

Lykke Kempfner
Lykke Kempfner on 16 Aug 2019
I have same problem.
I have many *.mat files with data that can not fit in memory. You may consider the files as not standard images. I have the ReadFunction for the files. I wish to create a datastore (?) where each sample are associated with two single values and not a class.
Are there any solution to this issue ?

Community Treasure Hunt

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

Start Hunting!