incorrect input size of image

23 views (last 30 days)
new_user
new_user on 21 Dec 2021
Commented: Image Analyst on 21 Dec 2021
images = imageDatastore('call', 'IncludeSubfolders',true, 'LabelSource','foldernames');
[Training_image, Validation_image] = splitEachLabel(images, 0.6); %split images in 75, 25% use 'randomized' also
Input_Layer_Size = net.Layers(1).InputSize(1:2); % (1:2 = 1st 2 elemnts of input size), input layer size stored in this variable (Input_layer_size)
Resized_Training_image = augmentedImageDatastore(Input_Layer_Size, Training_image, 'ColorPreprocessing','gray2rgb');
net = trainNetwork(Resized_Training_image, New_Network, Training_Options) % training the network
trainall=[]
for i=1:2200
i
a=readimage(Resized_Training_image,i);
[m n c]=size(a);m
Error using DAGNetwork/activations (line 262)
The spatial dimension sizes [169 300 3] of the input images to layer 'input_1' must be greater than or equal to the corresponding
minimum input dimension sizes of the layer [224 224 3].
%% what should i do to insert the resized taining image in the for loop operation.

Accepted Answer

Image Analyst
Image Analyst on 21 Dec 2021
Replace
a=readimage(Resized_Training_image,i);
[m n c]=size(a);m
with
rgbImage = readimage(Resized_Training_image, i);
[rows, columns, numberOfColorChannels] = size(rgbImage);
fprintf('Original image #%d has %d rows, %d columns, and %d color channels.\n', ...
i, rows, columns, numberOfColorChannels)
if rows ~= 224 || columns ~= 224
% Need to resize laterally to 224 by 224.
rgbImage = imresize(rgbImage, [224, 224]);
end
if numberOfColorChannels == 1
% It's gray scale. Need to convert to color.
rgbImage = ind2rgb(rgbImage, gray(256));
end
  3 Comments
Image Analyst
Image Analyst on 21 Dec 2021
I don't know. It's difficult for me to reproduce without your images and your folder structure. But the error is now in readimage() which comes before any of my resizing code, so the error lies in your code. Maybe try reading the image this way instead
fullFileName = images.Files{i};
a = imread(fullFileName);
and again I ask you to use descriptive filenames. No one like looking at code that is an alphabet soup of single letter variables. It's maybe not so bad with a very short program but once you get dozens of lines, it can get confusing knowing what each letter actually represents without searching back over the code.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!