afe.load.importers.general_importer
Attributes
Classes
Generic enumeration. |
|
Functions
|
Create a model name from the name of the file the model was loaded from. |
|
Get the default layout for a model format. This is the data layout that |
|
Determine the format of a model stored in files based on the filenames. |
|
Ensure that the importer parameters specify a model format. If a format is |
Import a module into TVM. |
|
|
General-purpose import function that wraps the other importers and is permissive in what inputs it takes. |
|
Construct ImporterParams with required values for importing an ONNX model. |
|
Construct ImporterParams with required values for importing a PyTorch model. |
|
Construct ImporterParams with required values for importing a Tensorflow model. |
|
Construct ImporterParams with required values for importing a Tensorflow model. |
|
Construct ImporterParams with required values for importing a TFLite model. |
|
Construct ImporterParams with required values for importing a Keras model. |
|
Construct ImporterParams with required values for importing a Caffe model. |
|
Construct ImporterParams with required values for importing a Caffe2 model. |
Module Contents
- class afe.load.importers.general_importer.ModelFormat[source]
Generic enumeration.
Derive from this class to define new enumerations.
- afe.load.importers.general_importer.make_model_name_from_path(path: str) str [source]
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.
- afe.load.importers.general_importer.default_layout(model_format: ModelFormat, ndim: int = 4) str [source]
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.
- class afe.load.importers.general_importer.ImporterParams[source]
- format: ModelFormat | None[source]
- input_types: None | InputMapping[afe.ir.tensor_type.ScalarType] | List[afe.ir.tensor_type.ScalarType] = None[source]
- property dtype_dict: Dict[afe.ir.defines.NodeName, afe.ir.tensor_type.ScalarType][source]
- afe.load.importers.general_importer.detect_format(file_paths: List[str]) ModelFormat [source]
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.
- Parameters:
file_paths – Paths of the model files. Different formats use different numbers of files.
- Returns:
The inferred format.
- afe.load.importers.general_importer.update_with_detected_format(import_params: ImporterParams) ImporterParams [source]
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.
- Parameters:
import_params – Importer parameters that may have None in its format field
- Returns:
Parameters derived from import_params, having a non-None format field
- afe.load.importers.general_importer.import_from_import_params(import_params: ImporterParams) Tuple[afe._tvm._defines.TVMIRModule, List[str] | None] [source]
Import a module into TVM.
- Parameters:
import_params – Parameters specifying what to import
- Returns:
The imported module and its outputs’ names. The output names are only returned if the source model format has output names.
- afe.load.importers.general_importer.import_model_to_tvm(format: ModelFormat | None = None, file_paths: List[str] = [], input_names: List[str] | None = None, output_names: List[str] | None = None, input_types: None | InputMapping[afe.ir.tensor_type.ScalarType] | List[afe.ir.tensor_type.ScalarType] = None, input_shapes: None | InputMapping[TensorShape] | List[TensorShape] = None, layout: str | None = None, custom_convert_map: NodeConversionMapping | None = None)[source]
General-purpose import function that wraps the other importers and is permissive in what inputs it takes.
- afe.load.importers.general_importer.onnx_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType]) ImporterParams [source]
Construct ImporterParams with required values for importing an ONNX model.
- Parameters:
model_path – Path to the model file.
shape_dict – Dictionary with names and shapes of the model’s input tensors.
dtype_dict – Dictionary with names and scalar numeric types of the model’s input tensors.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.pytorch_source(model_path: str, input_names: List[str], input_shapes: List[Tuple[int, Ellipsis]]) ImporterParams [source]
Construct ImporterParams with required values for importing a PyTorch model.
- Parameters:
model_path – Path to the model file.
input_names – Names of the model’s input tensors.
input_shapes – Shapes of the model’s input tensors.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.tensorflow_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], output_names: List[str]) ImporterParams [source]
Construct ImporterParams with required values for importing a Tensorflow model.
- Parameters:
model_path – Path to the model file.
shape_dict – Dictionary with names and shapes of the model’s input tensors.
output_names – Names of the model’s output tensors.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.tensorflow2_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], output_names: List[str]) ImporterParams [source]
Construct ImporterParams with required values for importing a Tensorflow model.
- Parameters:
model_path – Path to the model file.
shape_dict – Dictionary with names and shapes of the model’s input tensors.
output_names – Names of the model’s output tensors.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.tflite_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType]) ImporterParams [source]
Construct ImporterParams with required values for importing a TFLite model.
- Parameters:
model_path – Path to the model file.
shape_dict – Dictionary with names and shapes of the model’s input tensors.
dtype_dict – Dictionary with names and scalar numeric types of the model’s input tensors.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.keras_source(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], layout: str) ImporterParams [source]
Construct ImporterParams with required values for importing a Keras model.
- Parameters:
model_path – Path to the model file.
shape_dict – Dictionary with names and shapes of the model’s input tensors.
layout – Keras can be in both channel-first and channel-last layout.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.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 [source]
Construct ImporterParams with required values for importing a Caffe model.
- Parameters:
prototxt_file_path – Prototxt file path.
caffemodel_file_path – Caffe model file path.
shape_dict – Dictionary with names and shapes of the model’s input tensors.
dtype_dict – Dictionary with names and scalar numeric types of the model’s input tensors.
- Returns:
ImporterParams.
- afe.load.importers.general_importer.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 [source]
Construct ImporterParams with required values for importing a Caffe2 model.
- Parameters:
init_net_file_path
predict_net_file_path
shape_dict – Dictionary with names and shapes of the model’s input tensors.
dtype_dict – Dictionary with names and scalar numeric types of the model’s input tensors.
- Returns:
ImporterParams.