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

3 次查看(过去 30 天)
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));

回答(1 个)

Jinal
Jinal 2023-10-4
编辑:Jinal 2023-10-4
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.
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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by