How to pass images to a cnn for analysis?

4 ビュー (過去 30 日間)
Teshan Rezel
Teshan Rezel 2020 年 1 月 31 日
コメント済み: Teshan Rezel 2020 年 2 月 6 日
Hi folks,
I'm not very familiar with matlab so apologies for the obvious question, but how can I pass an image to my cnn to be analysed?
My cnn's code is as follows:
AnisotropyDatasetPath = fullfile(matlabroot,'Training', 'Anisotropy');
IsotropyDatasetPath = fullfile(matlabroot,'Training', 'Isotropy');
FillerDatasetPath = fullfile(matlabroot,'Training', 'Filler');
TrainingDatasetPath = fullfile(matlabroot,'Training');
imds = imageDatastore(TrainingDatasetPath, 'IncludeSubfolders',true,...
'LabelSource','foldernames');
labelCount = countEachLabel(imds)
numTrainFiles = 999;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');
layers = [
imageInputLayer([227 227 3])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(3)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation)
thanks!

採用された回答

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020 年 2 月 3 日
Hey Teshan,
After you train a neural network for deep learning using trainNetwork into net, follow this procedure:
  • Use the function augmentedImageDatastore for effective preprocessing of the images
  • Use the activations function to compute the DL Network layer activations i.e. the image features using the CNN net
  • Use the predict function to finally make a prediction using the classifier
The overall workflow that I mentioned is available in this example as well.
Hope this helps!
  1 件のコメント
Teshan Rezel
Teshan Rezel 2020 年 2 月 6 日
thanks Vinai, this was really helpful!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by