Ho do I change my dataset of images to the same size?

3 ビュー (過去 30 日間)
Abdulaziz Alotaibi
Abdulaziz Alotaibi 2021 年 2 月 18 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 18 日
Hello everyone,
I'm building a CNN model, but first I would like to control the images saiz
since all the dataset images aize are 40*24*1 , and I would like to change it to like 100*60*1
How do I do that ?
this is my code:
clear;
clc;
outputFolder = fullfile("binary_dataset");
rootFolder = fullfile(outputFolder, "Categories");
categories = {'Anomaly','No-Anomaly'}; % names of the folders
imds = imageDatastore(fullfile(rootFolder,categories),'LabelSource','foldernames');
tbl = countEachLabel(imds);
[imdsTrain,imdsValidation] = splitEachLabel(imds, 0.8, 'randomize');
inputSize = [40 24 1];
numClasses = 2;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(5,20,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(5,20,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(5,20,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',1, ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
accuracy = mean(YPred == YValidation)

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 18 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 18 日
Steps:
  • Call the images one by one
  • Do resize
  • Save in the different folder
Later use those folder images (resize images) in CNN
  2 件のコメント
Abdulaziz Alotaibi
Abdulaziz Alotaibi 2021 年 2 月 18 日
編集済み: Abdulaziz Alotaibi 2021 年 2 月 18 日
I Used the following Code and worked for me!
Thank you.
srcFiles = dir('E:\img\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('E:\img\',srcFiles(i).name);
im = imread(filename);
k=imresize(im,[300,300]);
newfilename=strcat('E:\img\',srcFiles(i).name);
imwrite(k,newfilename,'jpg');
end
I got this code from here:
https://www.mathworks.com/matlabcentral/answers/314902-how-to-store-resize-images-into-new-directory
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 18 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 18 日
:) Welcome

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by