當前位置: 首頁>>代碼示例>>Python>>正文


Python ops.get_stats_for_node_def方法代碼示例

本文整理匯總了Python中tensorflow.python.framework.ops.get_stats_for_node_def方法的典型用法代碼示例。如果您正苦於以下問題:Python ops.get_stats_for_node_def方法的具體用法?Python ops.get_stats_for_node_def怎麽用?Python ops.get_stats_for_node_def使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.framework.ops的用法示例。


在下文中一共展示了ops.get_stats_for_node_def方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _flops

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def _flops(op):
  """Get the number of flops of a convolution, from the ops stats registry.

  Args:
    op: A tf.Operation object.

  Returns:
    The number os flops needed to evaluate conv_op.
  """
  return ops.get_stats_for_node_def(
      tf.get_default_graph(), op.node_def, 'flops').value 
開發者ID:google-research,項目名稱:morph-net,代碼行數:13,代碼來源:resource_function_test.py

示例2: testSimpleStatistics

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def testSimpleStatistics(self):
    g = tf.Graph()
    with g.as_default():
      a = tf.Variable(tf.random_normal([25, 16]))
      b = tf.Variable(tf.random_normal([16, 9]))
      tf.matmul(a, b)
      for op in g.get_operations():
        flops = ops.get_stats_for_node_def(g, op.node_def, "flops").value
        if op.name == "MatMul":
          self.assertEqual(7200, flops) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:12,代碼來源:matmul_op_test.py

示例3: testTransposedStatistics

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def testTransposedStatistics(self):
    g = tf.Graph()
    with g.as_default():
      a = tf.Variable(tf.random_normal([16, 25]))
      b = tf.Variable(tf.random_normal([16, 9]))
      tf.matmul(a, b, transpose_a=True)
      for op in g.get_operations():
        flops = ops.get_stats_for_node_def(g, op.node_def, "flops").value
        if op.name == "MatMul":
          self.assertEqual(7200, flops) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:12,代碼來源:matmul_op_test.py

示例4: testRegisteredNode

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def testRegisteredNode(self):
    graph = ops.Graph()
    node = ops._NodeDef("a", "an_a")
    flops = ops.get_stats_for_node_def(graph, node, "flops")
    self.assertEqual(20, flops.value)
    missing_stat = ops.get_stats_for_node_def(graph, node, "missing_stat")
    self.assertEqual(None, missing_stat.value) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:9,代碼來源:ops_test.py

示例5: testUnregisteredNode

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def testUnregisteredNode(self):
    graph = ops.Graph()
    node = ops._NodeDef("b", "a_b")
    weight_params = ops.get_stats_for_node_def(graph, node, "weight_params")
    self.assertEqual(None, weight_params.value) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:7,代碼來源:ops_test.py

示例6: _get_logged_ops

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def _get_logged_ops(graph, run_meta=None):
  """Extract trainable model parameters and FLOPs for ops from a Graph.

  Args:
    graph: tf.Graph.
    run_meta: RunMetadata proto used to complete shape information.
  Returns:
    logged_ops: dict mapping from op_name to OpLogEntry.
  """
  if run_meta:
    graph = _fill_missing_graph_shape(graph, run_meta)

  logged_ops = {}
  graph_def = graph.as_graph_def()
  for node in graph_def.node:
    try:
      stats = ops.get_stats_for_node_def(graph, node, REGISTERED_FLOP_STATS)
    except ValueError:
      # Catch Exception When shape is incomplete. Skip it.
      stats = None

    if not stats or not stats.value:
      continue
    if node.name not in logged_ops:
      entry = tfprof_log_pb2.OpLogEntry()
      entry.name = node.name
      entry.float_ops = int(stats.value)
      logged_ops[entry.name] = entry

  for v in graph.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES):
    if v.op.name not in logged_ops:
      entry = tfprof_log_pb2.OpLogEntry()
      entry.name = v.op.name
      entry.types.append(TRAINABLE_VARIABLES)
      logged_ops[entry.name] = entry
    else:
      logged_ops[v.op.name].types.append(TRAINABLE_VARIABLES)
  return logged_ops 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:40,代碼來源:tfprof_logger.py

示例7: calculate_graph_metrics

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def calculate_graph_metrics(graph_def, statistic_types, input_layer,
                            input_shape_override, batch_size):
  """Looks at the performance statistics of all nodes in the graph."""
  _ = tf.import_graph_def(graph_def, name="")
  total_stats = {}
  node_stats = {}
  for statistic_type in statistic_types:
    total_stats[statistic_type] = ops.OpStats(statistic_type)
    node_stats[statistic_type] = {}
  # Make sure we get pretty-printed numbers with separators.
  locale.setlocale(locale.LC_ALL, "")
  with tf.Session() as sess:
    input_tensor = sess.graph.get_tensor_by_name(input_layer)
    input_shape_tensor = input_tensor.get_shape()
    if input_shape_tensor:
      input_shape = input_shape_tensor.as_list()
    else:
      input_shape = None
    if input_shape_override:
      input_shape = input_shape_override
    if input_shape is None:
      raise ValueError("""No input shape was provided on the command line,"""
                       """ and the input op itself had no default shape, so"""
                       """ shape inference couldn't be performed. This is"""
                       """ required for metrics calculations.""")
    input_shape[0] = batch_size
    input_tensor.set_shape(input_shape)
    for node in graph_def.node:
      # Ensure that the updated input shape has been fully-propagated before we
      # ask for the statistics, since they may depend on the output size.
      op = sess.graph.get_operation_by_name(node.name)
      ops.set_shapes_for_outputs(op)
      for statistic_type in statistic_types:
        current_stats = ops.get_stats_for_node_def(sess.graph, node,
                                                   statistic_type)
        node_stats[statistic_type][node.name] = current_stats
        total_stats[statistic_type] += current_stats
  return total_stats, node_stats 
開發者ID:yselivonchyk,項目名稱:TensorFlow_DCIGN,代碼行數:40,代碼來源:graph_metrics.py

示例8: _flops

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def _flops(op):
  """Get the number of flops of a convolution, from the ops stats registry.

  Args:
    op: A tf.Operation object.

  Returns:
    The number os flops needed to evaluate conv_op.
  """
  return (ops.get_stats_for_node_def(tf.get_default_graph(), op.node_def,
                                     'flops').value) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:13,代碼來源:bilinear_cost_utils_test.py

示例9: _get_logged_ops

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def _get_logged_ops(graph, run_meta=None, add_trace=True):
  """Extract trainable model parameters and FLOPs for ops from a Graph.

  Args:
    graph: tf.Graph.
    run_meta: RunMetadata proto used to complete shape information.
    add_trace: Whether to add op trace information.
  Returns:
    logged_ops: dict mapping from op_name to OpLogEntry.
  """
  if run_meta:
    graph = _fill_missing_graph_shape(graph, run_meta)

  op_missing_shape = 0
  logged_ops = {}
  for op in graph.get_operations():
    try:
      stats = ops.get_stats_for_node_def(
          graph, op.node_def, REGISTERED_FLOP_STATS)
    except ValueError:
      # Catch Exception When shape is incomplete. Skip it.
      op_missing_shape += 1
      stats = None

    entry = tfprof_log_pb2.OpLogEntry()
    entry.name = op.name
    add_entry = False
    if stats and stats.value:
      entry.float_ops = int(stats.value)
      add_entry = True

    if add_trace:
      for tb in op.traceback:
        trace = entry.code_def.traces.add()
        trace.file = tb[0] if tb[0] else 'none'
        trace.lineno = tb[1] if tb[1] else -1
        trace.function = tb[2] if tb[2] else 'none'
        trace.line = tb[3] if tb[3] else 'none'
      add_entry = True

    if add_entry:
      logged_ops[entry.name] = entry

  for v in graph.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES):
    if v.op.name not in logged_ops:
      entry = tfprof_log_pb2.OpLogEntry()
      entry.name = v.op.name
      entry.types.append(TRAINABLE_VARIABLES)
      logged_ops[entry.name] = entry
    else:
      logged_ops[v.op.name].types.append(TRAINABLE_VARIABLES)
  if op_missing_shape > 0 and not run_meta:
    sys.stderr.write('%d ops no flops stats due to incomplete shapes. '
                     'Consider passing run_meta to use run_time shapes.\n' %
                     op_missing_shape)
  return logged_ops 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:58,代碼來源:tfprof_logger.py

示例10: _get_logged_ops

# 需要導入模塊: from tensorflow.python.framework import ops [as 別名]
# 或者: from tensorflow.python.framework.ops import get_stats_for_node_def [as 別名]
def _get_logged_ops(graph, run_meta=None):
  """Extract trainable model parameters and FLOPs for ops from a Graph.

  Args:
    graph: tf.Graph.
    run_meta: RunMetadata proto used to complete shape information.
  Returns:
    logged_ops: dict mapping from op_name to OpLogEntry.
  """
  if run_meta:
    graph = _fill_missing_graph_shape(graph, run_meta)

  op_missing_shape = 0
  logged_ops = {}
  graph_def = graph.as_graph_def()
  for node in graph_def.node:
    try:
      stats = ops.get_stats_for_node_def(graph, node, REGISTERED_FLOP_STATS)
    except ValueError:
      # Catch Exception When shape is incomplete. Skip it.
      op_missing_shape += 1
      stats = None

    if not stats or not stats.value:
      continue
    if node.name not in logged_ops:
      entry = tfprof_log_pb2.OpLogEntry()
      entry.name = node.name
      entry.float_ops = int(stats.value)
      logged_ops[entry.name] = entry

  for v in graph.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES):
    if v.op.name not in logged_ops:
      entry = tfprof_log_pb2.OpLogEntry()
      entry.name = v.op.name
      entry.types.append(TRAINABLE_VARIABLES)
      logged_ops[entry.name] = entry
    else:
      logged_ops[v.op.name].types.append(TRAINABLE_VARIABLES)
  if op_missing_shape > 0 and not run_meta:
    sys.stderr.write('%d ops no flops stats due to incomplete shapes. '
                     'Consider passing run_meta to use run_time shapes.\n' %
                     op_missing_shape)
  return logged_ops 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:46,代碼來源:tfprof_logger.py


注:本文中的tensorflow.python.framework.ops.get_stats_for_node_def方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。