### Build and Run Acuitylite Docker Environment Source: https://context7.com/verisilicon/acuitylite/llms.txt Builds the recommended Docker image and runs a container for Acuitylite development. Installs Acuitylite inside the container. ```bash # Build the recommended Docker image (Ubuntu 22.04 / Python 3.10) docker build -f docker/Dockerfile.ubuntu22.04_py3.10 -t acuity_env . # Run the container, mounting your working directory docker run -it -v $(pwd):/home/builder --name acuity_ide --user builder acuity_env /bin/bash # Inside the container, install Acuitylite pip install acuitylite --no-deps ``` -------------------------------- ### Full Pipeline: TFLite (pre-quantized) to TIM-VX + NBG Export Source: https://context7.com/verisilicon/acuitylite/llms.txt This example demonstrates importing a pre-quantized TFLite model and exporting it to TIM-VX and NBG formats. It includes inference validation and specific export configurations for TIM-VX and NBG. ```python #!/usr/bin/env python3 import numpy as np import tensorflow as tf from acuitylib.interface.importer import TFLiteLoader from acuitylib.interface.exporter import TimVxExporter, OvxlibExporter from acuitylib.interface.inference import Inference mobilenet = 'model/mobilenet_v1_1.0_224_quant.tflite' labels = [697, 813] def get_data(): for image_path in ['data/697.jpg', 'data/813.jpg']: arr = tf.io.decode_image(tf.io.read_file(image_path)).numpy() arr = arr.reshape(1, 224, 224, 3).astype(np.float32) arr = (arr - 128.0) / 128.0 # Re-quantize input for pre-quantized TFLite model arr = np.rint(arr / 0.0078125) + 128 yield {'input': np.array(arr, dtype=np.uint8)} # 1. Import (already quantized — do NOT call Quantization again) model = TFLiteLoader(mobilenet).load() # 2. Inference validation infer = Inference(model) infer.build_session() for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) assert outs[0].flatten()[labels[i]] > 0.9 # 3. Export TIM-VX case TimVxExporter(model).export('export_timvx/quant/mobilenet') # 4. Export NBG only via OvxlibExporter OvxlibExporter(model).export('export_ovxlib/quant/mobilenet', pack_nbg_only=True) ``` -------------------------------- ### Full Pipeline: Caffe to TIM-VX + TFLite Export Source: https://context7.com/verisilicon/acuitylite/llms.txt This comprehensive example covers the entire pipeline from importing a Caffe model to exporting it in both TIM-VX and TFLite formats, including float inference checks and per-channel INT8 quantization. ```python #!/usr/bin/env python3 import numpy as np import tensorflow as tf from acuitylib.interface.importer import CaffeLoader from acuitylib.interface.exporter import TimVxExporter, TFLiteExporter from acuitylib.interface.quantization import Quantization, QuantizerType from acuitylib.interface.inference import Inference prototxt = 'model/lenet.prototxt' caffe_model = 'model/lenet.caffemodel' def get_data(): for image_path in ['data/0.jpg', 'data/1.png']: arr = tf.io.decode_image(tf.io.read_file(image_path)).numpy() arr = arr.reshape(1, 1, 28, 28).astype(np.float32) yield {'input': arr} # 1. Import model = CaffeLoader(model=prototxt, weights=caffe_model).load() # 2. Float inference check infer = Inference(model) infer.build_session() for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) assert outs[0].flatten()[i] > 0.99 # 3. Float exports TimVxExporter(model).export('export_timvx/float16/lenet') TFLiteExporter(model).export('export_tflite/float16/lenet.tflite') # 4. Per-channel int8 quantization Quantization(model).quantize( input_generator_func=get_data, quantizer=QuantizerType.PERCHANNEL_SYMMETRIC_AFFINE, qtype='int8', iterations=1 ) # 5. Quantized inference check infer = Inference(model) infer.build_session() for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) assert outs[0].flatten()[i] > 0.99 # 6. Quantized exports TimVxExporter(model).export('export_timvx/pcq_symi8/lenet') TFLiteExporter(model).export('export_tflite/pcq_symi8/lenet.tflite') ``` -------------------------------- ### Run Quantized Model Inference Source: https://context7.com/verisilicon/acuitylite/llms.txt Runs inference on a quantized Acuity model. Accepts input data as a list or dictionary. Set `return_quantized_data=True` to get raw quantized integer values. ```python import numpy as np import tensorflow as tf from acuitylib.interface.inference import Inference # --- Quantized inference (pass list instead of dict) --- infer_q = Inference(model) # model already quantized infer_q.build_session() for data in get_data(): ins, outs = infer_q.run_session( inputs=data, # list or dict accepted return_quantized_data=False # set True to get raw quantized int values ) print(np.argmax(outs[0])) ``` -------------------------------- ### Build and Run TIM-VX Application Source: https://context7.com/verisilicon/acuitylite/llms.txt Instructions for building and running an exported TIM-VX case. Requires setting environment variables for TIM-VX and Vivante SDK paths, then using `make` within the exported case directory. ```bash export TIM_VX_DIR=/path/to/tim-vx/build/install export VIVANTE_SDK_DIR=/path/to/tim-vx/prebuilt-sdk/x86_64_linux export LD_LIBRARY_PATH=$TIM_VX_DIR/lib:$VIVANTE_SDK_DIR/lib # Build with make or cmake inside the exported case directory cd export_timvx/asymu8/squeezenet make ``` -------------------------------- ### MobileNet TensorFlow Inference Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/demo_tensorflow.rst.txt This script performs inference using a pre-trained MobileNet model with TensorFlow. Ensure TensorFlow is installed and the model file is accessible. ```python import tensorflow as tf import numpy as np # Load the model model = tf.keras.models.load_model('mobilenet_v1_1.0_224.tflite') # Prepare input data (example: a random image) input_shape = model.input_shape input_data = np.random.rand(1, input_shape[1], input_shape[2], input_shape[3]).astype(np.float32) # Perform inference predictions = model.predict(input_data) # Process predictions (e.g., find the top prediction) predicted_class = np.argmax(predictions[0]) confidence = np.max(predictions[0]) print(f"Predicted class: {predicted_class}") print(f"Confidence: {confidence:.4f}") ``` -------------------------------- ### Export NBG only with custom SDK and license Source: https://context7.com/verisilicon/acuitylite/llms.txt This snippet demonstrates exporting a model in NBG format, specifically when a custom SDK and license are required. Ensure the 'viv_sdk' path points to a directory containing 'prebuilt-sdk/x86_64_linux'. ```python OvxlibExporter(model).export( 'export_ovxlib/quant/mobilenet', pack_nbg_only=True, viv_sdk='/path/to/my_sdk', # must contain prebuilt-sdk/x86_64_linux licence='/path/to/licence.txt' ) ``` -------------------------------- ### OnnxLoader Class Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.onnxloader.html Initializes the OnnxLoader with the path to the ONNX model file. ```APIDOC ## class importer.OnnxLoader(_model_) Translates a Onnx model to Acuity formats. ### __init__(model) Parameters: * **model** – The file path of the imported Onnx model file, a .onnx file. ``` -------------------------------- ### CaffeLoader Constructor Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.caffeloader.html Initializes the CaffeLoader with model and weights file paths. ```APIDOC ## CaffeLoader(model, weights=None) ### Description Translates a Caffe model to Acuity formats. ### Parameters * **model** (string) - Required - The file path of the imported Caffe model file, a .prototxt file. * **weights** (string) - Optional - The file path of the imported weights file, a .caffemodel file. ``` -------------------------------- ### Load and Run Quantized TFLite Model with Acuitylite Source: https://github.com/verisilicon/acuitylite/blob/main/docs/demo_tflite.html This snippet demonstrates loading a quantized TFLite model, performing inference, and verifying the output. It includes data preprocessing and quantization steps specific to quantized models. ```python #!/usr/bin/env python3 import tensorflow as tf import numpy as np from acuitylib.interface.importer import TFLiteLoader from acuitylib.interface.exporter import TimVxExporter from acuitylib.interface.exporter import OvxlibExporter from acuitylib.interface.inference import Inference # wget https://storage.googleapis.com/download.tensorflow.org// # models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz mobilenet = "model/mobilenet_v1_1.0_224_quant.tflite" image0 = "data/697.jpg" image1 = "data/813.jpg" labels = [697, 813] # data generator def get_data(): for image in [image0, image1]: arr = tf.io.decode_image(tf.io.read_file(image)).numpy().reshape(1, 224, 224, 3).astype(np.float32) arr = (arr-128.0)/128.0 # preprocess arr = np.rint(arr / 0.0078125) + 128 # quantize arr as quantized input for quantized model(begin from 6.27.0) inputs = {'input': np.array(arr, dtype=np.uint8)} yield inputs def test_tflite_mobilenet(): # no need to quantize using acuity lite for quant model # load tflite quant model quantmodel = TFLiteLoader(mobilenet).load() # inference with quant model infer = Inference(quantmodel) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session assert outs[0].flatten()[labels[i]] > 0.9 # export tim-vx quant case TimVxExporter(quantmodel).export('export_timvx/quant/mobilenet') # export nbg OvxlibExporter(quantmodel).export('export_ovxlib/quant/mobilenet', pack_nbg_only=True) if __name__ == '__main__': test_tflite_mobilenet() ``` -------------------------------- ### AcuityModel Initialization Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/acuitymodel.rst.txt Initializes the AcuityModel. This is the constructor for the class. ```APIDOC ## __init__ ### Description Initializes the AcuityModel. ### Method __init__ ``` -------------------------------- ### Download Mobilenet V1 TFLite Model Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/demo_tflite.rst.txt Use wget to download the quantized Mobilenet V1 model. No further quantization is needed with Acuity Lite for this model. ```bash wget https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz ``` -------------------------------- ### Load Darknet Model with Acuitylite Source: https://context7.com/verisilicon/acuitylite/llms.txt Loads a Darknet model using DarknetLoader. Requires both the .cfg and .weights files. ```python from acuitylib.interface.importer import DarknetLoader # Load AlexNet from Darknet format model = DarknetLoader( model='model/alexnet2.cfg', weights='model/alexnet2.weights' ).load() # Returns: AcuityModel ``` -------------------------------- ### TensorflowLoader Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.tensorflowloader.html Initializes the TensorflowLoader with the path to the Tensorflow model file. ```APIDOC ## class importer.TensorflowLoader Translates a Tensorflow model to Acuity formats. ### __init__(model) Parameters: * **model** (string) - The file path of the imported Tensorflow model file, a .pb file. ``` -------------------------------- ### AcuityModel Constructor Source: https://github.com/verisilicon/acuitylite/blob/main/docs/acuitymodel.html Initializes the AcuityModel with an Acuitylite network object. ```APIDOC ## AcuityModel.__init__ ### Description Initializes the AcuityModel with an Acuitylite network object. ### Parameters * **net** (Acuitylite network object) - The Acuitylite network object to be used. ``` -------------------------------- ### Load, Quantize, and Export TensorFlow Model Source: https://github.com/verisilicon/acuitylite/blob/main/docs/demo_tensorflow.html This script loads a TensorFlow model, performs asymmetric affine quantization using a data generator, runs inference on the quantized model, and exports it to TFLite format. Ensure the model path and data paths are correct. ```python #!/usr/bin/env python3 import tensorflow as tf import numpy as np from acuitylib.interface.importer import TensorflowLoader from acuitylib.interface.exporter import TFLiteExporter from acuitylib.interface.quantization import Quantization, QuantizerType from acuitylib.interface.inference import Inference # prepare mobilenet = "model/mobilenet_v1.pb" image0 = "data/697.jpg" image1 = "data/813.jpg" labels = [697, 813] # data generator def get_data(): for image in [image0, image1]: arr = tf.io.decode_image(tf.io.read_file(image)).numpy().reshape(1, 224, 224, 3).astype(np.float32) arr = (arr-128.0)/128.0 # preprocess inputs = {'input': np.array(arr, dtype=np.float32)} yield inputs def test_tensorflow_mobilenet(): # load tensorflow model model = TensorflowLoader(mobilenet).load(inputs=['input'], input_size_list=[[1, 224, 224, 3]], outputs=['MobilenetV1/Logits/SpatialSqueeze']) # quantization quantizer = QuantizerType.ASYMMETRIC_AFFINE qtype = 'uint8' Quantization(model).quantize(input_generator_func=get_data, quantizer=quantizer, qtype=qtype, iterations=1) # inference with quant model infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session assert outs[0].flatten()[labels[i]] > 0.99 # export tflite quant case TFLiteExporter(model).export('export_tflite/asymu8/mobilenet.tflite') if __name__ == '__main__': test_tensorflow_mobilenet() ``` -------------------------------- ### Inference Methods Source: https://github.com/verisilicon/acuitylite/blob/main/docs/genindex.html Methods for building and running inference sessions. ```APIDOC ## Inference Methods ### `Inference.build_session()` Builds an inference session. ### `Inference.run_session()` Runs an inference session. ``` -------------------------------- ### Load Darknet Model and Perform Inference Source: https://github.com/verisilicon/acuitylite/blob/main/docs/demo_darknet.html Loads a Darknet model and its weights, then builds an inference session to run predictions on input data. Preprocesses input images by subtracting 128 and dividing by 128. ```python #!/usr/bin/env python3 import tensorflow as tf import numpy as np from acuitylib.interface.importer import DarknetLoader from acuitylib.interface.exporter import TFLiteExporter from acuitylib.interface.quantization import Quantization, QuantizerType from acuitylib.interface.inference import Inference alexnet_model = "model/alexnet2.cfg" alexnet_weights = "model/alexnet2.weights" image0 = "data/space_shuttle_227x227.jpg" # data generator def get_data(): for image in [image0]: arr = tf.io.decode_image(tf.io.read_file(image)).numpy().reshape(1, 3, 227, 227).astype(np.float32) arr = (arr-128.0)/128.0 # preprocess inputs = {'input': np.array(arr, dtype=np.float32)} yield inputs def test_darknet_alexnet(): # load darknet model model = DarknetLoader(model=alexnet_model, weights=alexnet_weights).load() # inference infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session print(outs[0]) # perchanneli8 quantization quantizer = QuantizerType.PERCHANNEL_SYMMETRIC_AFFINE qtype = 'int8' Quantization(model).quantize(input_generator_func=get_data, quantizer=quantizer, qtype=qtype, iterations=1) # inference with quantized model infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session print(outs[0]) # export tflite perchanneli8 case TFLiteExporter(model).export('export_tflite/pcq_symi8/alexnet.tflite') if __name__ == '__main__': test_darknet_alexnet() ``` -------------------------------- ### Importer Methods Source: https://github.com/verisilicon/acuitylite/blob/main/docs/genindex.html Methods for loading models using different importer classes. ```APIDOC ## Importer Methods ### `CaffeLoader.load()` Loads a model using the Caffe loader. ### `DarknetLoader.load()` Loads a model using the Darknet loader. ### `OnnxLoader.load()` Loads a model using the ONNX loader. ### `TensorflowLoader.load()` Loads a model using the TensorFlow loader. ### `TFLiteLoader.load()` Loads a model using the TFLite loader. ``` -------------------------------- ### ONNX SqueezeNet Inference and Export Source: https://github.com/verisilicon/acuitylite/blob/main/docs/demo_onnx.html Loads an ONNX model, performs inference, and exports it to Tim-VX format. Requires the ONNX model and an input image. ```python #!/usr/bin/env python3 import tensorflow as tf import numpy as np from acuitylib.interface.importer import OnnxLoader from acuitylib.interface.exporter import TimVxExporter from acuitylib.interface.exporter import TFLiteExporter from acuitylib.interface.quantization import Quantization, QuantizerType from acuitylib.interface.inference import Inference # prepare onnx_model = "model/squeezenet.onnx" image0 = "data/813.jpg" # data generator def get_data(): for image in [image0]: arr = tf.io.decode_image(tf.io.read_file(image)).numpy() arr = np.transpose(arr, [2, 0, 1]) arr = arr.reshape(1, 3, 224, 224) inputs = {'data_0': np.array(arr, dtype=np.float32)} yield inputs def test_onnx_squeezenet(): # import model model = OnnxLoader(model=onnx_model).load(inputs=['data_0'], input_size_list=[[1, 3, 224, 224]], outputs=['softmaxout_1']) # inference infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session assert np.argmax(outs[0].flatten()) == 812 TimVxExporter(model).export('export_timvx/float16/lenet') # quantize quantizer = QuantizerType.ASYMMETRIC_AFFINE qtype = 'uint8' Quantization(model).quantize(input_generator_func=get_data, quantizer=quantizer, qtype=qtype, iterations=1) # inference with quantized model infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session assert np.argmax(outs[0].flatten()) == 812 # export tim-vx case TimVxExporter(model).export('export_timvx/asymu8/squeezenet') TFLiteExporter(model).export('export_tflite/asymu8/squeezenet.tflite') if __name__ == '__main__': test_onnx_squeezenet() ``` -------------------------------- ### Export to Ovxlib Application Source: https://context7.com/verisilicon/acuitylite/llms.txt Serializes an Acuity model into an Ovxlib C application. Use `pack_nbg_only=True` to generate only the NBG binary without the full C source code. ```python from acuitylib.interface.exporter import OvxlibExporter # Export full Ovxlib application OvxlibExporter(model).export('export_ovxlib/quant/mobilenet') # Export NBG only (using default SDK) OvxlibExporter(model).export( 'export_ovxlib/quant/mobilenet', pack_nbg_only=True ) ``` -------------------------------- ### Load and Test Caffe LeNet Model Source: https://github.com/verisilicon/acuitylite/blob/main/docs/demo_caffe.html Loads a Caffe model, performs float inference, exports to Tim-VX and TFLite, quantizes the model, performs quantized inference, and exports again. ```python #!/usr/bin/env python3 import tensorflow as tf import numpy as np from acuitylib.interface.importer import CaffeLoader from acuitylib.interface.exporter import TimVxExporter, TFLiteExporter from acuitylib.interface.quantization import Quantization, QuantizerType from acuitylib.interface.inference import Inference prototxt \= "model/lenet.prototxt" caffe_model \= "model/lenet.caffemodel" image0 \= "data/0.jpg" image1 \= "data/1.png" # data generator def get_data(): for image in [image0, image1]: arr = tf.io.decode_image(tf.io.read_file(image)).numpy().reshape(1, 1, 28, 28).astype(np.float32) # arr = arr/255.0 # preprocess inputs = {'input': np.array(arr, dtype=np.float32)} yield inputs def test_caffe_lenet(): # load caffe model model = CaffeLoader(model=prototxt, weights=caffe_model).load() # inference with float model infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session assert outs[0].flatten()[i] > 0.99 # export tim-vx float16 case TimVxExporter(model).export('export_timvx/float16/lenet') # export tflite float16 case TFLiteExporter(model).export('export_tflite/float16/lenet.tflite') # perchanneli8 quantization quantizer = QuantizerType.PERCHANNEL_SYMMETRIC_AFFINE qtype = 'int8' Quantization(model).quantize(input_generator_func=get_data, quantizer=quantizer, qtype=qtype, iterations=1) # inference with quantized model infer = Inference(model) infer.build_session() # build inference session for i, data in enumerate(get_data()): ins, outs = infer.run_session(data) # run inference session assert outs[0].flatten()[i] > 0.99 # export tim-vx perchanneli8 case TimVxExporter(model).export('export_timvx/pcq_symi8/lenet') # export tflite perchanneli8 case TFLiteExporter(model).export('export_tflite/pcq_symi8/lenet.tflite') if __name__ == '__main__': test_caffe_lenet() ``` -------------------------------- ### TimVxExporter.export Method Source: https://github.com/verisilicon/acuitylite/blob/main/docs/exporter.tim-vx.html Exports the TIM-VX application to a specified directory with a given prefix. ```APIDOC ## Method: export ### Description Exports TIM-VX application. ### Method Signature ```python export(output, api_def_json_path=None, **kwargs) ``` **Parameters:** * **output** (str) - The directory of the exported applications with the prefix specified. Use the syntax ‘/’. Where: Output directory: The directory of the generated outputs including subdirectories and files. Prefix: The prefix of the generated subdirectories and files. For example, “export_timvx/uint8/lenet” * **api_def_json_path** (str) - Optional. The path to specify TIM-VX api defined json files. **Returns:** [Acuitylite](index.html) ``` -------------------------------- ### OnnxLoader.load Method Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.onnxloader.html Loads the ONNX model, allowing for specification of inputs, input sizes, data types, and outputs. ```APIDOC ## OnnxLoader.load(inputs=None, input_size_list=None, input_dtype_list=None, outputs=None, remove_io_perm=False, compute_arch=0) Load Onnx model. Parameters: * **inputs** – Specify the input points of the TFLite graph, requries list type. Such as [‘input_point_1’, ‘input_point_2’]. When this argument is omitted, Acuity uses all header points of this model. * **input_size_list** – The tensor shape sizes of the input points listed in the inputs argument, requires list type. For example, [[1,3,224,224],[1,12,1]], which represents the tensor shape sizes of two input points. * **input_dtype_list** – Specify the data type of input tensors if it is not float type, requires list type. For example, [‘float’, ‘int8’]. * **outputs** – Specify the output points of the Onnx graph, requries list type. For example, [‘output_point_1’, ‘output_point_2’]. When this argument is omitted, Acuity uses all tail points of this model. Returns: Acuity network. ``` -------------------------------- ### Quantization Module Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/api.rst.txt Handles model quantization operations. ```APIDOC ## Quantization This module provides functionalities for model quantization. ### Quantization Class - **Description**: Class for performing quantization on models. - **Usage**: Instantiate `quantization.Quantization` to access quantization features. ``` -------------------------------- ### load Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.tensorflowloader.html Loads a Tensorflow model, specifying inputs, input sizes, and outputs. ```APIDOC ## importer.TensorflowLoader.load Load Tensorflow model. ### Parameters * **inputs** (list) - Specify the input points of the Tensorflow graph, requires list type. Such as ['input_point_1', 'input_point_2']. * **input_size_list** (list) - The tensor shape sizes of the input points listed in the inputs argument, requires list type. For example, [[1,224,224,3],[1,12,1]], which represents the tensor shape sizes of two input points. * **outputs** (list) - Specify the output points of the Tensorflow graph, requires list type. For example, ['output_point_1', 'output_point_2']. ### Returns Acuity network. ``` -------------------------------- ### importer.TensorflowLoader Source: https://context7.com/verisilicon/acuitylite/llms.txt Load a TensorFlow frozen graph (.pb) into an Acuity network. Input and output nodes, along with their shapes, are required parameters. ```APIDOC ## importer.TensorflowLoader ### Description Translates a TensorFlow `.pb` frozen graph into an Acuity network. `inputs`, `input_size_list`, and `outputs` are all required. ### Method ```python TensorflowLoader(model: str).load(inputs: list, input_size_list: list, outputs: list) ``` ### Parameters #### Path Parameters - **model** (str) - Required - Path to the TensorFlow frozen graph (.pb) file. #### Query Parameters - **inputs** (list) - Required - List of input node names. - **input_size_list** (list) - Required - List of input tensor shapes (e.g., `[[1, 224, 224, 3]]` for NHWC). - **outputs** (list) - Required - List of output node names. ### Response #### Success Response - **AcuityModel** - An Acuity network object. ### Request Example ```python from acuitylib.interface.importer import TensorflowLoader # Load MobileNetV1 frozen graph (NHWC layout) model = TensorflowLoader(model='model/mobilenet_v1.pb').load( inputs=['input'], input_size_list=[[1, 224, 224, 3]], # NHWC outputs=['MobilenetV1/Logits/SpatialSqueeze'] ) ``` ``` -------------------------------- ### importer.DarknetLoader Source: https://context7.com/verisilicon/acuitylite/llms.txt Load a Darknet model by providing paths to its .cfg and .weights files. Both arguments are required for loading. ```APIDOC ## importer.DarknetLoader ### Description Translates a Darknet `.cfg` + `.weights` pair into an Acuity network. Both arguments are required. ### Method ```python DarknetLoader(model: str, weights: str).load() ``` ### Parameters #### Path Parameters - **model** (str) - Required - Path to the Darknet .cfg file. - **weights** (str) - Required - Path to the Darknet .weights file. ### Response #### Success Response - **AcuityModel** - An Acuity network object. ### Request Example ```python from acuitylib.interface.importer import DarknetLoader # Load AlexNet from Darknet format model = DarknetLoader( model='model/alexnet2.cfg', weights='model/alexnet2.weights' ).load() ``` ``` -------------------------------- ### importer.CaffeLoader Source: https://context7.com/verisilicon/acuitylite/llms.txt Load a Caffe model by providing paths to its .prototxt and .caffemodel files. The `proto` argument can specify 'caffe' or 'lstm_caffe' for different layer types. ```APIDOC ## importer.CaffeLoader ### Description Translates a Caffe `.prototxt` + `.caffemodel` pair into an Acuity network object. The optional `proto` argument in `load()` supports `'caffe'` (standard) or `'lstm_caffe'` (LSTM layers). ### Method ```python CaffeLoader(model: str, weights: str).load(proto: str = 'caffe') ``` ### Parameters #### Path Parameters - **model** (str) - Required - Path to the Caffe .prototxt file. - **weights** (str) - Required - Path to the Caffe .caffemodel file. #### Query Parameters - **proto** (str) - Optional - Specifies the Caffe protocol. Accepts 'caffe' or 'lstm_caffe'. Defaults to 'caffe'. ### Response #### Success Response - **AcuityModel** - An Acuity network object. ### Request Example ```python from acuitylib.interface.importer import CaffeLoader # Load standard Caffe LeNet model = CaffeLoader( model='model/lenet.prototxt', weights='model/lenet.caffemodel' ).load(proto='caffe') # Load with LSTM protocol lstm_model = CaffeLoader( model='model/lstm_net.prototxt', weights='model/lstm_net.caffemodel' ).load(proto='lstm_caffe') ``` ``` -------------------------------- ### Run AlexNet Darknet Model Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/demo_darknet.rst.txt Executes the AlexNet model using Darknet. This snippet is part of a demonstration script for integrating Darknet with AcuityLite. ```python import sys import os # Add the parent directory to the Python path to import modules # This is a common setup for running examples in a project structure current_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.dirname(current_dir) sys.path.append(parent_dir) from acuitylite.inference.darknet import Darknet def alexnet_darknet_test(): # Initialize Darknet with the AlexNet model configuration and weights # The model is loaded from specified paths darknet = Darknet(config_file='../cfg/alexnet.cfg', weights_file='../weights/alexnet.weights') # Perform inference on a sample image # The image path is provided, and the result of the inference is returned result = darknet.inference(image_path='../data/dog.jpg') # Print the inference result to the console print(result) if __name__ == '__main__': alexnet_darknet_test() ``` -------------------------------- ### Load TensorFlow Frozen Graph with Acuitylite Source: https://context7.com/verisilicon/acuitylite/llms.txt Loads a TensorFlow frozen graph (.pb) using TensorflowLoader. Requires explicit inputs, input sizes, and outputs. ```python from acuitylib.interface.importer import TensorflowLoader # Load MobileNetV1 frozen graph (NHWC layout) model = TensorflowLoader(model='model/mobilenet_v1.pb').load( inputs=['input'], input_size_list=[[1, 224, 224, 3]], # NHWC outputs=['MobilenetV1/Logits/SpatialSqueeze'] ) # Returns: AcuityModel ``` -------------------------------- ### Inference.run_session Source: https://context7.com/verisilicon/acuitylite/llms.txt Builds and runs a host-side inference session on the Acuity model. Returns input and output pairs for accuracy validation. ```APIDOC ## Inference.Inference — Run a model inference session ### Description Builds and runs a host-side inference session on the Acuity model (float or quantized). Returns a list of `(inputs_tuple, outputs_tuple)` pairs, letting you validate accuracy before exporting. ### Parameters #### inputs - (dict or list) - Input data for the model. Can be a dictionary mapping layer names to NumPy arrays or a list of NumPy arrays. #### return_quantized_data - (bool) - Set to True to get raw quantized integer values. Defaults to False. #### backend - (string) - The backend to use for the inference session. Defaults to 'tensorflow'. ### Request Example ```python import numpy as np import tensorflow as tf from acuitylib.interface.inference import Inference # --- Float inference example (Caffe LeNet on MNIST digits) --- infer = Inference(model) infer.build_session(backend='tensorflow') # default backend for i, data in enumerate(get_data()): # data: dict of {layer_name: np.array} ins, outs = infer.run_session(data) predicted_digit = np.argmax(outs[0].flatten()) print(f"Image {i}: predicted={predicted_digit}, confidence={outs[0].flatten()[i]:.4f}") assert outs[0].flatten()[i] > 0.99 # sanity-check # --- Quantized inference (pass list instead of dict) --- infer_q = Inference(model) # model already quantized infer_q.build_session() for data in get_data(): ins, outs = infer_q.run_session( inputs=data, # list or dict accepted return_quantized_data=False # set True to get raw quantized int values ) print(np.argmax(outs[0])) ``` ``` -------------------------------- ### Quantization Methods Source: https://github.com/verisilicon/acuitylite/blob/main/docs/genindex.html Methods for quantizing models. ```APIDOC ## Quantization Methods ### `Quantization.quantize()` Quantizes a model. ``` -------------------------------- ### Load ONNX Model with Acuitylite Source: https://context7.com/verisilicon/acuitylite/llms.txt Loads an ONNX model using OnnxLoader. Allows explicit specification of input/output nodes and tensor shapes, or auto-detection. ```python from acuitylib.interface.importer import OnnxLoader # Load SqueezeNet with explicit inputs/outputs model = OnnxLoader(model='model/squeezenet.onnx').load( inputs=['data_0'], input_size_list=[[1, 3, 224, 224]], # NCHW outputs=['softmaxout_1'] ) # Returns: AcuityModel # Load with multiple inputs of mixed types model_multi = OnnxLoader(model='model/custom.onnx').load( inputs=['image', 'metadata'], input_size_list=[[1, 3, 224, 224], [1, 12, 1]], input_dtype_list=['float', 'int8'], outputs=['logits'] ) ``` -------------------------------- ### TFLiteLoader.load Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.tfliteloader.html Loads the TFLite model into Acuity, allowing specification of input and output points. ```APIDOC ## load(inputs=None, input_size_list=None, outputs=None, **kwargs) ### Description Loads the TFLite model into Acuity. It allows for the explicit specification of input and output tensor names and their corresponding shapes. If input or output points are not specified, Acuity will infer them from the model. ### Parameters #### Query Parameters - **inputs** (list) - Optional - Specify the input points of the TFLite graph. For example: `['input_point_1', 'input_point_2']`. If omitted, Acuity uses all header points. - **input_size_list** (list) - Optional - The tensor shape sizes of the input points listed in the `inputs` argument. For example: `[[1, 3, 224, 224], [1, 12, 1]]`. - **outputs** (list) - Optional - Specify the output points of the TFLite graph. For example: `['output_point_1', 'output_point_2']`. If omitted, Acuity uses all tail points. ### Returns Acuity network. ``` -------------------------------- ### CaffeLoader.load Method Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.caffeloader.html Loads the Caffe model using the specified protocol. ```APIDOC ## CaffeLoader.load(proto='caffe') ### Description Load Caffe model. ### Parameters * **proto** (string) - Optional - The protocol used by the CaffeLoader, ‘caffe’ for the standard Caffe format protocal, ‘lstm_caffe’ for the LSTM layer protocal. ### Returns Acuity network. ``` -------------------------------- ### Importer Modules Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/api.rst.txt Provides classes for loading models from various frameworks. ```APIDOC ## Importer Classes This section details the available importer classes for loading models from different frameworks. ### CaffeLoader - **Description**: Loads models from the Caffe framework. - **Usage**: Instantiate `importer.CaffeLoader` to use. ### DarknetLoader - **Description**: Loads models from the Darknet framework. - **Usage**: Instantiate `importer.DarknetLoader` to use. ### OnnxLoader - **Description**: Loads models from the ONNX format. - **Usage**: Instantiate `importer.OnnxLoader` to use. ### TensorflowLoader - **Description**: Loads models from the TensorFlow framework. - **Usage**: Instantiate `importer.TensorflowLoader` to use. ### TFLiteLoader - **Description**: Loads models from the TensorFlow Lite format. - **Usage**: Instantiate `importer.TFLiteLoader` to use. ``` -------------------------------- ### TFLiteLoader Constructor Source: https://github.com/verisilicon/acuitylite/blob/main/docs/importer.tfliteloader.html Initializes the TFLiteLoader with the path to the TensorFlow Lite model. ```APIDOC ## TFLiteLoader(model) ### Description Initializes the TFLiteLoader with the path to the TensorFlow Lite model. ### Parameters #### Path Parameters - **model** (string) - Required - The file path of the imported TensorFlow Lite (TFLite) model, in an optimized FlatBuffer format identified by the .tflite file extension. ``` -------------------------------- ### Quantization Class Source: https://github.com/verisilicon/acuitylite/blob/main/docs/_sources/quantization.rst.txt The Quantization class provides methods for model quantization. The `quantize` method is used to perform the quantization process. ```APIDOC ## quantize ### Description Performs model quantization. It's recommended to use 500-1000 pictures for quantization and avoid quantizing already quantized TensorFlow Lite models. ### Method Signature `quantize(input_generator_func, quantizer=QuantizerType.ASYMMETRIC_AFFINE, qtype='uint8', iteration=1, minimize_layer_error=False)` ### Parameters * **input_generator_func** (function) - A function that generates input data. * **quantizer** (QuantizerType, optional) - The quantizer to use. Defaults to `QuantizerType.ASYMMETRIC_AFFINE`. Supports `QuantizerType.ASYMMETRIC_AFFINE` and `QuantizerType.PERCHANNEL_SYMMETRIC_AFFINE`. * **qtype** (string, optional) - The quantization type. Defaults to 'uint8'. Supports 'uint8' for ASYMMETRIC_AFFINE and 'int8' for PERCHANNEL_SYMMETRIC_AFFINE. * **iteration** (int, optional) - The number of sample image batches. Defaults to 1. * **minimize_layer_error** (bool, optional) - If True, minimizes quantization error for improved accuracy at the cost of longer processing time. Defaults to False. ``` -------------------------------- ### Quantization Class Source: https://github.com/verisilicon/acuitylite/blob/main/docs/quantization.html The Quantization class provides methods for quantizing network tensors. It includes a constructor and a quantize method with several configurable parameters. ```APIDOC ## class quantization.Quantization ### Description Provides methods for quantizing network tensors. ### Methods #### __init__(model) Initializes the Quantization object. * **model**: The model to be quantized. #### quantize(input_generator_func, quantizer=QuantizerType.ASYMMETRIC_AFFINE, qtype='uint8', iteration=1, minimize_layer_error=False) Quantizes the network tensors. Usually 500~1000 pictures are needed. Do not perform quantization on acuity networks converted from TensorFlow Lite models that have been quantized. * **input_generator_func** (function) - A function that generates input data. Requires function type. * **quantizer** (QuantizerType) - The quantizer to use. Supports QuantizerType.ASYMMETRIC_AFFINE and QuantizerType.PERCHANNEL_SYMMETRIC_AFFINE. * **qtype** (string) - The quantization type. Supports 'uint8' for ASYMMETRIC_AFFINE and 'int8' for PERCHANNEL_SYMMETRIC_AFFINE. * **iteration** (int) - The number of sample image batches. * **minimize_layer_error** (bool) - If True, minimizes quantization error, improving accuracy but increasing processing time. ``` -------------------------------- ### Export to TIM-VX Application Source: https://context7.com/verisilicon/acuitylite/llms.txt Serializes an Acuity model into a TIM-VX C++ application. Optionally generates an NBG binary by setting `pack_nbg_unify=True`. Custom SDK and license paths can be provided. ```python from acuitylib.interface.exporter import TimVxExporter # Export float16 TIM-VX case (no NBG) TimVxExporter(model).export('export_timvx/float16/lenet') # Export quantized TIM-VX case with bundled NBG (uses default SDK) TimVxExporter(model).export( 'export_timvx/asymu8/squeezenet', pack_nbg_unify=True ) # Export with a custom Vivante SDK and licence TimVxExporter(model).export( 'export_timvx/asymu8/squeezenet', pack_nbg_unify=True, viv_sdk='/path/to/my_sdk', # must contain build/install and prebuilt-sdk/x86_64_linux licence='/path/to/licence.txt' # content = target device string ) ``` -------------------------------- ### Run Float Model Inference Source: https://context7.com/verisilicon/acuitylite/llms.txt Builds and runs a host-side inference session on a float Acuity model. Returns a list of (inputs_tuple, outputs_tuple) pairs for accuracy validation. Requires the model to be built with `infer.build_session(backend='tensorflow')`. ```python import numpy as np import tensorflow as tf from acuitylib.interface.inference import Inference # --- Float inference example (Caffe LeNet on MNIST digits) --- infer = Inference(model) infer.build_session(backend='tensorflow') # default backend for i, data in enumerate(get_data()): # data: dict of {layer_name: np.array} ins, outs = infer.run_session(data) predicted_digit = np.argmax(outs[0].flatten()) print(f"Image {i}: predicted={predicted_digit}, confidence={outs[0].flatten()[i]:.4f}") assert outs[0].flatten()[i] > 0.99 # sanity-check ```