Last active
March 1, 2021 07:32
-
-
Save kretes/02dc479ab7a63a8b5a559c5e7df89598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [7]: import numpy as np | |
...: import tensorflow as tf | |
...: print(tf.version.GIT_VERSION, tf.version.VERSION) | |
...: | |
...: dim = 300 | |
...: | |
...: def return_single(*args): | |
...: x = np.random.rand(dim,dim,dim) | |
...: return x,1 | |
...: | |
...: def return_list(*args): | |
...: x = np.random.rand(dim,dim,dim) | |
...: return [x], [1] | |
...: | |
...: def return_nd(*args): | |
...: x = np.random.rand(dim,dim,dim) | |
...: return np.array([x]), np.array([1]) | |
...: | |
...: def make_ds(fun): | |
...: the_ds = tf.data.Dataset.range(5) | |
...: the_ds = the_ds.map( | |
...: lambda fn: tf.py_function( | |
...: fun, [fn], | |
...: [tf.float32,tf.float32] | |
...: ) | |
...: ) | |
...: return the_ds | |
...: | |
v2.4.0-49-g85c8b2a817f 2.4.1 | |
In [8]: %%time | |
...: for _ in make_ds(return_single): | |
...: pass | |
...: | |
CPU times: user 1.02 s, sys: 435 ms, total: 1.46 s | |
Wall time: 1.46 s | |
In [9]: %%time | |
...: for _ in make_ds(return_nd): | |
...: pass | |
...: | |
CPU times: user 1.2 s, sys: 850 ms, total: 2.05 s | |
Wall time: 2.06 s | |
In [10]: %%time | |
...: for _ in make_ds(return_list): | |
...: pass | |
...: | |
CPU times: user 11.4 s, sys: 345 ms, total: 11.7 s | |
Wall time: 11.7 s | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
print(tf.version.GIT_VERSION, tf.version.VERSION) | |
dim = 300 | |
def return_single(*args): | |
x = np.random.rand(dim,dim,dim) | |
return x,1 | |
def return_list(*args): | |
x = np.random.rand(dim,dim,dim) | |
return [x], [1] | |
def return_nd(*args): | |
x = np.random.rand(dim,dim,dim) | |
return np.array([x]), np.array([1]) | |
def make_ds(fun): | |
the_ds = tf.data.Dataset.range(5) | |
the_ds = the_ds.map( | |
lambda fn: tf.py_function( | |
fun, [fn], | |
[tf.float32,tf.float32] | |
) | |
) | |
return the_ds | |
%%time | |
for _ in make_ds(return_single): | |
pass | |
%%time | |
for _ in make_ds(return_nd): | |
pass | |
%%time | |
for _ in make_ds(return_list): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment