Image Regression using .mat Files and a datastore

조회 수: 54 (최근 30일)
Matthew Fall
Matthew Fall 2019년 4월 29일
댓글: luisa di monaco 2022년 1월 6일
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?

채택된 답변

luisa di monaco
luisa di monaco 2019년 12월 7일
편집: luisa di monaco 2020년 1월 2일
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).
inputData=fileDatastore(fullfile('inputData'),'ReadFcn',@load,'FileExtensions','.mat');
targetData=fileDatastore(fullfile('targetData'),'ReadFcn',@load,'FileExtensions','.mat');
inputDatat = transform(inputData,@(data) rearrange_datastore(data));
targetDatat = transform(targetData,@(data) rearrange_datastore(data));
trainData=combine(inputDatat,targetDatat);
% here I defined my network architecture
% here I defined my training options
net=trainNetwork(trainData, Layers, options);
function image = rearrange_datastore(data)
image=data.C;
image= {image};
end
  댓글 수: 18
Fadhurrahman
Fadhurrahman 2022년 1월 6일
편집: Fadhurrahman 2022년 1월 6일
hello @luisa di mona how did you create all 50000 mat files with 32x32? is there any refrence to do it?
luisa di monaco
luisa di monaco 2022년 1월 6일
Hi,
the creation process was part of my thesis work. Here you can download my thesis:
http://webthesis.biblio.polito.it/id/eprint/14716 . Dataset creation is described in chapter 4 (4.2, 4.3 and 4.5) .
Here you can find some Matlab code: https://github.com/lu-p/standard-PIV-image-generator
I hope this can help.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Johanna Pingel
Johanna Pingel 2019년 4월 29일
편집: Johanna Pingel 2019년 4월 29일
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});
  댓글 수: 2
Matthew Fall
Matthew Fall 2019년 4월 29일
Thank you for your swift reply.
Unfortunately, the matlab regression example requires loading all of the training and validation data in memory, which I want to avoid by using the datastore.
I've tried using the imageDatastore with regression labels before, but then trainNetwork gives me the error:
Error using trainNetwork (line 150)
Invalid training data. The labels of the ImageDatastore must be a categorical vector.
tianliang wang
tianliang wang 2021년 4월 28일
Is it more convenient to use mat files as the training set for the images to vectors regression ?

댓글을 달려면 로그인하십시오.


Lykke Kempfner
Lykke Kempfner 2019년 8월 16일
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 ?
  댓글 수: 2
Tomer Nahshon
Tomer Nahshon 2020년 1월 22일
Same here
tanfeng
tanfeng 2020년 10월 12일
You could try this
tblTrain=table(X,Y)
net = trainNetwork(tblTrain,layers,options);

댓글을 달려면 로그인하십시오.

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by