function checkImage​AndNetwork​ChannelSiz​es

조회 수: 2 (최근 30일)
Nicha
Nicha 2019년 11월 17일
댓글: Jyothis Gireesh 2019년 11월 20일
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

답변 (1개)

Jyothis Gireesh
Jyothis Gireesh 2019년 11월 20일
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
Nicha
Nicha 2019년 11월 20일
Those are great answers! May I ask how and if I can change this internal function? MATLAB didn't allow me to change and save it when I tried.
Jyothis Gireesh
Jyothis Gireesh 2019년 11월 20일
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?

댓글을 달려면 로그인하십시오.

카테고리

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