function checkImageAndNetworkChannelSizes
Ältere Kommentare anzeigen
I'm using MATLAB R2019b and I'm trying to create a CNN model that takes grayscale images as input. However, I got the error in checkImageAndNetworkChannelSizes function even though both image channel size and network channel size are 1 because ndims(I) of grayscale image is 2 and therefore the first part of the conditional statement is true. Is this a bug? Is there a way to get around this? I try to add singleton dimension to my image but it seems to be ignored/dropped.
function checkImageAndNetworkChannelSizes(I, networkChannelSize)
% If the input image size has a different channel size than that of
% the network input size, we need to error.
[~, ~, Isize] = size(I);
if ndims(I) ~= 3 || Isize ~= networkChannelSize
error(message('vision:rcnn:invalidInputImageChannelSize', Isize, networkChannelSize));
end
Antworten (1)
Jyothis Gireesh
am 20 Nov. 2019
Here are a few pointers which may be of help:
- The function “ndims()” ignores all the trailing singleton dimensions of the input matrix. Hence it ignores the third singleton dimension and returns 2 when the input is a 2-D matrix.
- One possible workaround is to use the “permute()” function as follows:
if ndims(permute(I, [3 1 2])) ~= 3 || Isize ~= networkChannelSize
error(message('vision:rcnn:invalidInputImageChannelSize', Isize, networkChannelSize));
end
If “I" is of size m x n, the permute operation changes the size of the matrix to 1 x m x n and “ndims()” returns 3.
This method may create an error if “I” is a 4-D or higher dimensional matrix.
- Else you may include another “if” condition which checks whether “ndims(I)” is equal to 2 or not.
Hope this helps!!
2 Kommentare
Nicha
am 20 Nov. 2019
Jyothis Gireesh
am 20 Nov. 2019
It is not a recommended pratice to edit the contents of a MATLAB internal function.
The problem may be due to wrong arguments provided in the "imageInputLayer" or any other layers of the model. Could you attach the code so that I can take a look at it?
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!