class_docstr: Attributes:
  layer_list - a list of layer names in the Keras model
  connection_map - a map where the key is a layer, the value is a list of its successors
  reverse_connection_map - a map where the key is a layer, the value is a list of its predecessors
  keras_layer_map - a map where the key is a layer name, the value is Keras layer
  model - a reference of the keras model.
  blob_names - blob names for each one of the edge.
class_docstr_tok: ["Attributes",":","layer_list","-","a","list","of","layer","names","in","the","Keras","model","connection_map","-","a","map","where","the","key","is","a","layer",",","the","value","is","a","list","of","its","successors","reverse_connection_map","-","a","map","where","the","key","is","a","layer",",","the","value","is","a","list","of","its","predecessors","keras_layer_map","-","a","map","where","the","key","is","a","layer","name",",","the","value","is","Keras","layer","model","-","a","reference","of","the","keras","model",".","blob_names","-","blob","names","for","each","one","of","the","edge","."]
code: def insert_permute_for_spatial_bn(self):
      # find spatial batchnorm layers
      spatial_bn_layers = []
      for layer in self.layer_list:
          keras_layer = self.keras_layer_map[layer]
          if (
              isinstance(keras_layer, _keras.layers.BatchNormalization)
              and len(keras_layer.input_shape) == 4
          ):
              if keras_layer.axis == 1 or keras_layer.axis == 2:
                  spatial_bn_layers.append(layer)
  
      for sbn in spatial_bn_layers:
          axis = self.keras_layer_map[sbn].axis
          # axis == 1: swap H axis; axis == 2 : swap W axis
          dims = (0, 2, 1, 3) if axis == 1 else (0, 3, 2, 1)
          # add permutation before spatial batchnorm
          pred = self.get_predecessors(sbn)[0]
          permute_layer = pred + "_permute_" + sbn
          keras_permute = _keras.layers.Permute(dims=dims)
          self._insert_layer_between(
              pred, sbn, permute_layer, keras_permute
          )
          # add permutation after spatial batchnorm
          succs = self.get_successors(sbn)
          if len(succs) == 0:
              permute_layer = sbn + "_permute_"
              keras_permute = _keras.layers.Permute(dims=dims)
              self._insert_layer_between(
                  sbn, None, permute_layer, keras_permute
              )
          else:
              for succ in succs:
                  permute_layer = sbn + "_permute_" + succ
                  keras_permute = _keras.layers.Permute(dims=dims)
                  self._insert_layer_between(
                      sbn, succ, permute_layer, keras_permute
                  )
  
imports: import keras
  import numpy
label_desc: Use image node_id 33 for calling the NetGraph obj's underlying member method code with example usage: obj.insert_permute_for_spatial_bn() without return types