tf.tuple
Stay organized with collections
Save and categorize content based on your preferences.
Groups tensors together.
tf . tuple (
tensors , control_inputs = None , name = None
)
The returned tensors have the same value as the input tensors, but they
are computed only after all the input tensors have been computed.
Note: In TensorFlow 2 with eager and/or Autograph, you should not require
this method, as ops execute in the expected order thanks to automatic control
dependencies. Only use tf.tuple
when working with v1 tf.Graph
code.
See also tf.group
and tf.control_dependencies
.
Example:
with tf . Graph () . as_default ():
with tf . compat . v1 . Session () as sess :
v = tf . Variable ( 0.0 )
a = tf . constant ( 1.0 )
sess . run ( tf . compat . v1 . global_variables_initializer ())
for i in range ( 5 ):
update_op = v . assign_add ( 1.0 )
b = a + v
res_b = sess . run ( b )
res_v = sess . run ( v )
print ( res_v )
0.0
0.0
0.0
0.0
0.0
with tf . Graph () . as_default ():
with tf . compat . v1 . Session () as sess :
v = tf . Variable ( 0.0 )
a = tf . constant ( 1.0 )
sess . run ( tf . compat . v1 . global_variables_initializer ())
for i in range ( 5 ):
update_op = v . assign_add ( 1.0 )
calc = [ a + v ]
# `tf.tuple` ensures `update_op` is run before `b`
b = tf . tuple ( calc , [ tf . group ( update_op )])
res_b = sess . run ( b )
res_v = sess . run ( v )
print ( res_v )
1.0
2.0
3.0
4.0
5.0
Args
tensors
A list of Tensor
s or IndexedSlices
, some entries can be None
.
control_inputs
List of additional ops to finish before returning.
name
(optional) A name to use as a name_scope
for the operation.
Raises
ValueError
If tensors
does not contain any Tensor
or IndexedSlices
.
TypeError
If control_inputs
is not a list of Operation
or Tensor
objects.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license .
Last updated 2024-04-26 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-04-26 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."]]