Conv function error condition
tataganesh opened this issue · 1 comments
tataganesh commented
Hi Ahmed,
if len(img.shape) > 2 or len(conv_filter.shape) > 3: # Check if number of image channels matches the filter depth.
if img.shape[-1] != conv_filter.shape[-1]:
print("Error: Number of channels in both image and filter must match.")
sys.exit()
The above snippet in the conv function checks for channel mismatch. But, if len(img.shape)
is greater than 2 (eg - (224, 224, 3)), and the conv_filter's shape is (2,3,3)
, then the condition if img.shape[-1] != conv_filter.shape[-1]
is False
, even though the number of channels of the image, and the conv_filter, are not the same.
One possible solution is -
if len(img.shape) != len(conv_filter.shape) - 1: # Check whether number of dimensions is the same
print("Error: Number of dimensions in conv filter and image do not match.")
exit()
if len(img.shape) > 2 or len(conv_filter.shape) > 3: # Check if number of image channels matches the filter depth.
if img.shape[-1] != conv_filter.shape[-1]:
print("Error: Number of channels in both image and filter must match.")
sys.exit()
ahmedfgad commented
Hi,
Thanks too much for your edit. I followed your idea and it is completely right. I will modify the project accordingly.