[Python] What is the Keras 3 version of this numpy function of this IEEE754 to Unsigned...

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    Using the Keras 3 ops api, what is the Keras 3 version of this normalization function?

    def ieee754_to_uint8(x, axis=-1):
    """
    Normalize a tensor using IEEE 754 logic and map it to uint8 values.

    Args:
    x (tensor): A Keras tensor of shape (batch_size, seq_len).
    axis (int): Axis along which to normalize.

    Returns:
    A Keras tensor with dtype uint8, returning the same shape as input x.
    """
    # Find the maximum absolute value in x
    m = np.max(np.abs(x), axis=axis, keepdims=True)
    m[m==0] = 1

    y = (2**7 - 1 * (x > 0)) * x / m
    return (y.astype(int) + 128).astype(np.uint8)

    Continue reading...

Compartilhe esta Página