Skip to content

Instantly share code, notes, and snippets.

@jjh42
Created April 20, 2020 23:28
Show Gist options
  • Save jjh42/d2b824e42e54e99dce5a84d387c88b8d to your computer and use it in GitHub Desktop.
Save jjh42/d2b824e42e54e99dce5a84d387c88b8d to your computer and use it in GitHub Desktop.
Recipe for converting some nested numpy (or similar structure) to tensorflow types.
example_tf = tf.nest.map_structure(
tf.nest.map_structure(tf.convert_to_tensor, example))
output_types = tf.nest.map_structure(lambda t: t.dtype, tf_example)
output_shapes = tf.nest.map_structure(tf.nest.map_structure(
lambda t: t.shape.as_list(), tf_example))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment