afe === .. py:module:: afe .. autoapi-nested-parse:: The API for AFE as a library. Functions in this file are re-exported from other modules. See those modules for documentation. Submodules ---------- .. toctree:: :maxdepth: 1 /pages/api_reference/python-autoapi/afe/apis/index /pages/api_reference/python-autoapi/afe/backends/index /pages/api_reference/python-autoapi/afe/common_utils/index /pages/api_reference/python-autoapi/afe/core/index /pages/api_reference/python-autoapi/afe/devkit/index /pages/api_reference/python-autoapi/afe/driver/index /pages/api_reference/python-autoapi/afe/ir/index /pages/api_reference/python-autoapi/afe/load/index /pages/api_reference/python-autoapi/afe/tvm_converter/index Attributes ---------- .. autoapisummary:: afe.python_version afe.CALIBRATED_POSTFIX afe.QUANTIZED_POSTFIX afe.f Functions --------- .. autoapisummary:: afe.load_awesomenet afe.save_awesomenet afe.load_tensorflow_model afe.load_pytorch_model afe.load_tflite_model afe.load_onnx_model afe.load_keras_model afe.load_caffe_model afe.load_caffe2_model afe.quantize_net afe.execute_net afe.compile_net afe.simulate_isim_module Package Contents ---------------- .. py:data:: python_version .. py:function:: load_awesomenet(model_name: str, network_directory: str = '') -> afe.ir.net.AwesomeNet Loads an AwesomeNet from yaml and npz files :param model_name: The name of the model, used in file names. :param network_directory: The directory to load the files from. .. py:function:: save_awesomenet(net: afe.ir.net.AwesomeNet, model_name: str, output_directory: str = '') -> None Saves an AwesomeNet to a yaml and npz file. Overwrites existing files. :param net: AwesomeNet to save. :param model_name: The name of the model, used in file names. :param output_directory: The directory to save the files to. .. py:function:: load_tensorflow_model(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], output_names: List[str], layout: str = 'NHWC', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads a TensorFlow model into an _AwesomeNet format :param model_path: Path to a .pb TensorFlow model :param shape_dict: Dictionary of input names to input shapes eg. {'input', (1,224,224,3)} :param output_names: List of output names of the network eg. ['output1', 'output2'] :param layout: any variation of the characters NHWC representing Batch Size, Height, Width, and Channels :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: load_pytorch_model(model_path: str, input_names: List[str], input_shapes: List[Tuple[int, Ellipsis]], input_dtypes: Optional[List[afe.ir.tensor_type.ScalarType]] = None, layout: str = 'NCHW', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads a PyTorch model into an _AwesomeNet format. :param model_path: Path to a PyTorch file (.pt) that contains the entire model :param input_names: List of input names. eg ['input'] :param input_shapes: List of input shapes corresponding to input names. eg. [(1, 224, 224, 3)] :param input_dtypes: List of input datatypes corresponding to input names. eg ['float32'] :param layout: Input data layout. Default is 'NCHW' :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: load_tflite_model(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType], layout: str = 'NHWC', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads a TensorFlow Lite model into an _AwesomeNet format. :param model_path: Path to a .tflite file containing the TensorFlow Lite model :param shape_dict: Dictionary of input names to input shapes eg. {'input', (1,224,224,3)} :param dtype_dict: Dictionary of input names to input types eg. {'input', 'float32'} :param layout: Input data layout. Default is 'NHWC' :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: load_onnx_model(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType], layout: str = 'NCHW', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads an ONNX model into an _AwesomeNet format. :param model_path: Path to a .onnx file containing the onnx model :param shape_dict: Dictionary of input names to input shapes eg. {'input', (1,224,224,3)} :param dtype_dict: Dictionary of input names to input types eg. {'input', 'float32'} :param layout: Input data layout. Default is 'NCHW' :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: load_keras_model(model_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], layout: str = 'NCHW', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads a Keras model into an _AwesomeNet format. :param model_path: Path to a .h5 file containing the keras model :param shape_dict: Dictionary of input names to input shapes eg. {'input', (1,224,224,3)} :param layout: Input data layout. Default is 'NCHW' :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: load_caffe_model(prototxt_file_path: str, caffemodel_file_path: str, shape_dict: Dict[str, Tuple[int, Ellipsis]], dtype_dict: Dict[str, afe.ir.tensor_type.ScalarType], layout: str = 'NCHW', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads a caffe model into an _AwesomeNet format. :param prototxt_file_path: filepath to the caffe .prototxt file :param caffemodel_file_path: filepath to the caffe .caffemodel file :param shape_dict: Dictionary of input names to input shapes eg. {'input', (1,224,224,3)} :param dtype_dict: Dictionary of input names to input types eg. {'input', 'float32'} :param layout: Input data layout. Default is 'NCHW' :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: load_caffe2_model(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], layout: str = 'NCHW', is_quantized: bool = False) -> afe.ir.net.AwesomeNet Loads a caffe2 model into an _AwesomeNet format. :param init_net_file_path: filepath to the caffe2 .pb init_net file :param predict_net_file_path: filepath to the caffe2 .pb predict_net file :param shape_dict: Dictionary of input names to input shapes eg. {'input', (1,224,224,3)} :param dtype_dict: Dictionary of input names to input types eg. {'input', 'float32'} :param layout: Input data layout. Default is 'NCHW' :param is_quantized: Whether the model is pre-quantized. Default is False :return: An _AwesomeNet .. py:function:: quantize_net(net: afe.ir.net.AwesomeNet, input_generator: sima_utils.data.data_generator.DataGenerator, asymmetry: bool, per_channel: bool, max_calibration_samples: int) Quantizes a network. :param net: an _AwesomeNet :param input_generator: a DataGenerator we use to feed inputs into the _AwesomeNet during calibration :param asymmetry: If True this function performs asymmetric quantization. Otherwise, it performs symmetric quantization :param per_channel: If True this function performs per_channel quantization. :param max_calibration_samples: Maximum number of samples we use for calibration .. py:function:: execute_net(net: afe.ir.net.AwesomeNet, inputs: Dict[str, numpy.ndarray], dequantize_outputs: bool = True) -> List[numpy.ndarray] Executes a network. :param net: an _AwesomeNet :param inputs: Dictionary of placeholder node names (str) to the input data :param dequantize_outputs: Whether to dequantize the output data to floating point :return The result of executing the output node .. py:function:: compile_net(net: afe.ir.net.AwesomeNet, output_elf_path: str, compress: bool = True) Compile a network using Product Compiler. :param net: an _AwesomeNet. :param output_elf_path: Path in which elf files should be created. :param compress: If True mlc file is compressed before generating .elf file. .. py:function:: simulate_isim_module(elf_file: str, output_path: str, output_kpi_file_name: Optional[str] = None, output_trace_file_name: Optional[str] = None, generate_csv_kpi: Optional[bool] = True, override_existing: Optional[bool] = False, target: Optional[sima_utils.common.Platform] = None) Wrapper to take elf file and generate summary KPI file, and trace file. :param elf_file: Path to the location of the elf file to simulate in ISIM. :param output_path: Location of where to store all output files. If location does not exist, it will be created. :param output_kpi_file_name: Name for output kpi file. Default: elf_file name without '.elf' extension and finishing with '_kpis.txt' postfix. :param output_trace_file_name: Name for output trace file. Default: elf_file name without '.elf' extension and finishing with '_trace.mpack' postfix. :param generate_csv_kpi: Whether to generate a CSV file with the KPIs in addition to the txt. :param override_existing: Whether to override existing kpis and trace files from a previous run. :param target: [Optional] platform target. .. py:data:: CALIBRATED_POSTFIX :value: '_calibrated' .. py:data:: QUANTIZED_POSTFIX :value: '_quantized' .. py:data:: f