datastore error in dicom AI classification
4 views (last 30 days)
Show older comments
hi i get this error i need some help to fix it ?
Error using matlab.io.datastore.ImageDatastore
Files must be a valid string scalar, character vector, cell array of character vectors, string array, or a
matlab.io.datastore.FileSet.
on this row
imds = imageDatastore(dataSource,...
'IncludeSubfolders',true,...
'FileExtensions','.dcm',...
'ReadFcn',@(dcmfile) repmat(uint8(dicomread(dicominfo(dcmfile))),1,1,3));
pxds = pixelLabelDatastore(cellstr(labelData),labelDefs.Name,labelDefs.PixelLabelID,...
'IncludeSubfolders',true,...
'ReadFcn',@readFramesLabels,...
'FileExtensions','.mat');
pxlabeltbl = countEachLabel(pxds)
more over if someone can double check my code i whould realy appriciate it
this is the code
clear; close all; clc
%doTraining ;
try
prj = currentProject;
catch
OpenProject(pwd)
OpenPart01;
prj = currentProject;
end
datafolder = fullfile(prj.RootFolder,'Data');
load(fullfile(datafolder,"gTruthMed.mat"))
dataSource = gTruthMed.DataSource.Source;
labelData = gTruthMed.LabelData;
labelDefs = gTruthMed.LabelDefinitions;
imds = imageDatastore(dataSource,...
'IncludeSubfolders',true,...
'FileExtensions','.dcm',...
'ReadFcn',@(dcmfile) repmat(uint8(dicomread(dicominfo(dcmfile))),1,1,3));
pxds = pixelLabelDatastore(cellstr(labelData),labelDefs.Name,labelDefs.PixelLabelID,...
'IncludeSubfolders',true,...
'ReadFcn',@readFramesLabels,...
'FileExtensions','.mat');
pxlabeltbl = countEachLabel(pxds);
[net,info] = trainNetwork(datasource,lgraph,options);
augmenter = imageDataAugmenter('RandXReflection',true,...
'RandXTranslation',[-10 10], 'RandYTranslation',[-10 10],...
'RandRotation',[0 180]);
dataSource = pixelLabelImageDatastore(imds,pxds,...
'DataAugmentation',augmenter);
imtotal = numel(dataSource.Images);
trainidx = floor(imtotal*0.75);
validx = floor(imtotal*0.2);
testidx = floor(imtotal*0.05);
shuffleindx = randperm(imtotal);
trainds = partitionByIndex(datasource,shuffleindx(1:trainidx));
valds = partitionByIndex(dataSource,shuffleindx(trainidx+1:trainidx+validx));
testds = partitionByindex(dataSource,shuffleindx(trainidx+validx+1:end));
bar([numel(trainds.Images),numel(valds.Images),numel(testds.Images)])
title('Partitioned Dataset')
xticklabels({'Training Set','Validation Set','Testing Set'})
ylabel('Number of dicoms')
imageSize = [256 256 3];
numClasses = height(pxlabeltbl);
lgraph = segnetLayers(imageSize,numClasses,'vgg16');
analyzeNetwork(lgraph)
freaquency = pxlabeltbl.PixelCount ./ pxlabeltbl.ImagePixelCount;
bar(1:height(pxlabeltbl),frequency)
xticklabels(pxlabeltbl.Name); xtickangle(45)
ylabel('Frequency')
lgraph.Layers(end)
pxLayer = dicePixelClassificatoinLayer(...
'Name','Label');
lgraph = removeLayers(lgraph, lgraph.Layers(end).Name);
lgraph = addLayers(lgraph,pxLayer);
lgraph = connectLayers(lgraph,lgraph.Layers(end-1).Name,'labels');
lgraph.Layers(end)
if doTraining
options = trainingOptions('sgdm',...
'Momentum',0.9,...
'InitialLearnRate',0.0002,...
'L2Regularization',0.0005,...
'MaxEpochs',100,...
'MiniBatchSize',4,...
'Shuffle','every-epoch',...
'VerboseFrequency',100,...
'ValidationData',valds,...
'ValidationPatience',5,...
'Plots','training-progress',...
'ExecutionEnvironment','auto');
[net,info] = trainNetwork(tain,lgraph,options);
else
imshow(fullfile(prj.RootFolder,"HelperFunctions","images","SegnetTrainingProgressPlot.png"))
end
load mySemSegNetwork.mat
testimds = imageDatastore(testds.Images,...
'FileExtensions','.dcm',...
'ReadFcn',@(dcmfile) repmat(unit8(dicomread(dicominfo(dcmfile))),1,1,3));
testpxds = pixelLabelDatastore(testds.PixelLabelData,labelDefs.Name,labelDefs.PixelLabelID,...
'includeSubfolders',true,...
'readFcn',@readFramesLabels,...
'FileExtentions','.mat');
pxdsResults = semanticseg(testimds,net,...
'WriteLocation',fullfile(datafolder,'Results'),...
'verbose',true);
[B,imtitle] = overlayRndcontour(testimds,pxdsResults);
imshow(B)
title(imtitle)
metrics = evaluateSemanticSegmentation(pxdsResults,testpxds);
metrics.ClassMetrics
h = heatmap(labelDefs.Name,labelDefs.Name,metrics.NormalizedConfusionMatrix.Variables);
thank you
0 Comments
Answers (1)
Kojiro Saito
on 23 Jan 2023
Possibly,
dataSource = gTruthMed.DataSource.Source;
is N ×1 cell array.
Just converting it to "1 x N cell array" with single quatation (') would work.
imds = imageDatastore(dataSource',...
0 Comments
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!