tf.io.encode_proto  |  TensorFlow v2.16.1 (original) (raw)

The op serializes protobuf messages provided in the input tensors.

View aliases

Compat aliases for migration

SeeMigration guide for more details.

tf.compat.v1.io.encode_proto

tf.io.encode_proto(
    sizes: Annotated[Any, _atypes.Int32],
    values,
    field_names,
    message_type: str,
    descriptor_source: str = 'local://',
    name=None
) -> Annotated[Any, _atypes.String]

The types of the tensors in values must match the schema for the fields specified in field_names. All the tensors in values must have a common shape prefix, batch_shape.

The sizes tensor specifies repeat counts for each field. The repeat count (last dimension) of a each tensor in values must be greater than or equal to corresponding repeat count in sizes.

A message_type name must be provided to give context for the field names. The actual message descriptor can be looked up either in the linked-in descriptor pool or a filename provided by the caller using thedescriptor_source attribute.

For the most part, the mapping between Proto field types and TensorFlow dtypes is straightforward. However, there are a few special cases:

The descriptor_source attribute selects the source of protocol descriptors to consult when looking up message_type. This may be:

Args
sizes A Tensor of type int32. Tensor of int32 with shape [batch_shape, len(field_names)].
values A list of Tensor objects. List of tensors containing values for the corresponding field.
field_names A list of strings. List of strings containing proto field names.
message_type A string. Name of the proto message type to decode.
descriptor_source An optional string. Defaults to "local://".
name A name for the operation (optional).
Returns
A Tensor of type string.