code: def test_training_4d(self):
      sp = 8
      batch_size = 2
      n_features = 2
      n_classes = 3
      # 2-features
      features = tf.random_normal(
          shape=[batch_size, sp, sp, sp, sp, n_features]
      )
      # 3-class classification
      logits = tf.random_normal(
          shape=[batch_size, sp, sp, sp, sp, n_classes]
      )
      # ground truth
      gt = tf.random_uniform(
          shape=[batch_size, sp, sp, sp, sp, n_classes],
          minval=0,
          maxval=1,
      )
  
      with tf.device("/cpu:0"):
          crf_layer = CRFAsRNNLayer(
              w_init=[[1] * n_classes, [1] * n_classes],
              mu_init=np.eye(n_classes),
              T=2,
          )
          smoothed_logits = crf_layer(features, logits)
      loss = tf.reduce_mean(tf.abs(smoothed_logits - gt))
      opt = tf.train.GradientDescentOptimizer(0.5).minimize(
          loss, colocate_gradients_with_ops=True
      )
  
      with tf.Session() as sess:
          sess.run(tf.global_variables_initializer())
          params = sess.run(tf.trainable_variables())
          for param in params:
              if param.shape == (n_classes, n_classes):
                  self.assertAllClose(param, np.eye(n_classes))
          sess.run(opt)
          params_1 = sess.run(tf.trainable_variables())
          self.assertGreater(
              np.sum(np.abs(params_1[0] - params[0])), 0.0
          )
  
file_path: NiftyNet/tests/crf_test.py
imports: from __future__ import absolute_import, print_function
  import numpy
  import tensorflow
  from niftynet.layer.crf import CRFAsRNNLayer
  from niftynet.layer.crf import permutohedral_prepare, permutohedral_compute
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 4 for calling the CRFTest obj's underlying member method code with example usage: obj.test_training_4d() without return types