how can i make alexnet accept 277x277x1 images

i got error in example TransferLearningUsingAlexNetExample Error using trainNetwork (line 140) The training images are of size 227x227x1 but the input layer expects images of size 227x227x3. my dataset 277X277x1

3 Comments

you can use Software Faststone Image resizer
a=imread(' ');
l=alexnet;
a=imresize(a,[227 227]);
s=classify(l,a);
imshow(a);
try this.
How can I apply this to an DataSet. I have abaout 4000 Images I have to resize so it would take way to long to do this for every Image indevidually.

Sign in to comment.

 Accepted Answer

You can resize an image with the imresize function. Now since your images are of size 277x277x1 I will assume they are grayscale, but AlexNet was trained with RGB values and are thus 227x227x 3. It is not possible for you to recover color information from a grayscale image. You may be required to retrain the entire network with grayscale images.
I suggest for more questions on getting started with Deep Learning you check out the FREE Deep Learning OnRamp: https://matlabacademy.mathworks.com/

9 Comments

can i change the code to accept image of size 227 x 277 x 1 ??
Sure. But this would require retraining the entire network. This may take weeks to months depending on your hardware.
ya i need to retraining how can i do that ?
any fast tutorial can i follow it i use 2017b matlab
I completed the Alexnet Training with my dataset. How I can input an image and make the network predict it? I tried the code below.Butb it takes tha classnames of the pretrained network.Not the classnames that I newly created.
function img = imageread(file)
img=imread('D:\as.jpg');
% Resize to match AlexNet input
img = imresize(img,[227 227]);
% Convert grayscale to color (RGB)
img = repmat(img,[1 1 3]);
imds1 = imageDatastore(fullfile(matlabroot,'toolbox','matlab','images','New Folder'),...
'IncludeSubfolders',true,'ReadFcn',@imageread)
img=read(imds1)
imshow(img)
end
but it shows error in @imageread. is this code right?
Brendan Hamm
how can retraining ???
I suggest you consider converting your grayscale to RGB by taking
YourImage(:,:,[1 1 1])
or equivalently
repmat(YourImage, 1, 1, 3)
@abdo You can retrain by following the process in the doc:
You can also learn more through the both free and hands on training course Deep Learning Onramp. I highly recommend this approach if you are just getting started.
Thank you Brendan Hamm sir for recommending useful training course Deep Learning Onramp.
These days you should use an augmented image datastore as that can automatically resize and automatically convert to gray or rgb.

Sign in to comment.

More Answers (2)

how can i make [224 224 1] img size ?
The training images are of size 256x256x3 but the input layer expects images of size 224x224x3.
pls help me to solve this error

1 Comment

You can make an augmented datastore of the images that resizes them auomatically, while leaving your raw images the same

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!