Labelled data from volume segmenter

5 次查看(过去 30 天)
I have a 3D data 461by951by651 as a mat file and I used the volume segmenter app to label it. I got a 3D categorical Label of the same size as the data. I can not use this label as an input for a data store or for a training network as it has to be in an array. I tried using reshape function but it didn’t work. Any help?
  3 个评论
AMEN BARGEES
AMEN BARGEES 2022-7-27
data and labels are now 461by619101 in 2 separate .mat files,
do I have to save it as 461by1 619101 times files for the data and again for the labels as when I try the datastore splitEachLabel gives no validation files which give the error below.
imds=imageDatastore("F3\Data","FileExtensions",".mat","LabelSource","none", ...
"ReadFcn",@matRead,"Labels","F3\Labels");
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomize');
inputSize = [10 10];
numClasses = 2;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(5,20)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'MaxEpochs',4, ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);
Error using nnet.cnn.TrainingOptionsSGDM (line 119)
The value of 'ValidationData' is invalid. ImageDatastore has no labels.
Error in trainingOptions (line 324)
opts = nnet.cnn.TrainingOptionsSGDM(varargin{:});
Walter Roberson
Walter Roberson 2022-7-27
'Labels' as a property is expected to be the actual label content. There is no direct way to specify a corresponding file name, not that I can see.
You can set the Labels property, but you cannot do so on a per-file basis.
When you use imageDatastore, then the label is expected to be the label for the entire image.

请先登录,再进行评论。

回答(1 个)

prabhat kumar sharma
编辑:prabhat kumar sharma 2023-10-26
Hello Amen,
I understand you are facing issue with the labels of the data. As you are using 2D CNN then you have to convert your 3D MAT file data into 2D. When you convert your 3D data into 2D slices and treat each slice as an independent sample, you will need to have a label for each slice.
Typically, labels are 1D where each element in the array corresponds to a label for the corresponding sample in your dataset. For instance, if you have 1000 samples, you need to have a 1D array of 1000 labels.
If you convert your 3D data into 2D slices, the number of samples in your dataset will increase (since each slice is now a separate sample), and you will need to create a label for each slice.
So, if you originally had a 3D matrix with dimensions 461x951x651 and you convert this into 2D slices, you will have 651 slices (assuming you're slicing along the third dimension). You will then need a 1D array of 651 labels - one for each slice.
Remember that the order of the labels should match the order of the slices. The first label in your array corresponds to the first slice, the second label to the second slice, and so on.
You can refer the below code for conversion of labels.
% Assuming your 3D label matrix is stored in the variable 'labels3D'
labels3D = load('F3\Labels'); % Adjust this line according to how you're loading your labels
% Convert the 3D label matrix to 2D slices
labels2D = squeeze(mat2cell(labels3D, size(labels3D, 1), size(labels3D, 2), ones(1, size(labels3D, 3))));
% Now, you need to assign a single label for each 2D slice. This depends on your specific task.
% If you're doing classification and each slice belongs to a single class, you might take the most common label in each slice:
labels = cellfun(@(x) mode(x(:)), labels2D);
I hope it helps!

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by