Deep Learnign pre-processing image datastore

4 visualizaciones (últimos 30 días)
mz123
mz123 el 8 de Abr. de 2021
Editada: mz123 el 12 de Abr. de 2021
Good morning,
I'm trying to simplify my question which I'm not able to solve. I've got an image datastore of grayscale imges with size [1674 1396]. I have a function which basically extract a ROI from the image and the resize it to fit the input layer of the net and also convert to rgb. The function i wrote is the following:
function M = myFunc(I) %image as input; image as output
I = imadjust(I);
BW = false(size(I,1),size(I,2)); % Create empty mask.
% Draw ROIs
xPos = [133.3982 236.8818 1131.7109 1239.2527 1271.7182 1156.0600 261.2309 163.8345];
yPos = [236.8891 113.1145 102.9691 242.9764 1452.3145 1588.2636 1600.4382 1492.8964];
m = size(BW, 1);
n = size(BW, 2);
addedRegion = poly2mask(xPos, yPos, m, n);
BW = BW | addedRegion;
% Create masked image.
M = I;
M(~BW) = 0;
M = imresize(M,[224 224]);
end
According to this example https://it.mathworks.com/help/deeplearning/ug/datastores-for-deep-learning.html at the paragraph Example: Transform Image Datastore to Train Digit Classification Network
I optain the following error:
Error using trainNetwork (line 170)
Invalid training data. Responses must be nonempty.
like in this topic
but I'm not able to fix my function to perform my task.
Here my full script:
imPath = 'C:\Users\zanoli.TECNO06\Documents\MATLAB\FILM\Pictures\'; %path to images
imds = imageDatastore(imPath,'FileExtensions','.jpg',...
"IncludeSubfolders",true,"LabelSource","foldernames"); %definition of an image-datastore
numClasses = numel(categories(imds.Labels)); % count how many different labels are present
dsnew = transform(imds,@preprocessForTraining,'IncludeInfo',true); %definition of transformed datastore applying transform function defined by "@"
%% standard commands for googlenet
net = googlenet;
lgraph = layerGraph(net);
newFc = fullyConnectedLayer(numClasses,"Name","new_fc");
lgraph = replaceLayer(lgraph,"loss3-classifier",newFc);
newOut = classificationLayer("Name","new_out");
lgraph = replaceLayer(lgraph,"output",newOut);
options = trainingOptions("sgdm","InitialLearnRate", 0.01); %
ly = net.Layers;
inputLayer = ly(1);
inputSize = inputLayer.InputSize;
targetSize = [inputSize(1) inputSize(2)];
%% End of standard commands for googlenet
[filmNet,info] = trainNetwork(dsnew, lgraph, options); % do the trainig but error appears here!!!!!!!
function [dataOut, info] = preprocessForTraining(data,info)
data = imadjust(data);
% Create empty mask.
BW = false(size(data,1),size(data,2));
% Draw ROIs
xPos = [133.3982 236.8818 1131.7109 1239.2527 1271.7182 1156.0600 261.2309 163.8345];
yPos = [236.8891 113.1145 102.9691 242.9764 1452.3145 1588.2636 1600.4382 1492.8964];
m = size(BW, 1);
n = size(BW, 2);
addedRegion = poly2mask(xPos, yPos, m, n);
BW = BW | addedRegion;
% Create masked image.
dataOut = data;
dataOut(~BW) = 0;
dataOut = imresize(dataOut,[224 224]);
end
Why I'm not able to perform my task?
Any suggestion is kindly appreciated. Thank you!

Respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by