keras-unet icon indicating copy to clipboard operation
keras-unet copied to clipboard

IoU smooth parameters incompatible with input being np.uint8

Open maxpv opened this issue 4 years ago • 1 comments

Thanks again for this nice package.

JFYI, I've noticed an issue while using metrics.iou when the input is np.uint8 and the smooth parameter is a float -by default:

import numpy as np
from keras_unet.metrics import iou

tshape = (30, 50)

input = np.zeros(tshape, dtype=np.uint8)

iou(input, input, smooth=1.).numpy()
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
   6841   message = e.message + (" name: " + name if name is not None else "")
   6842   # pylint: disable=protected-access
-> 6843   six.raise_from(core._status_to_exception(e.code, message), None)
   6844   # pylint: enable=protected-access
   6845 

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: cannot compute AddV2 as input #1(zero-based) was expected to be a uint8 tensor but is a float tensor [Op:AddV2]iou

To sum up:

  • Input np.uint8 with smooth type float generates an error
  • Input np.uint8 with smooth type np.uint8 generates works
  • Input np.float32 with smooth type float/np.uint8 works

maxpv avatar Dec 09 '20 16:12 maxpv

Hi @maxpv Good catch! Seems to be a mistake indeed.

karolzak avatar Dec 17 '20 08:12 karolzak