how to reduce time for this Convolutional Neural Network to get result?

1 visualizzazione (ultimi 30 giorni)
I have a problem and no time with me, please help me if you can, how can I reduce the time taken by this CNN to get the result ?
newImage = imread(fullfile('test3.PNG'));
net = resnet50();
net.Layers(1);
net.Layers(end);
outputFolder = fullfile('discontinuities');
rootfolder = fullfile(outputFolder,'discontinuities types');
types = {'longitudinal crack','transverse crack'};
imds = imageDatastore(fullfile(rootfolder,types),'Labelsource','foldernames');
[trainingSet, testSet] = splitEachLabel(imds, 0.3 , 'randomize');
imageSize = net.Layers(1).InputSize;
augmentedTrainingSet = augmentedImageDatastore(imageSize, ...
trainingSet, 'ColorPreprocessing', 'gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize, ...
testSet, 'ColorPreprocessing', 'gray2rgb');
ds = augmentedImageDatastore(imageSize,...
newImage, 'ColorPreprocessing', 'gray2rgb');
featureLayer = 'fc1000';
trainingFeatures = activations(net, ...
augmentedTrainingSet, featureLayer, 'MiniBatchSize', 32, 'OutputAs', 'columns');
trainingLabels = trainingSet.Labels;
classifier = fitcecoc(trainingFeatures, trainingLabels, ...
'Learner', 'Linear', 'Coding', 'onevsall', 'ObservationsIn', 'columns');
testFeatures = activations(net, ...
augmentedTestSet, featureLayer, 'MiniBatchSize', 32, 'OutputAs', 'columns');
predictLabels = predict(classifier, testFeatures, 'ObservationsIn', 'columns');
testLabels = testSet.Labels;
imageFeatures = activations(net, ...
ds, featureLayer, 'MiniBatchSize', 32, 'OutputAs', 'columns');
label = predict(classifier, imageFeatures, 'ObservationsIn', 'columns');
sprintf('The loaded image belongs to %s class', label)
  5 Commenti
Walter Roberson
Walter Roberson il 5 Giu 2023
We do not know what parts are important to you, so it is difficult to advise what might be faster.
You appear to have only two classes of input, which might suggest that you could use a two-class SVM trainer instead of using fitcecoc() which is for multi-class SVM.
On the other hand, I notice that you do not have a third directory for "no crack". And that means that if you were to feed in a picture of (for example) an orange, that it would have to classify it as either having a transverse crack or longitudinal crack. Any time you fit against multiple classes, the technology you are using has no method of saying "None of the above": it must resolve any input to one of the classes.
I would suggest to you that you should have at least three and possibly four classes: (1) longitudinal crack, (2) transverse crack; (3) no crack; and (possibly) (4) cracks but indeterminate, such as a picture that has cracks in multiple directions.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 5 Giu 2023
See https://www.mathworks.com/help/stats/fitcecoc.html#d124e356431 for information on 'options' 'useparallel' for computation in parallel provided you have the Parallel Computing Toolbox
To use GPU you would need to have Parallel Computing Toolbox, and an appropriate NVIDIA GPU and would need to have created data as a gpuArray and would need to have configured 'Learners' as svm, knn, or tree (possibly by using the corresponding template function); in such a case you would not use 'Options', 'UseParallel'; see https://www.mathworks.com/help/stats/fitcecoc.html#refsect-extended-capabilities

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by