helpers.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:odin 作者: imito 项目源码 文件源码
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])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号