code: def test_cross_entropy_value(self):
      # test value is -0.5 * [1 * log(e / (1+e)) + 1 * log(e^2 / (e^2 + 1))]
      with self.cached_session():
          predicted = tf.constant(
              [[0, 1], [2, 0]], dtype=tf.float32, name="predicted"
          )
          labels = tf.constant([1, 0], dtype=tf.int64, name="labels")
          predicted, labels = [
              tf.expand_dims(x, axis=0) for x in (predicted, labels)
          ]
  
          test_loss_func = LossFunction(2, loss_type="CrossEntropy")
          computed_cross_entropy = test_loss_func(predicted, labels)
          self.assertAlmostEqual(
              computed_cross_entropy.eval(),
              -0.5
              * (
                  np.log(np.e / (1 + np.e))
                  + np.log(np.e**2 / (1 + np.e**2))
              ),
          )
  
          test_dense_loss = LossFunction(
              2, loss_type="CrossEntropy_Dense"
          )
          labels = tf.sparse_tensor_to_dense(
              labels_to_one_hot(labels, 2)
          )
          computed_cross_entropy = test_loss_func(
              predicted, tf.to_int32(labels)
          )
          self.assertAlmostEqual(
              computed_cross_entropy.eval(),
              -0.5
              * (
                  np.log(np.e / (1 + np.e))
                  + np.log(np.e**2 / (1 + np.e**2))
              ),
          )
  
imports: from __future__ import absolute_import, print_function
  import numpy
  import tensorflow
  from niftynet.layer.loss_segmentation import LossFunction, labels_to_one_hot
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 1 for calling the CrossEntropyTests obj's underlying member method code with example usage: obj.test_cross_entropy_value() without return types