code: def _optimize_nn(layers):
      type_map, output_map, input_map = _get_nn_mappings(layers)
      bn_layers = []
      conv_layers = []
      ip_layers = []
      bias_layers = []
      scale_layers = []
  
      # Only fuse with non-instance batchnorm layers
      if "batchnorm" in type_map.keys():
          for bn_layer_idx in type_map["batchnorm"]:
              if not layers[
                  int(bn_layer_idx)
              ].batchnorm.instanceNormalization:
                  bn_layers.append(bn_layer_idx)
  
      if "convolution" in type_map.keys():
          conv_layers = type_map["convolution"]
  
      if "innerProduct" in type_map.keys():
          ip_layers = type_map["innerProduct"]
  
      if "bias" in type_map.keys():
          bias_layers = type_map["bias"]
  
      if "scale" in type_map.keys():
          scale_layers = type_map["scale"]
  
      # Convolution optimizations
      for conv_idx in conv_layers:
          if len(output_map[conv_idx]) != 1:
              continue
          output_idx = output_map[conv_idx][0]
          if len(input_map[output_idx]) != 1:
              continue
  
          # Batchnorm fusion
          if output_idx in bn_layers:
              _conv_bn_fusion(int(conv_idx), int(output_idx), layers)
              return _optimize_nn(layers)
  
          # Scale fusion
          if output_idx in scale_layers:
              _fuse_layer_with_scale_layer(
                  int(conv_idx), int(output_idx), layers
              )
              return _optimize_nn(layers)
  
          # Bias fusion
          if output_idx in bias_layers:
              _fuse_layer_with_bias_layer(
                  int(conv_idx), int(output_idx), layers
              )
              return _optimize_nn(layers)
  
      # Inner Product optimizations
      for ip_idx in ip_layers:
          if len(output_map[ip_idx]) != 1:
              continue
          output_idx = output_map[ip_idx][0]
          if len(input_map[output_idx]) != 1:
              continue
  
          # Scale Fusion
          if output_idx in scale_layers:
              _fuse_layer_with_scale_layer(
                  int(ip_idx), int(output_idx), layers
              )
              return _optimize_nn(layers)
  
          # Bias Fusion
          if output_idx in bias_layers:
              _fuse_layer_with_bias_layer(
                  int(ip_idx), int(output_idx), layers
              )
              return _optimize_nn(layers)
  
      # Batchnorm optimizations
      for bn_idx in bn_layers:
          if len(output_map[bn_idx]) != 1:
              continue
          output_idx = output_map[bn_idx][0]
          if len(input_map[output_idx]) != 1:
              continue
  
          # Scale Fusion
          if output_idx in scale_layers:
              _bn_scale_fusion(int(bn_idx), int(output_idx), layers)
              return _optimize_nn(layers)
  
imports: import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: _optimize_nn(layers) and returns: _optimize_nn, _optimize_nn, _optimize_nn, _optimize_nn, _optimize_nn, _optimize_nn