def get_operation_footprint(op):
""" Trace back the inputs of given Op and record all:
* placholders
* variables
* ops
Those are related to given op.
The final footprint is concatenated string of all variables,
placeholders, constants, and Ops
Note
----
This is just a fair attempt to create short identification of a
tenorflow Op
"""
if not isinstance(op, tf.Operation) and hasattr(op, 'op'):
op = op.op
var = []
placeholder = []
const = []
ops = [op.type]
inputs = list(op._inputs)
while len(inputs) > 0:
i = inputs.pop()
o = i.op
ops.append(o.type)
if o.type == "VariableV2":
var.append(i)
elif o.type == "Placeholder":
placeholder.append(i)
elif o.type == "Const":
const.append(i)
inputs = list(o._inputs) + inputs
return ':'.join([get_normalized_name(v) for v in var]) + '|' +\
':'.join([get_normalized_name(p) for p in placeholder]) + '|' +\
':'.join([get_normalized_name(c) for c in const]) + '|' +\
':'.join([j.split(':')[0] for j in ops])
评论列表
文章目录