<br />

> [!NOTE]
> **Note:** This API is new and only available via `pip install tf-nightly`.

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/master/keras/src/quantizers/packing.py#L295-L331) |

Unpack a packed int2 tensor back to an int8 tensor.

    tf.keras.quantizers.unpack_int2(
        packed, orig_len, axis=0, dtype='int8'
    )

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.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `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"`. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `unpacked` | A tensor with the same shape as the original (unpacked) tensor. |

<br />

#### 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)

```python

```