keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 913 forks source link

Fix symbolic imagenet preprocessing #129

Closed lagejoao closed 2 years ago

lagejoao commented 5 years ago

Related with https://github.com/keras-team/keras-applications/issues/128

When input tensor is dtype='uint8' we are casting the mean_tensorto be uint8 and this is not the intended behaviour since we will be losing the floating point precision. Instead, we want to cast x (image tensor) to be float (floatx) so we can subtract the correct mean_tensor values.

Everyone working with explicit Tensor(dtype='uint8') and preprocessing images using preprocess_input will face a buggy channel mean subtraction.

lagejoao commented 5 years ago

@tanzhenyu looks like tests dont pass with the cntk backend. Any thoughts why?

lagejoao commented 4 years ago

@tanzhenyu @fchollet I trust keras will drop support for backends other than tf, but is it worthy to look into this meanwhile?

fchollet commented 4 years ago

What's the nature of the fix here?

lagejoao commented 4 years ago

What's the nature of the fix here?

@fchollet

Casting the mean_tensor to be uint8 is not the intended behaviour since we will be losing the floating point precision. Instead, we want to cast x (image tensor) to be float (floatx) so we can subtract the correct mean_tensor values.

Everyone working with explicit Tensor(dtype="uint8") and preprocessing images using preprocess_input will face a buggy channel mean subtraction.

lagejoao commented 4 years ago

@fchollet the PR title was a bit misleading. Added some comments and better description.

It is curious why cntk backend still fails with 66% assertion mismatch while other backends are OK 🤔