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 (최근 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));

댓글 수: 0
답변 (1개)
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.
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!