nodes: 0, module; 1, function_definition; 2, function_name:convert_tensor_to_probability_map; 3, parameters; 4, block; 5, identifier:scope; 6, identifier:operator; 7, identifier:container; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, string; 16, assignment; 17, assignment; 18, comparison_operator:model_type == 'neuralNetworkClassifier'; 19, block; 20, elif_clause; 21, else_clause; 22, assignment; 23, comparison_operator:len(operator.inputs[0].type.shape) != 2; 24, comment:# Calculate the shape attribute of ONNX Reshape; 25, block; 26, else_clause; 27, call; 28, string_content:This converter tries to convert a special operator 'TensorToProbabilityMap' into a sequence of some ONNX operators.
      Those operators are used to create a dictionary in which keys are class labels and values are the associated
      probabilities. We assume that the elements in the given probability tensor are aligned with the class labels
      specified in the CoreML model.
  
      Notice that ONNX<1.2 doesn't support a CoreML classifier with a batch size larger than one because old ONNX ZipMap
      is not able to produce a sequence of dictionaries. This issue has been fixed in ONNX-1.2.; 29, identifier:attrs; 30, dictionary; 31, identifier:model_type; 32, call; 33, identifier:model_type; 34, string; 35, expression_statement; 36, if_statement; 37, comparison_operator:model_type == 'pipelineClassifier'; 38, block; 39, block; 40, identifier:input_shape; 41, attribute; 42, call; 43, integer:2; 44, if_statement; 45, if_statement; 46, comment:# ZipMap in ONNX only accepts [C] and [N, C] inputs. In cases of [N, C, 1, 1], we reshape the probability tensor; 47, comment:# into [N, C] before feeding it into ZipMap.; 48, expression_statement; 49, expression_statement; 50, block; 51, attribute; 52, argument_list; 53, pair; 54, attribute; 55, argument_list; 56, string_content:neuralNetworkClassifier; 57, assignment; 58, comparison_operator:model.WhichOneof('ClassLabels') == 'stringClassLabels'; 59, block; 60, elif_clause; 61, else_clause; 62, identifier:model_type; 63, string; 64, expression_statement; 65, if_statement; 66, raise_statement; 67, attribute; 68, identifier:shape; 69, identifier:len; 70, argument_list; 71, comparison_operator:input_shape[0] != 'None'; 72, block; 73, else_clause; 74, call; 75, block; 76, else_clause; 77, assignment; 78, call; 79, expression_statement; 80, identifier:container; 81, identifier:add_node; 82, string; 83, identifier:buffer_name; 84, attribute; 85, keyword_argument; 86, dictionary_splat; 87, string; 88, call; 89, attribute; 90, identifier:WhichOneof; 91, string; 92, identifier:model; 93, attribute; 94, call; 95, string; 96, expression_statement; 97, comparison_operator:model.WhichOneof('ClassLabels') == 'int64ClassLabels'; 98, block; 99, block; 100, string_content:pipelineClassifier; 101, assignment; 102, comparison_operator:model.WhichOneof('ClassLabels') == 'stringClassLabels'; 103, block; 104, elif_clause; 105, else_clause; 106, call; 107, subscript; 108, identifier:type; 109, attribute; 110, subscript; 111, string; 112, expression_statement; 113, block; 114, identifier:all; 115, generator_expression; 116, expression_statement; 117, for_statement; 118, block; 119, identifier:buffer_name; 120, call; 121, identifier:apply_reshape; 122, argument_list; 123, assignment; 124, string_content:ZipMap; 125, subscript; 126, identifier:full_name; 127, identifier:op_domain; 128, string; 129, identifier:attrs; 130, string_content:name; 131, attribute; 132, argument_list; 133, identifier:operator; 134, identifier:raw_operator; 135, string_content:Type; 136, attribute; 137, identifier:neuralNetworkClassifier; 138, attribute; 139, argument_list; 140, string_content:stringClassLabels; 141, assignment; 142, call; 143, string; 144, expression_statement; 145, raise_statement; 146, identifier:model; 147, attribute; 148, call; 149, string; 150, expression_statement; 151, comparison_operator:model.WhichOneof('ClassLabels') == 'int64ClassLabels'; 152, block; 153, block; 154, identifier:TypeError; 155, argument_list; 156, attribute; 157, integer:0; 158, attribute; 159, identifier:shape; 160, identifier:input_shape; 161, integer:0; 162, string_content:None; 163, assignment; 164, expression_statement; 165, comment:# -1 means that this dimension is automatically determined in runtime and unknown in conversion time; 166, call; 167, for_in_clause; 168, assignment; 169, identifier:i; 170, subscript; 171, block; 172, expression_statement; 173, comment:# -1 means that this dimension is automatically determined in runtime and unknown in conversion time; 174, attribute; 175, argument_list; 176, identifier:scope; 177, attribute; 178, identifier:buffer_name; 179, identifier:container; 180, keyword_argument; 181, identifier:buffer_name; 182, attribute; 183, attribute; 184, integer:0; 185, string_content:ai.onnx.ml; 186, identifier:scope; 187, identifier:get_unique_operator_name; 188, string; 189, identifier:operator; 190, identifier:raw_operator; 191, identifier:model; 192, identifier:WhichOneof; 193, string; 194, subscript; 195, call; 196, attribute; 197, argument_list; 198, string_content:int64ClassLabels; 199, assignment; 200, call; 201, attribute; 202, identifier:pipelineClassifier; 203, attribute; 204, argument_list; 205, string_content:stringClassLabels; 206, assignment; 207, call; 208, string; 209, expression_statement; 210, raise_statement; 211, string; 212, identifier:operator; 213, identifier:inputs; 214, subscript; 215, identifier:type; 216, identifier:N; 217, subscript; 218, assignment; 219, identifier:isinstance; 220, argument_list; 221, identifier:i; 222, subscript; 223, identifier:C; 224, integer:1; 225, identifier:input_shape; 226, slice; 227, expression_statement; 228, assignment; 229, identifier:scope; 230, identifier:get_unique_variable_name; 231, string; 232, subscript; 233, identifier:full_name; 234, identifier:desired_shape; 235, list; 236, subscript; 237, identifier:full_name; 238, identifier:operator; 239, identifier:outputs; 240, string_content:ZipMap; 241, string_content:ClassLabels; 242, identifier:attrs; 243, string; 244, identifier:list; 245, generator_expression; 246, identifier:model; 247, identifier:WhichOneof; 248, string; 249, subscript; 250, call; 251, identifier:ValueError; 252, argument_list; 253, identifier:operator; 254, identifier:raw_operator; 255, identifier:model; 256, identifier:WhichOneof; 257, string; 258, subscript; 259, call; 260, attribute; 261, argument_list; 262, string_content:int64ClassLabels; 263, assignment; 264, call; 265, string_content:Only neural network classifiers and pipeline classifiers are supported; 266, attribute; 267, integer:0; 268, identifier:input_shape; 269, integer:0; 270, identifier:N; 271, unary_operator; 272, identifier:i; 273, attribute; 274, identifier:input_shape; 275, slice; 276, integer:1; 277, augmented_assignment; 278, identifier:C; 279, unary_operator; 280, string_content:buffer; 281, attribute; 282, integer:0; 283, identifier:N; 284, identifier:C; 285, attribute; 286, integer:0; 287, string_content:classlabels_strings; 288, call; 289, for_in_clause; 290, string_content:ClassLabels; 291, identifier:attrs; 292, string; 293, identifier:list; 294, generator_expression; 295, string; 296, string_content:ClassLabels; 297, identifier:attrs; 298, string; 299, identifier:list; 300, generator_expression; 301, identifier:model; 302, identifier:WhichOneof; 303, string; 304, subscript; 305, call; 306, identifier:ValueError; 307, argument_list; 308, identifier:operator; 309, identifier:inputs; 310, integer:1; 311, identifier:numbers; 312, identifier:Integral; 313, integer:1; 314, identifier:C; 315, call; 316, integer:1; 317, identifier:operator; 318, identifier:inputs; 319, identifier:operator; 320, identifier:inputs; 321, attribute; 322, argument_list; 323, identifier:s; 324, attribute; 325, string_content:classlabels_int64s; 326, call; 327, for_in_clause; 328, string_content:Unknown label type found; 329, string_content:classlabels_strings; 330, call; 331, for_in_clause; 332, string_content:ClassLabels; 333, identifier:attrs; 334, string; 335, identifier:list; 336, generator_expression; 337, string; 338, identifier:int; 339, argument_list; 340, identifier:s; 341, identifier:encode; 342, string; 343, attribute; 344, identifier:vector; 345, identifier:int; 346, argument_list; 347, identifier:i; 348, attribute; 349, attribute; 350, argument_list; 351, identifier:s; 352, attribute; 353, string_content:classlabels_int64s; 354, call; 355, for_in_clause; 356, string_content:Unknown label type found; 357, identifier:i; 358, string_content:utf-8; 359, identifier:model; 360, identifier:stringClassLabels; 361, identifier:i; 362, attribute; 363, identifier:vector; 364, identifier:s; 365, identifier:encode; 366, string; 367, attribute; 368, identifier:vector; 369, identifier:int; 370, argument_list; 371, identifier:i; 372, attribute; 373, identifier:model; 374, identifier:int64ClassLabels; 375, string_content:utf-8; 376, identifier:model; 377, identifier:stringClassLabels; 378, identifier:i; 379, attribute; 380, identifier:vector; 381, identifier:model; 382, identifier:int64ClassLabels
code: def convert_tensor_to_probability_map(scope, operator, container):
      '''
      This converter tries to convert a special operator 'TensorToProbabilityMap' into a sequence of some ONNX operators.
      Those operators are used to create a dictionary in which keys are class labels and values are the associated
      probabilities. We assume that the elements in the given probability tensor are aligned with the class labels
      specified in the CoreML model.
  
      Notice that ONNX<1.2 doesn't support a CoreML classifier with a batch size larger than one because old ONNX ZipMap
      is not able to produce a sequence of dictionaries. This issue has been fixed in ONNX-1.2.
      '''
      attrs = {'name': scope.get_unique_operator_name('ZipMap')}
  
      model_type = operator.raw_operator.WhichOneof('Type')
      if model_type == 'neuralNetworkClassifier':
          model = operator.raw_operator.neuralNetworkClassifier
          if model.WhichOneof('ClassLabels') == 'stringClassLabels':
              attrs['classlabels_strings'] = list(s.encode('utf-8') for s in model.stringClassLabels.vector)
          elif model.WhichOneof('ClassLabels') == 'int64ClassLabels':
              attrs['classlabels_int64s'] = list(int(i) for i in model.int64ClassLabels.vector)
          else:
              raise ValueError('Unknown label type found')
      elif model_type == 'pipelineClassifier':
          model = operator.raw_operator.pipelineClassifier
          if model.WhichOneof('ClassLabels') == 'stringClassLabels':
              attrs['classlabels_strings'] = list(s.encode('utf-8') for s in model.stringClassLabels.vector)
          elif model.WhichOneof('ClassLabels') == 'int64ClassLabels':
              attrs['classlabels_int64s'] = list(int(i) for i in model.int64ClassLabels.vector)
          else:
              raise ValueError('Unknown label type found')
      else:
          raise TypeError('Only neural network classifiers and pipeline classifiers are supported')
  
      input_shape = operator.inputs[0].type.shape
      if len(operator.inputs[0].type.shape) != 2:
          # Calculate the shape attribute of ONNX Reshape
          if input_shape[0] != 'None':
              N = input_shape[0]
          else:
              N = -1  # -1 means that this dimension is automatically determined in runtime and unknown in conversion time
  
          if all(isinstance(i, numbers.Integral) for i in input_shape[1:]):
              C = 1
              for i in input_shape[1:]:
                  C *= int(i)
          else:
              C = -1  # -1 means that this dimension is automatically determined in runtime and unknown in conversion time
  
          # ZipMap in ONNX only accepts [C] and [N, C] inputs. In cases of [N, C, 1, 1], we reshape the probability tensor
          # into [N, C] before feeding it into ZipMap.
          buffer_name = scope.get_unique_variable_name('buffer')
          apply_reshape(scope, operator.inputs[0].full_name, buffer_name, container, desired_shape=[N, C])
      else:
          buffer_name = operator.inputs[0].full_name
  
      container.add_node('ZipMap', buffer_name, operator.outputs[0].full_name,
                         op_domain='ai.onnx.ml', **attrs)