Skip to content

Instantly share code, notes, and snippets.

@yaroslavvb
Created November 1, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaroslavvb/973862f62f35f174a4e8942bd7bd022e to your computer and use it in GitHub Desktop.
Save yaroslavvb/973862f62f35f174a4e8942bd7bd022e to your computer and use it in GitHub Desktop.
Example of wrapper for session.run that returns dictionaries instead of lists
def sessrun(fetches):
values = tf.get_default_session().run(fetches)
return {fetches[i]: values[i] for i in range(len(values))}
a = tf.constant(1)
b = tf.constant(2)
c = tf.constant(3)
sess = tf.InteractiveSession()
result1 = sessrun([a, b])
print(result1[a], result1[b]) # => 1 2
result2 = sessrun([a, b, c])
print(result2[a], result2[b], result2[c]) # => 1 2 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment