Created
November 1, 2016 17:59
-
-
Save yaroslavvb/973862f62f35f174a4e8942bd7bd022e to your computer and use it in GitHub Desktop.
Example of wrapper for session.run that returns dictionaries instead of lists
This file contains hidden or 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
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