tf.keras.quantizers.unpack_int2

Unpack a packed int2 tensor back to an int8 tensor.

This reverses pack_int2, restoring the original tensor whose values lie in [-2, 1] (signed) or [0, 3] (unsigned) from a packed tensor where each byte stores four int2 values. It restores the original axis order and removes any padding that was added during packing.

packed An int8 or uint8 tensor with four int2 values per element along the specified axis.
orig_len The original (unpadded) length of the packed axis. Used to trim the padding inserted during packing.
axis The axis along which the tensor was packed. Defaults to 0.
dtype The data type of the input and unpacked tensor. Can be "int8" or "uint8". Defaults to "int8".

unpacked A tensor with the same shape as the original (unpacked) tensor.

Example:

import numpy as np from keras.quantizers import pack_int2, unpack_int2 codes = np.array([[-2, 1, 0, -1, 1]], dtype="int8") packed, _, orig_len = pack_int2(codes, axis=1) np.asarray(unpack_int2(packed, orig_len, axis=1)) array([[-2, 1, 0, -1, 1]], dtype=int8)