Exemplo n.º 1
0
def export(net, *inputs, file_name, file_format='AIR', **kwargs):
    """
    Export the MindSpore prediction model to a file in the specified format.

    Args:
        net (Cell): MindSpore network.
        inputs (Tensor): Inputs of the `net`.
        file_name (str): File name of the model to be exported.
        file_format (str): MindSpore currently supports 'AIR', 'ONNX' and 'MINDIR' format for exported model.

            - AIR: Ascend Intermediate Representation. An intermediate representation format of Ascend model.
              Recommended suffix for output file is '.air'.
            - ONNX: Open Neural Network eXchange. An open format built to represent machine learning models.
              Recommended suffix for output file is '.onnx'.
            - MINDIR: MindSpore Native Intermediate Representation for Anf. An intermediate representation format
              for MindSpore models.
              Recommended suffix for output file is '.mindir'.

        kwargs (dict): Configuration options dictionary.

            - quant_mode: The mode of quant.
            - mean: Input data mean. Default: 127.5.
            - std_dev: Input data variance. Default: 127.5.
    """
    logger.info("exporting model file:%s format:%s.", file_name, file_format)
    check_input_data(*inputs, data_class=Tensor)
    if not isinstance(file_name, str):
        raise ValueError(
            "Args file_name {} must be string, please check it".format(
                file_name))

    Validator.check_file_name_by_regular(file_name)
    net = _quant_export(net, *inputs, file_format=file_format, **kwargs)
    _export(net, file_name, file_format, *inputs)