MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / parse_example

Function parse_example

tensorflow/python/ops/parsing_ops.py:368–581  ·  view source on GitHub ↗

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, name=None, example_names=None)

Source from the content-addressed store, hash-verified

366
367@tf_export(v1=["io.parse_example", "parse_example"])
368def parse_example(serialized, features, name=None, example_names=None):
369 # pylint: disable=line-too-long
370 """Parses `Example` protos into a `dict` of tensors.
371
372 Parses a number of serialized [`Example`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto)
373 protos given in `serialized`. We refer to `serialized` as a batch with
374 `batch_size` many entries of individual `Example` protos.
375
376 `example_names` may contain descriptive names for the corresponding serialized
377 protos. These may be useful for debugging purposes, but they have no effect on
378 the output. If not `None`, `example_names` must be the same length as
379 `serialized`.
380
381 This op parses serialized examples into a dictionary mapping keys to `Tensor`
382 and `SparseTensor` objects. `features` is a dict from keys to `VarLenFeature`,
383 `SparseFeature`, and `FixedLenFeature` objects. Each `VarLenFeature`
384 and `SparseFeature` is mapped to a `SparseTensor`, and each
385 `FixedLenFeature` is mapped to a `Tensor`.
386
387 Each `VarLenFeature` maps to a `SparseTensor` of the specified type
388 representing a ragged matrix. Its indices are `[batch, index]` where `batch`
389 identifies the example in `serialized`, and `index` is the value's index in
390 the list of values associated with that feature and example.
391
392 Each `SparseFeature` maps to a `SparseTensor` of the specified type
393 representing a Tensor of `dense_shape` `[batch_size] + SparseFeature.size`.
394 Its `values` come from the feature in the examples with key `value_key`.
395 A `values[i]` comes from a position `k` in the feature of an example at batch
396 entry `batch`. This positional information is recorded in `indices[i]` as
397 `[batch, index_0, index_1, ...]` where `index_j` is the `k-th` value of
398 the feature in the example at with key `SparseFeature.index_key[j]`.
399 In other words, we split the indices (except the first index indicating the
400 batch entry) of a `SparseTensor` by dimension into different features of the
401 `Example`. Due to its complexity a `VarLenFeature` should be preferred over a
402 `SparseFeature` whenever possible.
403
404 Each `FixedLenFeature` `df` maps to a `Tensor` of the specified type (or
405 `tf.float32` if not specified) and shape `(serialized.size(),) + df.shape`.
406
407 `FixedLenFeature` entries with a `default_value` are optional. With no default
408 value, we will fail if that `Feature` is missing from any example in
409 `serialized`.
410
411 Each `FixedLenSequenceFeature` `df` maps to a `Tensor` of the specified type
412 (or `tf.float32` if not specified) and shape
413 `(serialized.size(), None) + df.shape`.
414 All examples in `serialized` will be padded with `default_value` along the
415 second dimension.
416
417 Examples:
418
419 For example, if one expects a `tf.float32` `VarLenFeature` `ft` and three
420 serialized `Example`s are provided:
421
422 ```
423 serialized = [
424 features
425 { feature { key: "ft" value { float_list { value: [1.0, 2.0] } } } },

Callers

nothing calls this directly

Calls 1

parse_example_v2Function · 0.85

Tested by

no test coverage detected