How can I use images which have different size for CNN?

조회 수: 22 (최근 30일)
Ersad Mert Mutlu
Ersad Mert Mutlu 2022년 2월 20일
댓글: Ersad Mert Mutlu 2022년 2월 20일
Hello everyone,
I have prepared a neural network and I need to test it now but my dataset has images that have different sizes. How can I use all of them even they have different size?

채택된 답변

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2022년 2월 20일
except some special cases, there is a limitation for forwarding different size arrays toward a CNN. after images pass the convolutional layers each one lead to an array with different size. and because of fully connected layers at end of network it is not possible to work with different size array. ( they should work with input with certain size)
so you should convert them to certain size for this network. and there is a fast method to do so:
input_size = Net.Layers(1).InputSize;
images_folder_path = 'E:\images'; % the folder contain all images
image_database = imageDatastore(images_folder_path);
image_database = transform(image_database,,@(x) (imresize(x,input_size(1:2))));
after this, you can pass this datastore to network all in once. for example with classification:
Output = classify(Net,image_database);
if not, select one by one and pass it through the network:
I = image_database.read;
y = classify(Net,I);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by