Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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));

Respuestas (1)

Jinal
Jinal el 4 de Oct. de 2023
Editada: Jinal el 4 de Oct. de 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.
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

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by