Difference between tf.data.Dataset.map() and tf.data.Dataset.apply()

GPhilo picture GPhilo · Nov 3, 2017 · Viewed 10.4k times · Source

With the recent upgrade to version 1.4, Tensorflow included tf.data in the library core. One "major new feature" described in the version 1.4 release notes is tf.data.Dataset.apply(), which is a "method for applying custom transformation functions". How is this different from the already existing tf.data.Dataset.map()?

Answer

Sunreef picture Sunreef · Nov 3, 2017

The difference is that map will execute one function on every element of the Dataset separately, whereas apply will execute one function on the whole Dataset at once (such as group_by_window given as example in the documentation).

The argument of apply is a function that takes a Dataset and returns a Dataset when the argument of map is a function that takes one element and returns one transformed element.