tf.compat.as_bytes

Converts bytearray, bytes, or unicode python input types to bytes.

Used in the notebooks

Used in the tutorials

Uses utf-8 encoding for text by default.

bytes_or_textA bytearray, bytes, str, or unicode object.
encodingA string indicating the charset for encoding unicode.

A bytes object.

TypeErrorIf bytes_or_text is not a binary or unicode string.