本文整理汇总了Python中tensorflow.python.ops.gen_nn_ops._sparse_softmax_cross_entropy_with_logits方法的典型用法代码示例。如果您正苦于以下问题:Python gen_nn_ops._sparse_softmax_cross_entropy_with_logits方法的具体用法?Python gen_nn_ops._sparse_softmax_cross_entropy_with_logits怎么用?Python gen_nn_ops._sparse_softmax_cross_entropy_with_logits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.gen_nn_ops
的用法示例。
在下文中一共展示了gen_nn_ops._sparse_softmax_cross_entropy_with_logits方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _testXent
# 需要导入模块: from tensorflow.python.ops import gen_nn_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_nn_ops import _sparse_softmax_cross_entropy_with_logits [as 别名]
def _testXent(self, np_features, np_labels):
np_loss, np_backprop = self._npXent(np_features, np_labels)
with self.test_session(use_gpu=True) as sess:
loss, backprop = gen_nn_ops._sparse_softmax_cross_entropy_with_logits(
np_features, np_labels)
tf_loss, tf_backprop = sess.run([loss, backprop])
self.assertAllCloseAccordingToType(np_loss, tf_loss)
self.assertAllCloseAccordingToType(np_backprop, tf_backprop)
示例2: testSingleClass
# 需要导入模块: from tensorflow.python.ops import gen_nn_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_nn_ops import _sparse_softmax_cross_entropy_with_logits [as 别名]
def testSingleClass(self):
for label_dtype in np.int32, np.int64:
with self.test_session(use_gpu=True) as sess:
loss, backprop = gen_nn_ops._sparse_softmax_cross_entropy_with_logits(
np.array([[1.], [-1.], [0.]]).astype(np.float32),
np.array([0, 0, 0]).astype(label_dtype))
tf_loss, tf_backprop = sess.run([loss, backprop])
self.assertAllClose([0.0, 0.0, 0.0], tf_loss)
self.assertAllClose([[0.0], [0.0], [0.0]], tf_backprop)
示例3: testInvalidLabel
# 需要导入模块: from tensorflow.python.ops import gen_nn_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_nn_ops import _sparse_softmax_cross_entropy_with_logits [as 别名]
def testInvalidLabel(self):
features = [
[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 2., 3., 4.],
[1., 2., 3., 4.]]
labels = [4, 3, 0, -1]
if tf.test.is_built_with_cuda() and tf.test.is_gpu_available():
with self.test_session(use_gpu=True) as sess:
loss, backprop = (
gen_nn_ops._sparse_softmax_cross_entropy_with_logits(
features, labels))
tf_loss, tf_backprop = sess.run([loss, backprop])
self.assertAllClose(
[[np.nan] * 4,
[0.25, 0.25, 0.25, -0.75],
[-0.968, 0.087, 0.237, 0.6439],
[np.nan] * 4],
tf_backprop, rtol=1e-3, atol=1e-3)
self.assertAllClose(
[np.nan, 1.3862, 3.4420, np.nan], tf_loss, rtol=1e-3, atol=1e-3)
with self.test_session(use_gpu=False) as sess:
loss, backprop = (
gen_nn_ops._sparse_softmax_cross_entropy_with_logits(
features, labels))
with self.assertRaisesOpError("Received a label value of"):
sess.run([loss, backprop])