Support string tensors for tf.count_nonzero
This fix tries to address the issue raised in 18712 where
`tf.count_nonzero` does not support string tensors.
The implementation of `tf.count_nonzero` relies on `tf.not_equal`
which actually support string tensors. The reason the string
tensor does not work is because `tf.count_nonzero` created
a numpy type `zero` which uses `input_tensor.dtype.as_numpy_dtype()`.
The numpy type `zero` is then passed to `tf.not_equal (which converts
numpy `zero` into a tensor zero). However,
`input_tensor.dtype.as_numpy_dtype()` will converts tf.string to
numpy.object thus the exception.
But that is not necessary as `zero` could be created
with `tf.zeros` directly without back and forth conversion
to numpy.
This fix fixes the issue.
This fix fixes 18712.
Signed-off-by:
Yong Tang <yong.tang.github@outlook.com>
Loading
Please sign in to comment