code: def _summarize_neural_network_spec_code_style(
      nn_spec, indentation=0, input_names=None, output_names=None
  ):
      """
      print nn_spec as if writing code
      """
      indentation_size = 1
  
      if input_names:
          print("def model({}):".format(", ".join(input_names)))
          indentation += indentation_size
  
      for i, layer in enumerate(nn_spec.layers):
          layer_type_str = layer.WhichOneof("layer")
          layer_inputs = list(layer.input)
          layer_outputs = list(layer.output)
  
          if layer_type_str == "loop":
              if len(layer.loop.conditionNetwork.layers) > 0:
                  _prPurple(indentation * "\t" + "Condition Network: ")
                  _summarize_neural_network_spec_code_style(
                      layer.loop.conditionNetwork,
                      indentation=indentation,
                  )
              if layer.loop.conditionVar:
                  layer_inputs.append(layer.loop.conditionVar)
              _print_layer_type_and_arguments(
                  layer_type_str, layer_inputs, indentation
              )
              indentation += indentation_size
              _summarize_neural_network_spec_code_style(
                  layer.loop.bodyNetwork, indentation=indentation
              )
              if len(layer.loop.conditionNetwork.layers) > 0:
                  _prPurple(indentation * "\t" + "Condition Network: ")
                  _summarize_neural_network_spec_code_style(
                      layer.loop.conditionNetwork,
                      indentation=indentation,
                  )
              indentation -= indentation_size
              continue
  
          if layer_type_str == "branch":
              _print_layer_type_and_arguments(
                  layer_type_str, layer_inputs, indentation
              )
              _prRed(indentation * "\t" + "IfBranch:")
              indentation += indentation_size
              _summarize_neural_network_spec_code_style(
                  layer.branch.ifBranch, indentation=indentation
              )
              indentation -= indentation_size
              if len(layer.branch.elseBranch.layers) > 0:
                  _prRed(indentation * "\t" + "ElseBranch:")
                  indentation += indentation_size
                  _summarize_neural_network_spec_code_style(
                      layer.branch.elseBranch, indentation=indentation
                  )
                  indentation -= indentation_size
              continue
  
          if (
              layer_type_str == "loopBreak"
              or layer_type_str == "loopContinue"
          ):
              _prRed(indentation * "\t" + layer_type_str)
              continue
  
          shape = None
          value = None
          if layer_type_str == "loadConstant":
              shape = layer.loadConstant.shape
              shape = list(shape)
              int_shape = [int(x) for x in shape]
              shape = tuple([1, 1] + int_shape)
              size = _find_size(shape)
              if (
                  size < 4
                  and len(layer.loadConstant.data.floatValue) > 0
              ):
                  value = map(
                      float, list(layer.loadConstant.data.floatValue)
                  )
  
          if layer_type_str == "loadConstantND":
              shape = layer.loadConstantND.shape
              shape = tuple(map(int, list(shape)))
              size = _find_size(shape)
              if (
                  size < 4
                  and len(layer.loadConstantND.data.floatValue) > 0
              ):
                  value = map(
                      float, list(layer.loadConstantND.data.floatValue)
                  )
  
          print(indentation * "\t", end="")
          print("{} =".format(", ".join(layer_outputs)), end="")
          _print_layer_type_and_arguments(
              layer_type_str,
              layer_inputs,
              indentation,
              to_indent=False,
              shape=shape,
              value=value,
          )
  
      if output_names:
          _prRed("\n" + indentation * "\t" + "return ", end="")
          print("{}".format(", ".join(output_names)))
  
file_path: coremltools/coremltools/models/neural_network/spec_inspection_utils.py
imports: from ...proto import NeuralNetwork_pb2
label_desc: Use image node_id 12 for calling a global function with example usage: _summarize_neural_network_spec_code_style(nn_spec, indentation, input_names, output_names) without return types