Нет встроенной функции (о которой я знаю), но ее легко сделать:
# Setup a graph
import tensorflow as tf
placeholder0 = tf.placeholder(tf.float32, [])
placeholder1 = tf.placeholder(tf.float32, [])
constant0 = tf.constant(2.0)
sum0 = tf.add(placeholder0, constant0)
sum1 = tf.add(placeholder1, sum0)
# Function to get *all* dependencies of a tensor.
def get_dependencies(tensor):
dependencies = set()
dependencies.update(tensor.op.inputs)
for sub_op in tensor.op.inputs:
dependencies.update(get_dependencies(sub_op))
return dependencies
print(get_dependencies(sum0))
print(get_dependencies(sum1))
# Filter on type to get placeholders.
print([tensor for tensor in get_dependencies(sum0) if tensor.op.type == 'Placeholder'])
print([tensor for tensor in get_dependencies(sum1) if tensor.op.type == 'Placeholder'])
Конечно, вы также можете включить фильтрацию заполнителя в функцию.