afe.apis.prerelease_v1 ====================== .. py:module:: afe.apis.prerelease_v1 .. autoapi-nested-parse:: This is the pre-release API for AFE. It supports importing models, loading and storing AFE's internal format, quantizing, executing, and simulating. Functions --------- .. autoapisummary:: afe.apis.prerelease_v1.load_onnx_model afe.apis.prerelease_v1.load_pytorch_model afe.apis.prerelease_v1.load_tensorflow_model afe.apis.prerelease_v1.load_tensorflow2_model afe.apis.prerelease_v1.load_tflite_model afe.apis.prerelease_v1.load_keras_model afe.apis.prerelease_v1.load_caffe_model afe.apis.prerelease_v1.load_caffe2_model afe.apis.prerelease_v1.quantize_net afe.apis.prerelease_v1.execute_net afe.apis.prerelease_v1.compile_net afe.apis.prerelease_v1.simulate_isim_module afe.apis.prerelease_v1.isim_net Module Contents --------------- .. 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_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_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_tensorflow2_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 SavedModel 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_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_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:function:: isim_net(elf_file: str, output_kpi_path: str, output_trace_path: Optional[str] = None, output_kpi_csv_path: Optional[str] = None, csv_format: Optional[bool] = False, target: Optional[sima_utils.common.Platform] = None) Take elf file and generate summary KPI file, and trace file. :param elf_file: a elf_file :param output_kpi_path: Path in which kpi files should be created :param output_trace_path: Optional Path in which trace files should be created. Only mla-isim supports --mpack. :param output_kpi_csv_path: Path in which kpi files in csv format should be created :param csv_format: Generate the Summary KPI in CVS format :param target: [Optional] platform target.