# Buggy code
def translate_xy(
    image: TensorLike, translate_to: TensorLike, replace: int
) -> TensorLike:
    """Translates image in X or Y dimension.

    Args:
        image: A 3D image `Tensor`.
        translate_to: A 1D `Tensor` to translate [x, y]
        replace: A one or three value 1D `Tensor` to fill empty pixels.
    Returns:
        Translated image along X or Y axis, with space outside image
            filled with replace.
    Raises:
        ValueError: if axis is neither 0 nor 1.
    """
    image = tf.convert_to_tensor(image)
    image = wrap(image)
    trans = tf.convert_to_tensor(translate_to)
    image = translate(image, [trans[0], trans[1]])
    return unwrap(image, replace)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-50c68fed8a6d> in <module>()
----> 1 sheared_image3 = tfa.image.shear_x(float_image, 0.3, replace=0.5)
2 sheared_image4 = tfa.image.shear_y(float_image, 0.4, replace=0.4)
3
4 plt.imshow(sheared_image3)
5 plt.show()

5 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_addons/image/transform_ops.py in shear_x(image, level, replace)
324     #  0  1].
325     image = transform(wrap(image), [1.0, level, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0])
--> 326     return unwrap(image, replace)
327
328

/usr/local/lib/python3.6/dist-packages/tensorflow_addons/image/utils.py in unwrap(image, replace)
135     alpha_channel = flattened_image[:, 3]
136
--> 137     replace = tf.constant(replace, tf.uint8)
138     if tf.rank(replace) == 0:
139         replace = tf.expand_dims(replace, 0)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name)
262   """
263   return _constant_impl(value, dtype, shape, name, verify_shape=False,
--> 264                         allow_broadcast=True)
265
266

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
273       with trace.Trace("tf.constant"):
274         return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
--> 275     return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
276
277   g = ops.get_default_graph()

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
298 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape):
299   """Implementation of eager constant."""
--> 300   t = convert_to_eager_tensor(value, ctx, dtype)
301   if shape is None:
302     return t

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
96       dtype = dtypes.as_dtype(dtype).as_datatype_enum
97   ctx.ensure_initialized()
---> 98   return ops.EagerTensor(value, ctx.device_name, dtype)
99
100

TypeError: Cannot convert 0.5 to EagerTensor of dtype uint8

# Fixed code
def translate_xy(
    image: TensorLike, translate_to: TensorLike, replace: TensorLike
) -> TensorLike:
    """Translates image in X or Y dimension.

    Args:
        image: A 3D image `Tensor`.
        translate_to: A 1D `Tensor` to translate `[x, y]`.
        replace: A one or three value 1D `Tensor` to fill empty pixels.
    Returns:
        Translated image along X or Y axis, with space outside image
            filled with replace.
    Raises:
        ValueError: if axis is neither 0 nor 1.
    """
    image = tf.convert_to_tensor(image)
    image = wrap(image)
    trans = tf.convert_to_tensor(translate_to)
    image = translate(image, [trans[0], trans[1]])
    return unwrap(image, replace)