class_docstr: This class defines a layer implementing CRFAsRNN described in [1] using
  a bilateral and a spatial kernel as in [2].
  Essentially, this layer smooths its input based on a distance in a feature
  space comprising spatial and feature dimensions.
  High-dimensional Gaussian filtering adapted from [3].
  
  [1] Zheng et al., https://arxiv.org/abs/1502.03240
  [2] Krahenbuhl and Koltun, https://arxiv.org/pdf/1210.5644.pdf
  [3] Adam et al., https://graphics.stanford.edu/papers/permutohedral/
class_docstr_tok: ["This","class","defines","a","layer","implementing","CRFAsRNN","described","in","[","1","]","using","a","bilateral","and","a","spatial","kernel","as","in","[","2","]",".","Essentially",",","this","layer","smooths","its","input","based","on","a","distance","in","a","feature","space","comprising","spatial","and","feature","dimensions",".","High-dimensional","Gaussian","filtering","adapted","from","[","3","]",".","[","1","]","Zheng","et","al.",",","https",":","\/\/arxiv.org\/abs\/1502.03240","[","2","]","Krahenbuhl","and","Koltun",",","https",":","\/\/arxiv.org\/pdf\/1210.5644.pdf","[","3","]","Adam","et","al.",",","https",":","\/\/graphics.stanford.edu\/papers\/permutohedral\/"]
docstr: Currently this layer supports spatial ND dense CRF with CPU only.
  To place the layer on CPU::
  
      with tf.device('/cpu:0'):
          crf_layer = CRFAsRNNLayer()
          crf_output = crf_layer(features, raw_logits)
  
  To ensure backpropagations during training are placed on CPU as well,
  the optimiser should be used with argument
  ``colocate_gradients_with_ops=True``, e.g.,::
  
      train_op = tf.train.GradientDescentOptimizer(.5).minimise(
          training_loss, colocate_gradients_with_ops=True)
  
  
  
  :param alpha: bandwidth for spatial coordinates in bilateral kernel.
                Higher values cause more spatial blurring
  :param beta: bandwidth for feature coordinates in bilateral kernel
                Higher values cause more feature blurring
  :param gamma: bandwidth for spatial coordinates in spatial kernel
                Higher values cause more spatial blurring
  :param T: number of stacked layers in the RNN
  :param aspect_ratio: spacing of adjacent voxels
      (allows isotropic spatial smoothing when voxels are not isotropic)
  :param mu_init: initial compatibility matrix [n_classes x n_classes]
      default value: `-1.0 * eye(n_classes)`
  :param w_init: initial kernel weights [2 x n_classes]
      where w_init[0] are the weights for the bilateral kernel,
            w_init[1] are the weights for the spatial kernel.
      default value: `[ones(n_classes), ones(n_classes)]`
  :param name:
docstr_tok: ["Currently","this","layer","supports","spatial","ND","dense","CRF","with","CPU","only",".","To","place","the","layer","on","CPU",":",":","with","tf.device","(","'\/cpu:0","'",")",":","crf_layer","=","CRFAsRNNLayer","(",")","crf_output","=","crf_layer","(","features",",","raw_logits",")","To","ensure","backpropagations","during","training","are","placed","on","CPU","as","well",",","the","optimiser","should","be","used","with","argument","``","colocate_gradients_with_ops=True","``",",","e.g.",",",":",":","train_op","=","tf.train.GradientDescentOptimizer","(",".5",")",".minimise","(","training_loss",",","colocate_gradients_with_ops=True",")",":","param","alpha",":","bandwidth","for","spatial","coordinates","in","bilateral","kernel",".","Higher","values","cause","more","spatial","blurring",":","param","beta",":","bandwidth","for","feature","coordinates","in","bilateral","kernel","Higher","values","cause","more","feature","blurring",":","param","gamma",":","bandwidth","for","spatial","coordinates","in","spatial","kernel","Higher","values","cause","more","spatial","blurring",":","param","T",":","number","of","stacked","layers","in","the","RNN",":","param","aspect_ratio",":","spacing","of","adjacent","voxels","(","allows","isotropic","spatial","smoothing","when","voxels","are","not","isotropic",")",":","param","mu_init",":","initial","compatibility","matrix","[","n_classes","x","n_classes","]","default","value",":","`","-1.0","*","eye","(","n_classes",")","`",":","param","w_init",":","initial","kernel","weights","[","2","x","n_classes","]","where","w_init","[","0","]","are","the","weights","for","the","bilateral","kernel",",","w_init","[","1","]","are","the","weights","for","the","spatial","kernel",".","default","value",":","`","[","ones","(","n_classes",")",",","ones","(","n_classes",")","]","`",":","param","name",":"]
code: def __init__(
      self,
      alpha=5.0,
      beta=5.0,
      gamma=5.0,
      T=5,
      aspect_ratio=None,
      mu_init=None,
      w_init=None,
      name="crf_as_rnn",
  ):
      """
      Currently this layer supports spatial ND dense CRF with CPU only.
      To place the layer on CPU::
  
          with tf.device('/cpu:0'):
              crf_layer = CRFAsRNNLayer()
              crf_output = crf_layer(features, raw_logits)
  
      To ensure backpropagations during training are placed on CPU as well,
      the optimiser should be used with argument
      ``colocate_gradients_with_ops=True``, e.g.,::
  
          train_op = tf.train.GradientDescentOptimizer(.5).minimise(
              training_loss, colocate_gradients_with_ops=True)
  
  
  
      :param alpha: bandwidth for spatial coordinates in bilateral kernel.
                    Higher values cause more spatial blurring
      :param beta: bandwidth for feature coordinates in bilateral kernel
                    Higher values cause more feature blurring
      :param gamma: bandwidth for spatial coordinates in spatial kernel
                    Higher values cause more spatial blurring
      :param T: number of stacked layers in the RNN
      :param aspect_ratio: spacing of adjacent voxels
          (allows isotropic spatial smoothing when voxels are not isotropic)
      :param mu_init: initial compatibility matrix [n_classes x n_classes]
          default value: `-1.0 * eye(n_classes)`
      :param w_init: initial kernel weights [2 x n_classes]
          where w_init[0] are the weights for the bilateral kernel,
                w_init[1] are the weights for the spatial kernel.
          default value: `[ones(n_classes), ones(n_classes)]`
      :param name:
      """
  
      super(CRFAsRNNLayer, self).__init__(name=name)
      self._alpha = alpha
      self._beta = beta
      self._gamma = gamma
      self._T = T
      self._aspect_ratio = aspect_ratio
      self._mu_init = mu_init
      self._w_init = w_init
  
      assert self._alpha > 0, "alpha should be positive"
      assert self._beta > 0, "beta should be positive"
      assert self._gamma > 0, "gamma should be positive"
  
file_path: NiftyNet/niftynet/layer/crf.py
imports: from __future__ import absolute_import, print_function
  import numpy
  import tensorflow
  from niftynet.layer.base_layer import TrainableLayer
  from niftynet.layer.layer_util import infer_spatial_rank, expand_spatial_params
label_desc: Use image node_id 1 to create a new CRFAsRNNLayer object from inherited base classes: TrainableLayer with example: obj = CRFAsRNNLayer(alpha, beta, gamma, T, aspect_ratio, mu_init, w_init, name)