Effacer les filtres
Effacer les filtres

how to make the same image size ?

1 vue (au cours des 30 derniers jours)
Mohamed Nasr
Mohamed Nasr le 28 Avr 2020
Réponse apportée : Sanyam le 13 Juil 2022
clear all;
clc;
close all;
imds = imageDatastore('D:\matlab aml\dataset1','FileExtensions',{'.jpg'},'IncludeSubfolders',true,'LabelSource','foldernames');
imgs = readall(imds);
figure;
perm = randperm(200,20);%Display some of the images in the datastore.
for i = 1:20
subplot(4,5,i);
imshow(imds.Files{perm(i)});
end
img = readimage(imds,1); %Check the size of the first image in digitData. Each image is 201-by-173-by-3 pixels.
size(img)
%Specify Training and Validation Sets
labelCount = countEachLabel(imds) %Calculate the number of images in each category
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);%Divide the data into training and validation data sets. Use 70% of the images for training and 30% for validation.
%Define the convolutional neural network architecture.
%%%%%%%code for resizing
inputSize=[227 227 1];
imdsTrain=augmentedImageDatastore(inputSize, imdsTrain,'ColorPreprocessing','RGB');
imdsValidation=augmentedImageDatastore(inputSize, imdsValidation,'ColorPreprocessing','RGB');
layers = [
imageInputLayer([227 227 1])
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(2)
softmaxLayer
classificationLayer];
%Specify Training Options
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
%Train Network Using Training Data
net = trainNetwork(imdsTrain,layers,options);
%Classify Validation Images and Compute Accuracy
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation)
this is my code and error is
ans =
201 173 3
labelCount =
2×2 table
Label Count
_____ _____
no 91
yes 154
Unrecognized method, property, or field 'Labels' for class 'augmentedImageDatastore'.
Error in ccn (line 59)
YValidation = imdsValidation.Labels;

Réponses (1)

Sanyam
Sanyam le 13 Juil 2022
The imdsValidation in your code is an augmentedImageDatastore, it is used to apply transformations to imageDatastore and does not have a 'labels' field.
Instead, you can proceed in this manner.
//refer to code
Here we have seperated the imageDatastore and augmentedImageDatastore and we can access the labels by
YValidation = imdsValidation.Labels; i.e referring the labels field of imageDataStore.
Also, when training the model and making predictions, please use the newly created augmentedImageDatastores (augdsTrain, augdsValidation).
Hope that helps! Thanks!!
[imdsTrain imdsValidation] = splitEachLabel(imds,0.7);
augdsTrain=augmentedImageDatastore(inputSize, imdsTrain,'ColorPreprocessing','RGB');
augdsValidation=augmentedImageDatastore(inputSize, imdsValidation,'ColorPreprocessing','RGB');

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by