def parse_coreml(model, initial_types=None, target_opset=None, custom_conversion_functions=None, custom_shape_calculators=None):
    '''
    This is the root function of the whole parsing procedure.
    :param model: CoreML model
    :param initial_types: A list providing some types for some root variables. Each element is a tuple of a variable
    name and a type defined in data_types.py.
    :param target_opset: number, for example, 7 for ONNX 1.2, and 8 for ONNX 1.3.
    :param custom_conversion_functions: a dictionary for specifying the user customized conversion function
    :param custom_shape_calculators: a dictionary for specifying the user customized shape calculator
    :return: a Topology object. It's a intermediate representation of the input CoreML model
    '''

    # Add model-level input and output names into a set. The set will be fed into our Topology so that all its elements
    # will not be used to declare variables
    reserved_variable_names = set()
    for var in list(model.description.input) + list(model.description.output):
        reserved_variable_names.add(var.name)

    # Determine the batch size for parsing CoreML model's input and output features. Note that batch size is always
    # missing in all CoreML models.
    default_batch_size = 1 if model.WhichOneof('Type') not in \
                              ['neuralNetworkClassifier', 'neuralNetworkRegressor', 'neuralNetwork'] else 'None'

    # Topology is shared by both of CoreML and scikit-learn conversion frameworks, so we have a wrapper class,
    # CoremlModelContainer, to make sure our topology-related functions can seamlessly handle both of CoreML and
    # scikit-learn.
    topology = Topology(CoremlModelContainer(model),
                        default_batch_size,
                        initial_types,
                        reserved_variable_names,
                        target_opset=target_opset,
                        custom_conversion_functions=custom_conversion_functions,
                        custom_shape_calculators=custom_shape_calculators)
    scope = topology.declare_scope('__root__')

    # Instead of using CoremlModelContainer, we directly pass the model in because _parse_model is CoreML-specific.
    _parse_model(topology, scope, model)
    topology.compile()

    for variable in topology.find_root_and_sink_variables():
        color_space = getattr(variable.type, 'color_space', None)
        if color_space:
            if topology.metadata_props.setdefault('Image.BitmapPixelFormat', color_space) != color_space:
                warnings.warn('Conflicting pixel formats found. In ONNX, all input/output images must use the same pixel format.')
        # Use original CoreML names for model-level input(s)/output(s)
        if variable.raw_name not in reserved_variable_names:
            continue
        topology.rename_variable(variable.onnx_name, variable.raw_name)
    return topology
def parse_coreml ( model , initial_types = None , target_opset = None , custom_conversion_functions = None , custom_shape_calculators = None ) : reserved_variable_names = set ( ) for var in list ( model . description . input ) + list ( model . description . output ) : reserved_variable_names . add ( var . name ) default_batch_size = 1 if model . WhichOneof ( 'Type' ) not in [ 'neuralNetworkClassifier' , 'neuralNetworkRegressor' , 'neuralNetwork' ] else 'None' topology = Topology ( CoremlModelContainer ( model ) , default_batch_size , initial_types , reserved_variable_names , target_opset = target_opset , custom_conversion_functions = custom_conversion_functions , custom_shape_calculators = custom_shape_calculators ) scope = topology . declare_scope ( '__root__' ) _parse_model ( topology , scope , model ) topology . compile ( ) for variable in topology . find_root_and_sink_variables ( ) : color_space = getattr ( variable . type , 'color_space' , None ) if color_space : if topology . metadata_props . setdefault ( 'Image.BitmapPixelFormat' , color_space ) != color_space : warnings . warn ( 'Conflicting pixel formats found. In ONNX, all input/output images must use the same pixel format.' ) if variable . raw_name not in reserved_variable_names : continue topology . rename_variable ( variable . onnx_name , variable . raw_name ) return topology
This is the root function of the whole parsing procedure.
    :param model: CoreML model
    :param initial_types: A list providing some types for some root variables. Each element is a tuple of a variable
    name and a type defined in data_types.py.
    :param target_opset: number, for example, 7 for ONNX 1.2, and 8 for ONNX 1.3.
    :param custom_conversion_functions: a dictionary for specifying the user customized conversion function
    :param custom_shape_calculators: a dictionary for specifying the user customized shape calculator
    :return: a Topology object. It's a intermediate representation of the input CoreML model