How to train a image to image regression network that the input and output is come from different folder.

7 visualizaciones (últimos 30 días)
Hi,
I want to train a image to image regression network, but I faced a problem.
the input datastore that used for training is come from the function of "transform". but,If there is no direct connection between the input data and the output data, in other words, the input data cannot be obtained through the "transform" function. In this case, how should the training set be constructed?
In order to solve this problem, I tried to build two datastores, one as input, and another as output. Finally, I used the "combine" function to generate the input - output pair. Here is my code:
%% output datastore
dataFolderout = fullfile('A:\wtl\New\Y');
imdsout = imageDatastore(dataFolderout, ...
'IncludeSubfolders',true, ....
'LabelSource','foldernames');
imdsout = shuffle(imdsout);
[imdsTrainout,imdsValout,imdsTestout] = splitEachLabel(imdsout,0.7,0.15,0.15,'randomized');
%% input datastore
dataFolderin = fullfile('A:\wtl\New\X');
imdsin = imageDatastore(dataFolderin, ...
'IncludeSubfolders',true, ....
'LabelSource','foldernames');
imdsin = shuffle(imdsin);
[imdsTrainin,imdsValin,imdsTestin] = splitEachLabel(imdsin,0.7,0.15,0.15,'randomized');
%% the combined datastore
dsTrain = combine(imdsTrainin,imdsTrainout); %%
dsVal = combine(imdsValin,imdsValout);
dsTest = combine(imdsTestin,imdsTestout);
%%training option
Minibatchsize=4;
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize',Minibatchsize, ...
'ValidationData',dsVal, ...
'Plots','training-progress', ...
'Verbose',false);
After running my code, I found that network can be trained.
But, after I rescale the two datastores using the "transform" function (code is shown below), and run the code of training options, there always report errors
(Error using nnet.cnn.TrainingOptionsADAM (line 129)
The value of 'ValidationData' is invalid. The datastore used for
'ValidationData' must return a table or cell array with at least 2
columns.
Error in trainingOptions (line 302)
opts = nnet.cnn.TrainingOptionsADAM(varargin{:});).
%% normalize the datastore
imdsTrain = transform(imdsTrain,@(x) rescale(x));
imdsVal = transform(imdsVal,@(x) rescale(x));
imdsTest = transform(imdsTest,@(x) rescale(x));
Note that the type of original data of my datastore is uint 16, the input and output of the network are in two different folders (X and Y), and each folder has the same number of subfolders (3) and pictures (100). Althrough I convert they to uint 8, the error still exist.
so, how can i solve this problem? help me, please!

Respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by