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


Python logging_ops.Print方法代碼示例

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


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

示例1: add_image_summary

# 需要導入模塊: from tensorflow.python.ops import logging_ops [as 別名]
# 或者: from tensorflow.python.ops.logging_ops import Print [as 別名]
def add_image_summary(tensor, name=None, prefix=None, print_summary=False):
  """Adds an image summary for the given tensor.

  Args:
    tensor: a variable or op tensor with shape [batch,height,width,channels]
    name: the optional name for the summary.
    prefix: An optional prefix for the summary names.
    print_summary: If `True`, the summary is printed to stdout when the summary
      is computed.

  Returns:
    An image `Tensor` of type `string` whose contents are the serialized
    `Summary` protocol buffer.
  """
  summary_name = _get_summary_name(tensor, name, prefix)
  # If print_summary, then we need to make sure that this call doesn't add the
  # non-printing op to the collection. We'll add it to the collection later.
  collections = [] if print_summary else None
  op = summary.image(
      name=summary_name, tensor=tensor, collections=collections)
  if print_summary:
    op = logging_ops.Print(op, [tensor], summary_name)
    ops.add_to_collection(ops.GraphKeys.SUMMARIES, op)
  return op 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:26,代碼來源:summaries.py

示例2: add_scalar_summary

# 需要導入模塊: from tensorflow.python.ops import logging_ops [as 別名]
# 或者: from tensorflow.python.ops.logging_ops import Print [as 別名]
def add_scalar_summary(tensor, name=None, prefix=None, print_summary=False):
  """Adds a scalar summary for the given tensor.

  Args:
    tensor: a variable or op tensor.
    name: the optional name for the summary.
    prefix: An optional prefix for the summary names.
    print_summary: If `True`, the summary is printed to stdout when the summary
      is computed.

  Returns:
    A scalar `Tensor` of type `string` whose contents are the serialized
    `Summary` protocol buffer.
  """
  collections = [] if print_summary else None
  summary_name = _get_summary_name(tensor, name, prefix)

  # If print_summary, then we need to make sure that this call doesn't add the
  # non-printing op to the collection. We'll add it to the collection later.
  op = summary.scalar(
      name=summary_name, tensor=tensor, collections=collections)
  if print_summary:
    op = logging_ops.Print(op, [tensor], summary_name)
    ops.add_to_collection(ops.GraphKeys.SUMMARIES, op)
  return op 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:27,代碼來源:summaries.py

示例3: print_tensor

# 需要導入模塊: from tensorflow.python.ops import logging_ops [as 別名]
# 或者: from tensorflow.python.ops.logging_ops import Print [as 別名]
def print_tensor(x, message=''):
  """Prints `message` and the tensor value when evaluated.

  Arguments:
      x: Tensor to print.
      message: Message to print jointly with the tensor.

  Returns:
      The same tensor `x`, unchanged.
  """
  return logging_ops.Print(x, [x], message)


# GRAPH MANIPULATION 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:16,代碼來源:backend.py

示例4: npairs_loss

# 需要導入模塊: from tensorflow.python.ops import logging_ops [as 別名]
# 或者: from tensorflow.python.ops.logging_ops import Print [as 別名]
def npairs_loss(labels, embeddings_anchor, embeddings_positive,
                reg_lambda=0.002, print_losses=False):
  """Computes the npairs loss.

  Npairs loss expects paired data where a pair is composed of samples from the
  same labels and each pairs in the minibatch have different labels. The loss
  has two components. The first component is the L2 regularizer on the
  embedding vectors. The second component is the sum of cross entropy loss
  which takes each row of the pair-wise similarity matrix as logits and
  the remapped one-hot labels as labels.

  See: http://www.nec-labs.com/uploads/images/Department-Images/MediaAnalytics/papers/nips16_npairmetriclearning.pdf

  Args:
    labels: 1-D tf.int32 `Tensor` of shape [batch_size/2].
    embeddings_anchor: 2-D Tensor of shape [batch_size/2, embedding_dim] for the
      embedding vectors for the anchor images. Embeddings should not be
      l2 normalized.
    embeddings_positive: 2-D Tensor of shape [batch_size/2, embedding_dim] for the
      embedding vectors for the positive images. Embeddings should not be
      l2 normalized.
    reg_lambda: Float. L2 regularization term on the embedding vectors.
    print_losses: Boolean. Option to print the xent and l2loss.

  Returns:
    npairs_loss: tf.float32 scalar.
  """
  # pylint: enable=line-too-long
  # Add the regularizer on the embedding.
  reg_anchor = math_ops.reduce_mean(
      math_ops.reduce_sum(math_ops.square(embeddings_anchor), 1))
  reg_positive = math_ops.reduce_mean(
      math_ops.reduce_sum(math_ops.square(embeddings_positive), 1))
  l2loss = math_ops.multiply(
      0.25 * reg_lambda, reg_anchor + reg_positive, name='l2loss')

  # Get per pair similarities.
  similarity_matrix = math_ops.matmul(
      embeddings_anchor, embeddings_positive, transpose_a=False,
      transpose_b=True)

  # Reshape [batch_size] label tensor to a [batch_size, 1] label tensor.
  lshape = array_ops.shape(labels)
  assert lshape.shape == 1
  labels = array_ops.reshape(labels, [lshape[0], 1])

  labels_remapped = math_ops.cast(
      math_ops.equal(labels, array_ops.transpose(labels)), dtypes.float32)
  labels_remapped /= math_ops.reduce_sum(labels_remapped, 1, keepdims=True)

  # Add the softmax loss.
  xent_loss = nn.softmax_cross_entropy_with_logits(
      logits=similarity_matrix, labels=labels_remapped)
  xent_loss = math_ops.reduce_mean(xent_loss, name='xentropy')

  if print_losses:
    xent_loss = logging_ops.Print(
        xent_loss, ['cross entropy:', xent_loss, 'l2loss:', l2loss])

  return l2loss + xent_loss 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:62,代碼來源:metric_learning.py

示例5: npairs_loss

# 需要導入模塊: from tensorflow.python.ops import logging_ops [as 別名]
# 或者: from tensorflow.python.ops.logging_ops import Print [as 別名]
def npairs_loss(labels, embeddings_anchor, embeddings_positive,
                reg_lambda=0.002, print_losses=False):
  """Computes the npairs loss.

  Npairs loss expects paired data where a pair is composed of samples from the
  same labels and each pairs in the minibatch have different labels. The loss
  has two components. The first component is the L2 regularizer on the
  embedding vectors. The second component is the sum of cross entropy loss
  which takes each row of the pair-wise similarity matrix as logits and
  the remapped one-hot labels as labels.

  See: http://www.nec-labs.com/uploads/images/Department-Images/MediaAnalytics/papers/nips16_npairmetriclearning.pdf

  Args:
    labels: 1-D tf.int32 `Tensor` of shape [batch_size/2].
    embeddings_anchor: 2-D Tensor of shape [batch_size/2, embedding_dim] for the
      embedding vectors for the anchor images. Embeddings should not be
      l2 normalized.
    embeddings_positive: 2-D Tensor of shape [batch_size/2, embedding_dim] for the
      embedding vectors for the positive images. Embeddings should not be
      l2 normalized.
    reg_lambda: Float. L2 regularization term on the embedding vectors.
    print_losses: Boolean. Option to print the xent and l2loss.

  Returns:
    npairs_loss: tf.float32 scalar.
  """
  # pylint: enable=line-too-long
  # Add the regularizer on the embedding.
  reg_anchor = math_ops.reduce_mean(
      math_ops.reduce_sum(math_ops.square(embeddings_anchor), 1))
  reg_positive = math_ops.reduce_mean(
      math_ops.reduce_sum(math_ops.square(embeddings_positive), 1))
  l2loss = math_ops.multiply(
      0.25 * reg_lambda, reg_anchor + reg_positive, name='l2loss')

  # Get per pair similarities.
  similarity_matrix = math_ops.matmul(
      embeddings_anchor, embeddings_positive, transpose_a=False,
      transpose_b=True)

  # Reshape [batch_size] label tensor to a [batch_size, 1] label tensor.
  lshape = array_ops.shape(labels)
  assert lshape.shape == 1
  labels = array_ops.reshape(labels, [lshape[0], 1])

  labels_remapped = math_ops.to_float(
      math_ops.equal(labels, array_ops.transpose(labels)))
  labels_remapped /= math_ops.reduce_sum(labels_remapped, 1, keep_dims=True)

  # Add the softmax loss.
  xent_loss = nn.softmax_cross_entropy_with_logits(
      logits=similarity_matrix, labels=labels_remapped)
  xent_loss = math_ops.reduce_mean(xent_loss, name='xentropy')

  if print_losses:
    xent_loss = logging_ops.Print(
        xent_loss, ['cross entropy:', xent_loss, 'l2loss:', l2loss])

  return l2loss + xent_loss 
開發者ID:CongWeilin,項目名稱:cluster-loss-tensorflow,代碼行數:62,代碼來源:metric_loss_ops.py


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