Is there an alternative to tf.py_function() for custom Python code?

前端 未结 1 1108
傲寒
傲寒 2020-12-12 03:02

I have started using TensorFlow 2.0 and have a little uncertainty with regard to one aspect.

Suppose I have this use case: while ingesting data with the tf.dat

相关标签:
1条回答
  • 2020-12-12 03:37

    There is no other way of doing it, because tf.data.Datasets are still (and they will always be, I suppose, for performance reasons) executed in graph mode and, thus, you cannot use anything outside of the tf.* methods, that can be easily converted by TensorFlow to its graph representation.

    Using tf.py_function is the only way to mix Python execution (and thus, you can use any Python library) and graph execution when using a tf.data.Dataset object (on the contrary of what happens when using TensorFlow 2.0, that being eager by default allow this mixed execution naturally).

    0 讨论(0)
提交回复
热议问题