afe.load.importers.general_importer =================================== .. py:module:: afe.load.importers.general_importer Attributes ---------- .. autoapisummary:: afe.load.importers.general_importer.TensorShape afe.load.importers.general_importer.InputMapping afe.load.importers.general_importer.NodeConversionMapping Classes ------- .. autoapisummary:: afe.load.importers.general_importer.ModelFormat afe.load.importers.general_importer.ImporterParams Functions --------- .. autoapisummary:: afe.load.importers.general_importer.make_model_name_from_path afe.load.importers.general_importer.default_layout afe.load.importers.general_importer.detect_format afe.load.importers.general_importer.update_with_detected_format afe.load.importers.general_importer.import_from_import_params afe.load.importers.general_importer.import_model_to_tvm afe.load.importers.general_importer.onnx_source afe.load.importers.general_importer.pytorch_source afe.load.importers.general_importer.tensorflow_source afe.load.importers.general_importer.tensorflow2_source afe.load.importers.general_importer.tflite_source afe.load.importers.general_importer.keras_source afe.load.importers.general_importer.caffe_source afe.load.importers.general_importer.caffe2_source Module Contents --------------- .. py:data:: TensorShape .. py:data:: InputMapping .. py:data:: NodeConversionMapping .. py:class:: ModelFormat Generic enumeration. Derive from this class to define new enumerations. .. py:attribute:: tensorflow :value: 'tensorflow' .. py:attribute:: tensorflow2 :value: 'tensorflow2' .. py:attribute:: tflite :value: 'tflite' .. py:attribute:: keras :value: 'keras' .. py:attribute:: pytorch :value: 'pytorch' .. py:attribute:: onnx :value: 'onnx' .. py:attribute:: caffe2 :value: 'caffe2' .. py:attribute:: caffe :value: 'caffe' .. py:function:: make_model_name_from_path(path: str) -> str Create a model name from the name of the file the model was loaded from. This is used in functions that do not take the model name as user input. .. py:function:: default_layout(model_format: ModelFormat, ndim: int = 4) -> str Get the default layout for a model format. This is the data layout that the format uses by convention. Returns either 4D or 5D layout. .. py:class:: ImporterParams .. py:attribute:: format :type: Optional[ModelFormat] .. py:attribute:: file_paths :type: List[str] .. py:attribute:: input_names :type: Optional[List[str]] :value: None .. py:attribute:: output_names :type: Optional[List[str]] :value: None .. py:attribute:: input_types :type: Union[None, InputMapping[afe.ir.tensor_type.ScalarType], List[afe.ir.tensor_type.ScalarType]] :value: None .. py:attribute:: input_shapes :type: Union[None, InputMapping[TensorShape], List[TensorShape]] :value: None .. py:attribute:: layout :type: Optional[str] :value: None .. py:attribute:: custom_convert_map :type: Optional[NodeConversionMapping] :value: None .. py:property:: shape_dict :type: Dict[afe.ir.defines.NodeName, afe.ir.defines.InputShape] .. py:property:: dtype_dict :type: Dict[afe.ir.defines.NodeName, afe.ir.tensor_type.ScalarType] .. py:function:: detect_format(file_paths: List[str]) -> ModelFormat Determine the format of a model stored in files based on the filenames. Raise an exception if the format can't be determined. This function does not try to access the files. :param file_paths: Paths of the model files. Different formats use different numbers of files. :return: The inferred format. .. py:function:: update_with_detected_format(import_params: ImporterParams) -> ImporterParams Ensure that the importer parameters specify a model format. If a format is not given, detect and record the format. Raises an exception if a format is not given and cannot be detected. :param import_params: Importer parameters that may have None in its format field :return: Parameters derived from import_params, having a non-None format field .. py:function:: import_from_import_params(import_params: ImporterParams) -> Tuple[afe._tvm._defines.TVMIRModule, Optional[List[str]]] Import a module into TVM. :param import_params: Parameters specifying what to import :return: The imported module and its outputs' names. The output names are only returned if the source model format has output names. .. py:function:: import_model_to_tvm(format: Optional[ModelFormat] = None, file_paths: List[str] = [], input_names: Optional[List[str]] = None, output_names: Optional[List[str]] = None, input_types: Union[None, InputMapping[afe.ir.tensor_type.ScalarType], List[afe.ir.tensor_type.ScalarType]] = None, input_shapes: Union[None, InputMapping[TensorShape], List[TensorShape]] = None, layout: Optional[str] = None, custom_convert_map: Optional[NodeConversionMapping] = None) General-purpose import function that wraps the other importers and is permissive in what inputs it takes. .. py:function:: onnx_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType]) -> ImporterParams Construct ImporterParams with required values for importing an ONNX model. :param model_path: Path to the model file. :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param dtype_dict: Dictionary with names and scalar numeric types of the model's input tensors. :return: ImporterParams. .. py:function:: pytorch_source(model_path: str, input_names: List[str], input_shapes: List[Tuple[int, Ellipsis]]) -> ImporterParams Construct ImporterParams with required values for importing a PyTorch model. :param model_path: Path to the model file. :param input_names: Names of the model's input tensors. :param input_shapes: Shapes of the model's input tensors. :return: ImporterParams. .. py:function:: tensorflow_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], output_names: List[str]) -> ImporterParams Construct ImporterParams with required values for importing a Tensorflow model. :param model_path: Path to the model file. :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param output_names: Names of the model's output tensors. :return: ImporterParams. .. py:function:: tensorflow2_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], output_names: List[str]) -> ImporterParams Construct ImporterParams with required values for importing a Tensorflow model. :param model_path: Path to the model file. :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param output_names: Names of the model's output tensors. :return: ImporterParams. .. py:function:: tflite_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType]) -> ImporterParams Construct ImporterParams with required values for importing a TFLite model. :param model_path: Path to the model file. :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param dtype_dict: Dictionary with names and scalar numeric types of the model's input tensors. :return: ImporterParams. .. py:function:: keras_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], layout: str) -> ImporterParams Construct ImporterParams with required values for importing a Keras model. :param model_path: Path to the model file. :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param layout: Keras can be in both channel-first and channel-last layout. :return: ImporterParams. .. py:function:: caffe_source(prototxt_file_path: str, caffemodel_file_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType]) -> ImporterParams Construct ImporterParams with required values for importing a Caffe model. :param prototxt_file_path: Prototxt file path. :param caffemodel_file_path: Caffe model file path. :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param dtype_dict: Dictionary with names and scalar numeric types of the model's input tensors. :return: ImporterParams. .. py:function:: caffe2_source(init_net_file_path: str, predict_net_file_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType]) -> ImporterParams Construct ImporterParams with required values for importing a Caffe2 model. :param init_net_file_path: :param predict_net_file_path: :param shape_dict: Dictionary with names and shapes of the model's input tensors. :param dtype_dict: Dictionary with names and scalar numeric types of the model's input tensors. :return: ImporterParams.