invalid training data. for network with 1 inputs and 1 output, datastore read function function must return a cell array with 2 columns but it returns cell array with 1 column
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
filepath = fullfile(matlabroot,"toolbox","images","disease");
files = [filepath; filepath; filepath];
volds = imageDatastore(filepath, ...
"IncludeSubfolders",true,'FileExtensions','.nii','ReadFcn',@(x) niftiread(x),"LabelSource","foldernames");
filepath1 = fullfile(matlabroot,"toolbox","images","LabelNames");
files1 = [filepath1; filepath1; filepath1];
classNames = ["1" ;"2" ;"3"; "4"];
pixelLabelID = [1; 2 ;3 ;4];
pxds = pixelLabelDatastore(filepath1,classNames,pixelLabelID, ...
'FileExtensions','.nii','ReadFcn', @(x) (niftiread(x)>0));

0 Kommentare
Antworten (1)
Jinal
am 4 Okt. 2023
Bearbeitet: Jinal
am 4 Okt. 2023
Hello thamizh vani,
As per my understanding, you are getting the error: “invalid training data. for network with 1 inputs and 1 output, datastore read function must return a cell array with 2 columns but it returns cell array with 1 column” while training a network” while training a network.
As the error mentions, the datastore read function should provide output as a cell array with two columns for “trainNetwork” to function correctly. Instead, it is returning an array with only one column currently.
The issue can be resolved using any of the following workarounds:
1) The metadata (such as file paths and class labels) for all the images can be saved in individual MAT-files. Then, a "fileDatastore" can be created from these MAT-files using a custom "ReadFcn" which returns the filepath as well as label of the image.
Please refer this page to get more information about how to implement this workaround: https://in.mathworks.com/matlabcentral/answers/736077-why-do-i-get-error-invalid-training-data-for-multiple-input-network-while-training-deep-neural-net
To know more about “fileDataStore”, the following link can be referred: https://in.mathworks.com/help/releases/R2022a/matlab/ref/matlab.io.datastore.filedatastore.html
2) Modifying the custom "ReadFcn” to ensure that it returns a cell array with 2 columns. For example, labels for the output data can be explicitly returned by passing the information of each image can be passed as the second argument to the "ReadFcn".
function outputData = customreader(x, info)
V = niftread(x);
outputData = {V, info.Label};
end
Best Regards,
Jinal Patel
0 Kommentare
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!