The training images are of size 2062x3545x3 but the input layer expects images of size 32x32x3.
6 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to train a D.L network with images with "2062x3545x3" of size (they are panchromatic). I follow the steps described in the "mathworks" as described bellow but I get this error: " The training images are of size 2062x3545x3 but the input layer expects images of size 32x32x3." So what I should do in order to train my network ? Many thanks.
numFilters = 64;
filterSize = 3;
numClasses = 2;
layers = [
imageInputLayer([32 32 3])
convolution2dLayer(filterSize,numFilters,'Padding',1)
reluLayer()
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(filterSize,numFilters,'Padding',1)
reluLayer()
transposedConv2dLayer(4,numFilters,'Stride',2,'Cropping',1);
convolution2dLayer(1,numClasses);
softmaxLayer()
pixelClassificationLayer()
]
opts = trainingOptions('sgdm', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',100, ...
'MiniBatchSize',64);
net = trainNetwork(trainingData,layers,opts);
3 个评论
arun anoop m
2020-7-19
I changed all images to 32x32 by the help of
picresize.com/en/batch
but still same error
Unexpected image size: All images must have the same size.
How can i solve?
Image Analyst
2020-7-19
Try my code below. Evidently not all of your images were of that size, or else you're trying to process a file that is not an image.
回答(1 个)
Image Analyst
2020-7-19
Below is a script I use to resize my images to 224 by 224 for Alex net. Adapt as needed.
% Resizes images to a size of 224x224, which AlexNet needs, and saves the resized images in a "Resized to 224x224" subfolder of the images folder.
% Image Analyst, March 21, 2020.
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
% Specify the folder where the files live.
inputImagesFolder = 'D:\whatever'; % Change it to whatever you need, if you want/need to.
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(inputImagesFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n\n%s\n\nPlease specify to an existing folder.', inputImagesFolder);
uiwait(warndlg(errorMessage));
% Try to find the highest level folder in that path that DOES exist.
while ~isfolder(inputImagesFolder) && length(inputImagesFolder) > 3
[inputImagesFolder, ~, ~] = fileparts(inputImagesFolder);
end
% Should have a good starting folder now.
inputImagesFolder = uigetdir(inputImagesFolder);
if inputImagesFolder == 0
return;
end
end
% Create output folder
outputImagesFolder = fullfile(inputImagesFolder, '/Resized to 224x224');
if ~isfolder(outputImagesFolder)
mkdir(outputImagesFolder);
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(inputImagesFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern)
numFiles = length(theFiles);
hFig = figure;
hFig.WindowState = 'maximized';
for k = 1 : numFiles
% Get the input file name.
baseFileName = theFiles(k).name;
fullFileName = fullfile(inputImagesFolder, baseFileName);
% Get the output file name.
outputFullFileName = fullfile(outputImagesFolder, baseFileName);
fprintf(1, 'Now reading %d of %d "%s"\n', k, numFiles, fullFileName);
% Read in input image with imread().
inputImage = imread(fullFileName);
% Resize it.
outputImage = imresize(inputImage, [224, 224]);
% Display input and output images.
subplot(1, 2, 1);
imshow(inputImage); % Display image.
caption = sprintf('Input image (%d of %d):\n"%s", %d by %d', k, numFiles, baseFileName, size(inputImage, 1), size(inputImage, 2));
title(caption, 'FontSize', fontSize, 'Interpreter', 'none');
subplot(1, 2, 2);
imshow(outputImage); % Display image.
caption = sprintf('Output image: "%s", %d by %d', baseFileName, size(outputImage, 1), size(outputImage, 2));
title(caption, 'FontSize', fontSize, 'Interpreter', 'none');
drawnow; % Force display to update immediately.
% Write out the resized output file to the output folder.
imwrite(outputImage, outputFullFileName);
end
fprintf('Done running %s.m.\n', mfilename);
% Open the output folder in File Explorer.
winopen(outputImagesFolder);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!