One of the novelties of TensorFlow 2 is the possibility to aggregate some statistics regarding tf.data pipelines, such as their latency (for the whole process and/or for each operation) or the number of bytes produced by each of their elements.
TensorFlow can be notified to gather these metric values for a dataset through its global options (refer to previous paragraphs). The tf.data.Options instances have a .experimental_stats field from the tf.data.experimental.StatsOption class (refer to the documentation at https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/data/experimental/StatsOptions). This class defines several options related to the aforementioned dataset metrics (for instance, setting .latency_all_edges to True to measure the latency). It also has a .aggregator attribute, which can receive an instance of tf.data.experimental.StatsAggregator (refer to the documentation at https://www.tensorflow.org/versions/r2.0/api_docs/python/tf...