Parses `Example` protos into a `dict` of tensors. Parses a number of serialized [`Example`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto) protos given in `serialized`. We refer to `serialized` as a batch with `batch_size` many entries of individual `Example` protos.
(serialized, features, example_names=None, name=None)
| 583 | |
| 584 | @tf_export("io.parse_example", v1=[]) |
| 585 | def parse_example_v2(serialized, features, example_names=None, name=None): |
| 586 | # pylint: disable=line-too-long |
| 587 | """Parses `Example` protos into a `dict` of tensors. |
| 588 | |
| 589 | Parses a number of serialized [`Example`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto) |
| 590 | protos given in `serialized`. We refer to `serialized` as a batch with |
| 591 | `batch_size` many entries of individual `Example` protos. |
| 592 | |
| 593 | `example_names` may contain descriptive names for the corresponding serialized |
| 594 | protos. These may be useful for debugging purposes, but they have no effect on |
| 595 | the output. If not `None`, `example_names` must be the same length as |
| 596 | `serialized`. |
| 597 | |
| 598 | This op parses serialized examples into a dictionary mapping keys to `Tensor` |
| 599 | and `SparseTensor` objects. `features` is a dict from keys to `VarLenFeature`, |
| 600 | `SparseFeature`, and `FixedLenFeature` objects. Each `VarLenFeature` |
| 601 | and `SparseFeature` is mapped to a `SparseTensor`, and each |
| 602 | `FixedLenFeature` is mapped to a `Tensor`. |
| 603 | |
| 604 | Each `VarLenFeature` maps to a `SparseTensor` of the specified type |
| 605 | representing a ragged matrix. Its indices are `[batch, index]` where `batch` |
| 606 | identifies the example in `serialized`, and `index` is the value's index in |
| 607 | the list of values associated with that feature and example. |
| 608 | |
| 609 | Each `SparseFeature` maps to a `SparseTensor` of the specified type |
| 610 | representing a Tensor of `dense_shape` `[batch_size] + SparseFeature.size`. |
| 611 | Its `values` come from the feature in the examples with key `value_key`. |
| 612 | A `values[i]` comes from a position `k` in the feature of an example at batch |
| 613 | entry `batch`. This positional information is recorded in `indices[i]` as |
| 614 | `[batch, index_0, index_1, ...]` where `index_j` is the `k-th` value of |
| 615 | the feature in the example at with key `SparseFeature.index_key[j]`. |
| 616 | In other words, we split the indices (except the first index indicating the |
| 617 | batch entry) of a `SparseTensor` by dimension into different features of the |
| 618 | `Example`. Due to its complexity a `VarLenFeature` should be preferred over a |
| 619 | `SparseFeature` whenever possible. |
| 620 | |
| 621 | Each `FixedLenFeature` `df` maps to a `Tensor` of the specified type (or |
| 622 | `tf.float32` if not specified) and shape `(serialized.size(),) + df.shape`. |
| 623 | |
| 624 | `FixedLenFeature` entries with a `default_value` are optional. With no default |
| 625 | value, we will fail if that `Feature` is missing from any example in |
| 626 | `serialized`. |
| 627 | |
| 628 | Each `FixedLenSequenceFeature` `df` maps to a `Tensor` of the specified type |
| 629 | (or `tf.float32` if not specified) and shape |
| 630 | `(serialized.size(), None) + df.shape`. |
| 631 | All examples in `serialized` will be padded with `default_value` along the |
| 632 | second dimension. |
| 633 | |
| 634 | Examples: |
| 635 | |
| 636 | For example, if one expects a `tf.float32` `VarLenFeature` `ft` and three |
| 637 | serialized `Example`s are provided: |
| 638 | |
| 639 | ``` |
| 640 | serialized = [ |
| 641 | features |
| 642 | { feature { key: "ft" value { float_list { value: [1.0, 2.0] } } } }, |
no test coverage detected