tf.keras.quantizers.unpack_ternary

Unpack a base-3 packed uint8 tensor back to ternary {-1, 0, +1}.

This reverses pack_ternary, restoring an int8 tensor whose values are in {-1, 0, +1}. The original axis order is preserved and any padding added during packing is removed.

packed A uint8 tensor produced by pack_ternary, with five trits encoded in each byte along axis.
orig_len The original (unpadded) length of the packed axis, used to strip padding.
axis The axis along which the tensor was packed. Defaults to 0.

An int8 tensor with values in {-1, 0, +1} and the original (unpacked) shape along axis.

Example:

import numpy as np from keras.quantizers import pack_ternary, unpack_ternary trits = np.array([[1, -1, 0, 1, 1, -1]], dtype="int8") packed, _, orig_len = pack_ternary(trits, axis=1) np.asarray(unpack_ternary(packed, orig_len, axis=1)) array([[ 1, -1, 0, 1, 1, -1]], dtype=int8)