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


Python nn_ops.softmax_cross_entropy_with_logits方法代碼示例

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


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

示例1: _log_prob

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import softmax_cross_entropy_with_logits [as 別名]
def _log_prob(self, x):
    x = self._assert_valid_sample(x)
    # broadcast logits or x if need be.
    logits = self.logits
    if (not x.get_shape().is_fully_defined() or
        not logits.get_shape().is_fully_defined() or
        x.get_shape() != logits.get_shape()):
      logits = array_ops.ones_like(x, dtype=logits.dtype) * logits
      x = array_ops.ones_like(logits, dtype=x.dtype) * x

    logits_shape = array_ops.shape(math_ops.reduce_sum(logits, -1))
    logits_2d = array_ops.reshape(logits, [-1, self.event_size])
    x_2d = array_ops.reshape(x, [-1, self.event_size])
    ret = -nn_ops.softmax_cross_entropy_with_logits(labels=x_2d,
                                                    logits=logits_2d)
    # Reshape back to user-supplied batch and sample dims prior to 2D reshape.
    ret = array_ops.reshape(ret, logits_shape)
    return ret 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:onehot_categorical.py

示例2: _log_prob

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import softmax_cross_entropy_with_logits [as 別名]
def _log_prob(self, x):
    x = ops.convert_to_tensor(x, name="x")
    # broadcast logits or x if need be.
    logits = self.logits
    if (not x.get_shape().is_fully_defined() or
        not logits.get_shape().is_fully_defined() or
        x.get_shape() != logits.get_shape()):
      logits = array_ops.ones_like(x, dtype=logits.dtype) * logits
      x = array_ops.ones_like(logits, dtype=x.dtype) * x

    logits_shape = array_ops.shape(logits)
    if logits.get_shape().ndims == 2:
      logits_2d = logits
      x_2d = x
    else:
      logits_2d = array_ops.reshape(logits, [-1, self.num_classes])
      x_2d = array_ops.reshape(x, [-1, self.num_classes])
    ret = -nn_ops.softmax_cross_entropy_with_logits(labels=x_2d,
                                                    logits=logits_2d)
    ret = array_ops.reshape(ret, logits_shape)
    return ret 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:23,代碼來源:onehot_categorical.py

示例3: test_binary_ops

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import softmax_cross_entropy_with_logits [as 別名]
def test_binary_ops(self):
    ops = [
        ('sigmoid_cross_entropy_with_logits',
         nn_impl.sigmoid_cross_entropy_with_logits,
         nn.sigmoid_cross_entropy_with_logits),
        ('softmax_cross_entropy_with_logits',
         nn_ops.softmax_cross_entropy_with_logits,
         nn.softmax_cross_entropy_with_logits),
        ('sparse_softmax_cross_entropy_with_logits',
         nn_ops.sparse_softmax_cross_entropy_with_logits,
         nn.sparse_softmax_cross_entropy_with_logits),
    ]
    for op_name, tf_op, lt_op in ops:
      golden_tensor = tf_op(self.original_lt.tensor, self.other_lt.tensor)
      golden_lt = core.LabeledTensor(golden_tensor, self.axes)
      actual_lt = lt_op(self.original_lt, self.other_lt)
      self.assertIn(op_name, actual_lt.name)
      self.assertLabeledTensorsEqual(golden_lt, actual_lt) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:20,代碼來源:nn_test.py

示例4: _entropy

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import softmax_cross_entropy_with_logits [as 別名]
def _entropy(self):
    if self.logits.get_shape().ndims == 2:
      logits_2d = self.logits
    else:
      logits_2d = array_ops.reshape(self.logits, [-1, self.num_classes])
    histogram_2d = nn_ops.softmax(logits_2d)
    ret = array_ops.reshape(
        nn_ops.softmax_cross_entropy_with_logits(labels=histogram_2d,
                                                 logits=logits_2d),
        self.batch_shape())
    ret.set_shape(self.get_batch_shape())
    return ret 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:14,代碼來源:onehot_categorical.py

示例5: _entropy

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import softmax_cross_entropy_with_logits [as 別名]
def _entropy(self):
    if self.logits.get_shape().ndims == 2:
      logits_2d = self.logits
    else:
      logits_2d = array_ops.reshape(self.logits, [-1, self.num_classes])
    histogram_2d = nn_ops.softmax(logits_2d)
    ret = array_ops.reshape(
        nn_ops.softmax_cross_entropy_with_logits(logits_2d, histogram_2d),
        self.batch_shape())
    ret.set_shape(self.get_batch_shape())
    return ret 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:categorical.py


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