how to connect if conditions with CNN ?

1 次查看(过去 30 天)
Please help if you can, how can i connect the result of the first part of this program (if condtions) with the second part of the program (Convolutional Neural Network) , if the result is not identified so i want to tell it to enter its image to complete identifying with CNN the first part : %enter data of scan clc,clear PAs = 44; DAs = 91; As = 93; Bs = 1; if (PAs==0) & (DAs==0) & (As==0) & (Bs==0) disp('specimen is sound'); elseif (45<PAs) & (PAs<55) & (90<DAs) & (DAs>100) & (As>100) & (Bs<2); disp('incomplete penetration') else disp('not identified'); end
the second part : clc clear all close all outputFolder = fullfile('discontinuities'); rootfolder = fullfile(outputFolder,'discontinuities types'); types = {'HAZ','lof','porosity'}; imds = imageDatastore(fullfile(rootfolder,types),'Labelsource','foldernames'); tbl = countEachLabel(imds); minSetCount = min(tbl{:,2}); imds = splitEachLabel(imds, minSetCount, 'randomize'); countEachLabel(imds); HAZ = find(imds.Labels == 'HAZ', 1); lof = find(imds.Labels == 'lof', 1); porosity = find(imds.Labels == 'porosity', 1);
% figure % subplot(2,2,1); % imshow(readimage(imds,HAZ)); % subplot(2,2,2); % imshow(readimage(imds,lof)); % subplot(2,2,3); % imshow(readimage(imds,porosity));
net = resnet50();
% figure % plot(net) % title('Architecture of ResNet-50') % set(gca, 'YLim', [150 170]);
net.Layers(1); net.Layers(end); numel(net.Layers(end).ClassNames); [trainingSet, testSet] = splitEachLabel(imds, 0.3 , 'randomize'); imageSize = net.Layers(1).InputSize; augmentedTrainingSet = augmentedImageDatastore(imageSize, ... trainingSet, 'ColorPreprocessing', 'gray2rgb'); augmentedTestSet = augmentedImageDatastore(imageSize, ... testSet, 'ColorPreprocessing', 'gray2rgb'); wl = net.Layers(2).Weights; wl = mat2gray(wl);
% figure % montage(wl) % title('First Convolutional Layer Weight');
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; confMat = confusionmat(testLabels, predictLabels); confMat = bsxfun(@rdivide, confMat, sum(confMat,2));
mean(diag(confMat));
newImage = imread(fullfile('test4.PNG'));
ds = augmentedImageDatastore(imageSize,... newImage, 'ColorPreprocessing', 'gray2rgb');
imageFeatures = activations(net, ... ds, featureLayer, 'MiniBatchSize', 32, 'OutputAs', 'columns');
label = predict(classifier, imageFeatures, 'ObservationsIn', 'columns');
sprintf('The loaded image belongs to %s class', label)
  1 个评论
Matt J
Matt J 2023-6-1
编辑:Matt J 2023-6-1
Your code is not readable. You need to repost it in this form,
a=1;
b=2;
c=3;
...

请先登录,再进行评论。

回答(0 个)

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by