### View Example Source on GitHub Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/recommendation/overview.md View the source code for the recommendation example on GitHub. ```markdown [View source on GitHub](https://github.com/tensorflow/examples/blob/master/lite/examples/recommendation/ml/ondevice_recommendation.ipynb) ``` -------------------------------- ### Run Example in Google Colab Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/recommendation/overview.md Run the recommendation example in Google Colab. ```markdown [Run in Google Colab](https://colab.research.google.com/github/tensorflow/examples/blob/master/lite/examples/recommendation/ml/ondevice_recommendation.ipynb) ``` -------------------------------- ### View TensorFlow.org Example Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/recommendation/overview.md View the recommendation example on TensorFlow.org. ```markdown [View on TensorFlow.org](https://www.tensorflow.org/lite/examples/recommendation/overview) ``` -------------------------------- ### Install the benchmark APK Source: https://github.com/google-ai-edge/litert/blob/main/tflite/tools/benchmark/android/README.md Use ADB to install the generated APK with permissions granted. ```bash adb install -r -d -g bazel-bin/tensorflow/lite/tools/benchmark/android/benchmark_model.apk ``` -------------------------------- ### Install Android SDK Command Line Tools Source: https://github.com/google-ai-edge/litert/blob/main/g3doc/instructions/BUILD_INSTRUCTIONS.md Downloads and installs the Android SDK command-line tools, sets up environment variables, and installs required SDK components. ```bash # Download Android SDK Command Line Tools mkdir -p ~/android-sdk cd ~/android-sdk wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip unzip commandlinetools-linux-9477386_latest.zip # Set up environment export ANDROID_HOME=~/android-sdk export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$PATH export PATH=$ANDROID_HOME/platform-tools:$PATH # Install required SDK components sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.0" "ndk;21.4.7075529" ``` -------------------------------- ### Install Project Requirements Source: https://github.com/google-ai-edge/litert/blob/main/tflite/java/ovic/Winner_OSS_Template.md Use this command to install all necessary dependencies for the project from the requirements.txt file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Hexagon SDK and Tools Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/CUSTOM_OP_INSTRUCTIONS.md Installs specific versions of the Hexagon SDK and Hexagon Tools using the qpm-cli. Ensure you have the correct paths for installation. ```bash # install hexagon sdk 6.4.0 qpm-cli --install hexagonsdk6.x --version 6.4.0.1 --path /path/to/Qualcomm/Hexagon_SDK/hexagon-sdk-6.4.0 # install hexagon sdk 6.5.0 qpm-cli --install hexagonsdk6.x --version 6.5.0.1 --path /path/to/Qualcomm/Hexagon_SDK/hexagon-sdk-6.5.0 # install hexagon tool 21.0 qpm-cli --extract hexagon21.0 --version 21.0.01.1 --path /path/to/Qualcomm/Hexagon_SDK/hexagon-sdk-6.5.0/tools/HEXAGON_Tools/21.0.01.1 ``` -------------------------------- ### Login and Install Hexagon SDK Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/LPAI_INSTRUCTIONS.md Logs into the QPM service and installs the Hexagon SDK. Replace with your actual username. ```bash qpm-cli --login qpm-cli --install HexagonSDK6.x ``` -------------------------------- ### Display Image Examples Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/models/modify/model_maker/image_classification.ipynb Visualizes 25 image examples with their corresponding labels from the dataset. ```python plt.figure(figsize=(10,10)) for i, (image, label) in enumerate(data.gen_dataset().unbatch().take(25)): plt.subplot(5,5,i+1) plt.xticks([]) plt.yticks([]) plt.grid(False) plt.imshow(image.numpy(), cmap=plt.cm.gray) plt.xlabel(data.index_to_label[label.numpy()]) plt.show() ``` -------------------------------- ### Download models for examples Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/r1/convert/cmdline_examples.md Download the MobileNet V1 and Inception V1 models required for the command-line conversion examples. ```bash echo "Download MobileNet V1" curl https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_0.50_128_frozen.tgz \ | tar xzv -C /tmp echo "Download Inception V1" curl https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_2016_08_28_frozen.pb.tar.gz \ | tar xzv -C /tmp ``` -------------------------------- ### Install Model Maker from Source Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/models/modify/model_maker/index.md Steps to clone the repository and perform an editable installation of the package. ```shell git clone https://github.com/tensorflow/examples cd examples/tensorflow_examples/lite/model_maker/pip_package pip install -e . ``` -------------------------------- ### Build and Install Benchmarker App Source: https://github.com/google-ai-edge/litert/blob/main/tflite/java/ovic/README.md Use Bazel to compile the binary and ADB to install the resulting APK onto a connected device. ```bash bazel build -c opt --cxxopt=-Wno-all //tensorflow/lite/java/ovic/demo/app:ovic_benchmarker_binary adb install -r bazel-bin/tensorflow/lite/java/ovic/demo/app/ovic_benchmarker_binary.apk ``` -------------------------------- ### Configure sparse checkout for the example app Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/android/tutorials/question_answer.md These commands configure git to only download the files necessary for the BERT question answering Android example. ```bash cd examples git sparse-checkout init --cone git sparse-checkout set lite/examples/bert_qa/android ``` -------------------------------- ### Install QPM3 Package Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/LPAI_INSTRUCTIONS.md Installs the QPM3 tool from a .deb package. Ensure you have the correct version for your system. ```bash sudo apt install ./qpm3--linux.deb ``` -------------------------------- ### Configure and Build CPU Example Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/examples/cmake_example/source_build_cc_api/README.md Configures and builds the C++ API example for CPU execution. Use this to set up the build environment for CPU-only inference. ```bash cmake -S litert/vendors/examples/cmake_example/source_build_cc_api \ -B /tmp/litert_source_build_cc_api_example \ -DLITERT_ENABLE_GPU=OFF \ -DLITERT_ENABLE_NPU=OFF cmake --build /tmp/litert_source_build_cc_api_example \ --target litert_source_build_cc_api_run_model \ --target litert_source_build_cc_api_no_absl_run_model \ -j ``` -------------------------------- ### LiteRT Qualcomm Integration Build Flow Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/README.md Illustrates the build and run documentation flow for LiteRT Qualcomm integration, starting from prerequisites to device-specific setup. ```mermaid flowchart LR A[PREREQUISITES.md
Install toolchain] --> B[QAIRT_SDK.md
QNN concepts and libraries] B --> C[HTP_INSTRUCTIONS.md
Compile and execute] C -. "IoT target" .-> D[IOT_DEVICE_SETUP.md
Flash oe-linux device] C -. "LPAI target" .-> E[LPAI_INSTRUCTIONS.md
Always-on low-power engine] ``` -------------------------------- ### Get Element Type Size Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/java/org/tensorflow/lite/support/tensorbuffer/TensorBufferFloat.html Returns the size in bytes of a single element in the buffer. For example, returns 4 for a float buffer and 1 for a byte buffer. ```java int getTypeSize() ``` -------------------------------- ### Configure and Build GPU Example Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/examples/cmake_example/source_build_cc_api/README.md Configures and builds the C++ API example for GPU execution, enabling GPU support. This command downloads the latest prebuilt accelerator artifact. ```bash cmake -S litert/vendors/examples/cmake_example/source_build_cc_api \ -B /tmp/litert_source_build_cc_api_gpu_example \ -DLITERT_ENABLE_GPU=ON \ -DLITERT_ENABLE_NPU=OFF cmake --build /tmp/litert_source_build_cc_api_gpu_example \ --target litert_source_build_cc_api_run_model \ --target litert_source_build_cc_api_no_absl_run_model \ -j ``` -------------------------------- ### Enable GPU acceleration in Java Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/android/delegates/gpu_task.md Configure GPU acceleration for Task Library models in Java by calling `useGpu()` on the `BaseOptions.Builder`. This example shows setup for `ObjectDetector`. ```java import org.tensorflow.lite.task.core.BaseOptions import org.tensorflow.lite.task.gms.vision.detector.ObjectDetector BaseOptions baseOptions = BaseOptions.builder().useGpu().build(); ObjectDetectorOptions options = ObjectDetectorOptions.builder() .setBaseOptions(baseOptions) .setMaxResults(1) .build(); val objectDetector = ObjectDetector.createFromFileAndOptions( context, model, options); ``` -------------------------------- ### Serve LiteRT.js Demos Source: https://github.com/google-ai-edge/litert/blob/main/litert/js/README.md Navigate to a demo directory and run the development server. ```bash cd demos/your-demo-directory npm run dev ``` -------------------------------- ### Clone the TensorFlow Examples Repository Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/android/quickstart.md Download the source code for the object detection example from the official GitHub repository. ```bash git clone https://github.com/tensorflow/examples.git ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/examples/cmake_example/source_build_cc_api/CMakeLists.txt Sets the minimum required CMake version and defines the project name and languages. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.20) project(litert_source_build_cc_api_example LANGUAGES CXX C) ``` -------------------------------- ### Build Segmentation Example with Bazel on Host Source: https://github.com/google-ai-edge/litert/blob/main/tensor/examples/segmentation/README.md Builds the segmentation example using Bazel on the host machine. Ensure necessary prebuilts are included for GPU acceleration. ```bash bazel build //tensor/examples/segmentation:segmentation_example ``` -------------------------------- ### Transform Pack Op to Concat and Reshape for GPU Source: https://github.com/google-ai-edge/litert/blob/main/tflite/converter/experimental/tac/README.md This example shows how an unsupported 'Pack' operation on GPU is transformed into 'Concat' and 'Reshape' operations, which are supported. This is part of the Get Alternative Subgraph View Pass. ```mlir func private @func_1_GPU_FLOAT(%arg0: tensor<1xf32>, %arg1: tensor<1xf32>) -> tensor<1xf32> attributes { tac.device = "GPU", tac.inference_type = "FLOAT", tac.interface_name = "func_1" } { %0 = tfl.add %arg0, %arg1 { fused_activation_function = "RELU6", tac.device = "GPU", tac.inference_type = "FLOAT" } : tensor<1xf32> return %0 : tensor<1xf32> } ``` ```mlir func private @func_2_CPU_FLOAT(%arg0: tensor<1xf32>, %arg1: tensor<1xf32>) -> tensor<2x1xf32> attributes { tac.device = "CPU", tac.inference_type = "FLOAT", tac.interface_name = "func_2" } { %0 = "tfl.pack"(%arg0, %arg1) { axis = 0 : i32, tac.device = "CPU", tac.inference_type = "FLOAT", values_count = 2 : i32 } : (tensor<1xf32>, tensor<1xf32>) -> tensor<2x1xf32> return %0 : tensor<2x1xf32> } func private @func_2_GPU_FLOAT(%arg0: tensor<1xf32>, %arg1: tensor<1xf32>) -> tensor<2x1xf32> attributes { tac.device = "GPU", tac.inference_type = "FLOAT", tac.interface_name = "func_2" } { %cst = arith.constant dense<1> : tensor<4xi32> %cst_0 = arith.constant dense<2> : tensor<1xi32> %cst_1 = arith.constant dense<[2, 1]> : tensor<2xi32> %0 = "tfl.reshape"(%arg0, %cst) { tac.device = "GPU", tac.inference_type = "FLOAT" } : (tensor<1xf32>, tensor<4xi32>) -> tensor<1x1x1x1xf32> %1 = "tfl.reshape"(%arg1, %cst) { tac.device = "GPU", tac.inference_type = "FLOAT" } : (tensor<1xf32>, tensor<4xi32>) -> tensor<1x1x1x1xf32> %2 = "tfl.concatenation"(%0, %1) { axis = 3 : i32, fused_activation_function = "NONE", tac.device = "GPU", tac.inference_type = "FLOAT" } : (tensor<1x1x1x1xf32>, tensor<1x1x1x1xf32>) -> tensor<1x1x1x2xf32> %3 = "tfl.reshape"(%2, %cst_0) { tac.device = "GPU", tac.inference_type = "FLOAT" } : (tensor<1x1x1x2xf32>, tensor<1xi32>) -> tensor<2xf32> %4 = "tfl.reshape"(%3, %cst_1) { tac.device = "GPU", tac.inference_type = "FLOAT" } : (tensor<2xf32>, tensor<2xi32>) -> tensor<2x1xf32> return %4 : tensor<2x1xf32> } ``` -------------------------------- ### Configure TFLite Build Options Source: https://github.com/google-ai-edge/litert/blob/main/tflite/CMakeLists.txt Sets various CMake options to enable or disable specific features and delegates for the TensorFlow Lite build. These options control functionalities like installation, examples, delegates, and testing. ```cmake set(CMAKE_MODULE_PATH "${TFLITE_SOURCE_DIR}/tools/cmake/modules" ${CMAKE_MODULE_PATH} ) set(CMAKE_PREFIX_PATH "${TFLITE_SOURCE_DIR}/tools/cmake/modules" ${CMAKE_PREFIX_PATH} ) include(GNUInstallDirs) include(CMakeDependentOption) option(TFLITE_ENABLE_INSTALL "Enable install rule" OFF) option(TFLITE_ENABLE_LABEL_IMAGE "Enable label_image example" OFF) option(TFLITE_ENABLE_BENCHMARK_MODEL "Enable the benchmark_model tool" OFF) option(TFLITE_ENABLE_RUY "Enable experimental RUY integration" OFF) option(TFLITE_ENABLE_RESOURCE "Enable experimental support for resources" ON) option(TFLITE_ENABLE_NNAPI "Enable NNAPI (Android only)." ON) cmake_dependent_option(TFLITE_ENABLE_NNAPI_VERBOSE_VALIDATION "Enable NNAPI verbose validation." OFF "TFLITE_ENABLE_NNAPI" ON) option(TFLITE_ENABLE_MMAP "Enable MMAP (unsupported on Windows)" ON) option(TFLITE_ENABLE_GPU "Enable GPU" OFF) option(TFLITE_ENABLE_METAL "Enable Metal delegate (iOS only)" OFF) option(TFLITE_ENABLE_XNNPACK "Enable XNNPACK backend" ON) option(TFLITE_ENABLE_EXTERNAL_DELEGATE "Enable External Delegate backend" ON) option(TFLITE_KERNEL_TEST "Enable tflite kernel unit test" OFF) ``` -------------------------------- ### Initialize LiteRT, Load Tokenizer and Weights Source: https://github.com/google-ai-edge/litert/blob/main/tensor/wasm/demo/gemma3/gemma3_demo.html Sets up the WebGPU device, initializes LiteRT, loads the tokenizer, and downloads model weights. Includes progress callbacks for download and loading. ```javascript import { createLiteRT } from '../../tensor_wasm.js'; import { Gemma3GraphBuilder } from './gemma3_graph.js'; import { SafetensorsLoader } from './safetensors.js'; import { embeddingLookupCpuFP32, embeddingLookupCpuINT4, computeRopeCosSinForPosition, loadTokenizer, loadWeights } from './gemma3_utils.js'; import { Gemma3Runner } from './gemma3_runner.js'; async function init() { const infoDiv = document.getElementById('info'); const outputDiv = document.getElementById('output'); infoDiv.textContent = "Loading LiteRT and Tokenizer WASM..."; try { if (!navigator.gpu) { throw new Error("WebGPU is not supported in this browser."); } const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice({ requiredLimits: { maxBufferSize: 671088640, maxStorageBufferBindingSize: 671088640 } }); window.gpuDevice = device; const litert = await createLiteRT({ preinitializedWebGPUDevice: device }); window.litert = litert; infoDiv.textContent = "Loading tokenizer model..."; const tokenizer = await loadTokenizer(createTokenizerModule, './tokenizer.model?v=1000'); infoDiv.textContent = "Downloading weights: 0%"; const modelUrl = 'https://huggingface.co/pyu10055/gemma3_270m_qpc/resolve/main/model_litert_qpc.safetensors'; const weights = await loadWeights( litert, device, modelUrl, (loaded, total) => { infoDiv.textContent = `Downloading weights: ${(loaded / total * 100).toFixed(1)}% `; }, (weightName) => { infoDiv.textContent = `Loading weight: ${weightName} `; } ); const config = { vocab_size: 262144, emb_dim: 640, hidden_dim: 2048, head_dim: 256, n_heads: 4, n_layers: 18, n_kv_groups: 1, sliding_window: 512, sliding_window_pattern: 6, rms_norm_eps: 1e-5, query_pre_attn_scalar: 256.0, rope_global_base: 1000000.0, rope_local_base: 10000.0 }; const builder = new Gemma3GraphBuilder(litert, config); infoDiv.textContent = "Setting up persistent Gemma 3 model runner (WebGPU accelerated)..."; const backend = "gpu"; const useGpu = true; const runner = new Gemma3Runner(litert, window.gpuDevice, tokenizer, weights, config, useGpu); console.log("Persistent setup: Calling runner.setup()..."); await runner.setup(); console.log("Persistent setup: runner.setup() completed successfully!"); window.runner = runner; infoDiv.textContent = "Ready."; document.getElementById('generateBtn').addEventListener('click', async () => { const prompt = document.getElementById('prompt').value; const wrappedPrompt = `user\n${prompt}\nmodel\n`; outputDiv.textContent = "Tokenizing...\n"; const tokens = tokenizer.Encode(wrappedPrompt, true); const tokenIds = []; for (let i = 0; i < tokens.size(); ++i) { tokenIds.push(tokens.get(i)); } console.log("WASM Token IDs:", tokenIds.join(" ")); outputDiv.textContent += `Prompt tokens: ${tokens.size()}\n`; outputDiv.textContent += `Selected Backend: WebGPU (Persistent execution context unblocked)\n`; // Fast-reset the KV cache variables state from prior clicks passes loops! await window.runner.resetKVCache(); console.log("Calling inferences prefill passes..."); outputDiv.textContent += "Processing prompt...\n"; const prefillStart = performance.now(); const nextToken = await window.runner.prefill(tokens); const prefillEnd = performance.now(); const prefillMs = prefillEnd - prefillStart; outputDiv.textContent += `Predicted first token: ${nextToken} (${tokenizer.DecodeToken(nextToken)})\n`; outputDiv.textContent += "Starting decode loop...\n"; let decodeTokensCount = 0; const decodeStart = performance.now(); const maxDecodeTokens = 512 - tokens.size(); await window.runner.decode(nextToken, maxDecodeTokens, (tokenStr) => { outputDiv.textContent += tokenStr; decodeTokensCount++; }); const decodeEnd = performance.now(); const decodeMs = decodeEnd - decodeStart; outputDiv.textContent += "\nGeneration complete.\n"; outputDiv.textContent += `\n--- Performance ---`; outputDiv.textContent += `\nPrefill: processed ${tokens.size()} tokens in ${prefillMs.toFixed(1)} ms (${(prefillMs / tokens.size()).toFixed(1)} ms/tok)`; if (decodeTokensCount > 0) { outputDiv.textContent += `\nDecode: generated ${decodeTokensCount} tokens in ${decodeMs.toFixed(1)} ms (${(decodeMs / decodeTokensCount).toFixed(1)} ms/tok)\n`; } }); } catch (err) { console.error(err); infoDiv.textContent = `Error: ${err.message}`; } } init(); ``` -------------------------------- ### Install Bazelisk on Linux Source: https://github.com/google-ai-edge/litert/blob/main/g3doc/instructions/BUILD_INSTRUCTIONS.md Installs Bazelisk on Linux by downloading the binary, making it executable, and moving it to the system's PATH. ```bash # Linux curl -LO https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64 chmod +x bazelisk-linux-amd64 sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel ``` -------------------------------- ### Download MoveNet Model and Inference Code Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/tutorials/pose_classification.ipynb Downloads the MoveNet Thunder model in TFLite format and clones the TensorFlow examples repository to access pose estimation inference and visualization logic. This setup is crucial for detecting body keypoints. ```python #@title Functions to run pose estimation with MoveNet #@markdown You'll download the MoveNet Thunder model from [TensorFlow Hub](https://www.google.com/url?sa=D&q=https%3A%2F%2Ftfhub.dev%2Fs%3Fq%3Dmovenet), and reuse some inference and visualization logic from the [MoveNet Raspberry Pi (Python)](https://github.com/tensorflow/examples/tree/master/lite/examples/pose_estimation/raspberry_pi) sample app to detect landmarks (ear, nose, wrist etc.) from the input images. #@markdown *Note: You should use the most accurate pose estimation model (i.e. MoveNet Thunder) to detect the keypoints and use them to train the pose classification model to achieve the best accuracy. When running inference, you can use a pose estimation model of your choice (e.g. either MoveNet Lightning or Thunder).* # Download model from TF Hub and check out inference code from GitHub !wget -q -O movenet_thunder.tflite https://tfhub.dev/google/lite-model/movenet/singlepose/thunder/tflite/float16/4?lite-format=tflite !git clone https://github.com/tensorflow/examples.git pose_sample_rpi_path = os.path.join(os.getcwd(), 'examples/lite/examples/pose_estimation/raspberry_pi') sys.path.append(pose_sample_rpi_path) ``` -------------------------------- ### Per-Graph Backend Configuration Example Source: https://github.com/google-ai-edge/litert/blob/main/litert/tools/flags/vendors/README_intel_openvino_flags.md This C++ example shows how to configure different OpenVINO backends for specific graph partitions. It sets the first graph (index 0) to use the 'npu' backend and the second graph (index 1) to use the 'cpu' backend. ```cpp #include "litert/tools/flags/vendors/intel_openvino_flags.h" #include "litert/tools/flags/flags.h" #include "litert/runtime/runtime.h" int main(int argc, char** argv) { // Parse flags, including Intel OpenVINO specific flags. litert::Flags::Init(argc, argv); // Example: Set per-graph backends. // Graph 0 will use NPU, Graph 1 will use CPU. // Partitions without an entry default to NPU. litert::SetIntelOpenVinoGraphBackends("0:npu;1:cpu"); // Initialize LiteRT runtime with parsed flags. litert::Runtime runtime; // ... rest of your LiteRT application ... return 0; } ``` -------------------------------- ### Install Prerequisites for Linux Workstation Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/HTP_INSTRUCTIONS.md Ensure your Linux workstation has the necessary locale and packages installed before proceeding with the eSDK installation. ```bash sudo locale-gen en_US.UTF-8 sudo apt update sudo apt install gawk ``` -------------------------------- ### Create and Load TensorAudio Instance (Kotlin) Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/java/org/tensorflow/lite/support/audio/TensorAudio.html Example of creating a TensorAudio instance and loading new data. Ensure the interpreter is ready to run. ```kotlin val tensor = TensorAudio.create(format, modelInputLength) tensor.load(newData) interpreter.run(tensor.getTensorBuffer(), outputBuffer); ``` -------------------------------- ### Build and Deploy Sample Stable Delegate Source: https://github.com/google-ai-edge/litert/blob/main/tflite/tools/benchmark/experimental/delegate_performance/android/README.md Builds the sample stable delegate using Bazel, sets permissions, and pushes it to the device's delegate performance directory. Ensure the delegateperformance files path exists before pushing. ```bash bazel build -c opt \ --config=android_arm64 \ tensorflow/lite/delegates/utils/experimental/sample_stable_delegate:tensorflowlite_sample_stable_delegate ``` ```bash # Set the permissions so that we can overwrite a previously installed delegate. chmod 755 bazel-bin/tensorflow/lite/delegates/utils/experimental/sample_stable_delegate/libtensorflowlite_sample_stable_delegate.so ``` ```bash # Ensure the delegateperformance files path exists. adbshell run-as org.tensorflow.lite.benchmark.delegateperformance mkdir -p /data/data/org.tensorflow.lite.benchmark.delegateperformance/files ``` ```bash # Install the sample delegate. adb push \ bazel-bin/tensorflow/lite/delegates/utils/experimental/sample_stable_delegate/libtensorflowlite_sample_stable_delegate.so \ /data/local/tmp/ adb shell run-as org.tensorflow.lite.benchmark.delegateperformance \ cp /data/local/tmp/libtensorflowlite_sample_stable_delegate.so \ /data/data/org.tensorflow.lite.benchmark.delegateperformance/files/ ``` -------------------------------- ### Install Model Tester Source: https://github.com/google-ai-edge/litert/blob/main/litert/js/apps/model_tester/README.md Install Model Tester using npm. This command installs the necessary package for using the model tester. ```bash npm i @litertjs-model-tester ``` -------------------------------- ### Configure Ubuntu Packages Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/IOT_DEVICE_SETUP.md Installs necessary packages and updates the system after Ubuntu has been flashed onto the device. This includes adding a PPA and installing QNN-related libraries. ```bash sudo apt-add-repository -s ppa:ubuntu-qcom-iot/qcom-ppa sudo apt update && sudo apt upgrade sudo apt install libatomic1 sudo apt install libqnn1 qnn-tools libqnn-dev ``` -------------------------------- ### Add Subdirectory for Label Image Example Source: https://github.com/google-ai-edge/litert/blob/main/tflite/CMakeLists.txt Adds the subdirectory for the label_image example. This is a common example demonstrating image classification with TFLite. ```cmake add_subdirectory(${TFLITE_SOURCE_DIR}/examples/label_image) ``` -------------------------------- ### Build and Run Benchmark Tool with Dummy Delegate Source: https://github.com/google-ai-edge/litert/blob/main/tflite/delegates/utils/dummy_delegate/README.md Build the benchmark binary and specify command-line flags to apply the dummy delegate when running the benchmark tool. ```bash bazel build -c opt tensorflow/lite/delegates/utils/dummy_delegate:benchmark_model_plus_dummy_delegate # Setting --use_dummy_delegate=true will apply the dummy delegate to the # TFLite model graph. bazel-bin/tensorflow/lite/delegates/utils/dummy_delegate/benchmark_model_plus_dummy_delegate --graph=/tmp/mobilenet-v2.tflite --use_dummy_delegate=true ``` -------------------------------- ### Install TensorFlow Lite Library and Headers Source: https://github.com/google-ai-edge/litert/blob/main/tflite/CMakeLists.txt Installs the TensorFlow Lite library, archives, and header files to the appropriate system locations when installation is enabled. ```cmake if(TFLITE_ENABLE_INSTALL) install( TARGETS tensorflow-lite EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) foreach(hdr ${_ALL_TFLITE_HDRS}) get_filename_component(dir ${hdr} DIRECTORY) file(RELATIVE_PATH dir ${CMAKE_CURRENT_SOURCE_DIR} ${dir}) install( FILES ${hdr} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tensorflow/lite/${dir}" ) endforeach() install( EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) endif() ``` -------------------------------- ### Install libffi7 Package Source: https://github.com/google-ai-edge/litert/blob/main/tflite/examples/minimal/README.md Installs the libffi7 package, which may be required on certain Ubuntu versions. Download the .deb file and install it using dpkg. ```sh wget http://es.archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi7_3.3-4_amd64.deb sudo dpkg -i libffi7_3.3-4_amd64.deb ``` -------------------------------- ### Initialize LiteRT and WebGPU Source: https://github.com/google-ai-edge/litert/blob/main/tensor/wasm/demo/game_of_life_demo.html Sets up the WebGPU environment and initializes the LiteRT WebAssembly module. Ensures WebGPU support and requests an adapter and device. ```javascript import { createLiteRT } from '../tensor_wasm.js'; async function runDemo() { const infoDiv = document.getElementById('info'); const perfDiv = document.getElementById('perf'); const canvas = document.getElementById('outputCanvas'); const ctx = canvas.getContext('2d'); // Request WebGPU adapter and device if (!navigator.gpu) { infoDiv.textContent = "Error: WebGPU is not supported by this browser."; return; } const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); infoDiv.textContent = "Initializing LiteRT WASM module..."; // Load the LiteRT WebAssembly module cleanly using createLiteRT! const litert = await createLiteRT({ preinitializedWebGPUDevice: device }); ``` -------------------------------- ### Convert Examples to Features Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/python/tflite_model_maker/text_classifier/AverageWordVecSpec.md Converts input examples into features and writes them to a TFRecord file. Requires examples, a TFRecord file path, and label names. ```python convert_examples_to_features( examples, tfrecord_file, label_names ) ``` -------------------------------- ### Initialize Interpreter and Restore Weights in Python Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/on_device_training/overview.ipynb Sets up a new interpreter and prepares the 'infer' and 'restore' signature runners. ```python another_interpreter = tf.lite.Interpreter(model_content=tflite_model) another_interpreter.allocate_tensors() infer = another_interpreter.get_signature_runner("infer") restore = another_interpreter.get_signature_runner("restore") ``` -------------------------------- ### Install Required Packages Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/models/modify/model_maker/object_detection.ipynb Installs the Model Maker package, pycocotools for evaluation, and specific versions of OpenCV and TensorFlow. Ensure you have the necessary permissions for apt installations. ```python #@title Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ``` ```bash !sudo apt -y install libportaudio2 !pip install -q --use-deprecated=legacy-resolver tflite-model-maker !pip install -q pycocotools !pip install -q opencv-python-headless==4.1.2.30 !pip uninstall -y tensorflow && pip install -q tensorflow==2.8.0 ``` -------------------------------- ### Add Subdirectory for TF Example Proto Source: https://github.com/google-ai-edge/litert/blob/main/tflite/CMakeLists.txt Adds the TensorFlow example directory, generating proto files within the specified binary directory. This is for TensorFlow-specific examples. ```cmake add_subdirectory(${TF_SOURCE_DIR}/core/example ${CMAKE_BINARY_DIR}/example_proto_generated) ``` -------------------------------- ### Example Usage of --intel_openvino_configs_map Source: https://github.com/google-ai-edge/litert/blob/main/litert/tools/flags/vendors/README_intel_openvino_flags.md Demonstrates how to pass custom OpenVINO configuration properties using the --intel_openvino_configs_map flag. This allows for fine-grained control over inference precision, caching, and stream parallelism. ```bash ./your_binary --intel_openvino_configs_map="INFERENCE_PRECISION_HINT=f16,CACHE_DIR=/tmp/ov_cache,NUM_STREAMS=2" ``` -------------------------------- ### Download and Install eSDK for IoT Device Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/HTP_INSTRUCTIONS.md Download the appropriate eSDK for your target IoT device and install it on your Linux workstation. Ensure sufficient space is reserved for the installation. ```bash adb shell "uname -a" cd ${IOT_DIR} wget https://artifacts.codelinaro.org/artifactory/qli-ci/flashable-binaries/qimpsdk/qcs8275-iq-8275-evk-pro-sku/x86-qcom-6.6.119-QLI.1.8-Ver.1.0_qim-product-sdk-esdk-2.3.0.zip unzip x86-qcom-6.6.119-QLI.1.8-Ver.1.0_qim-product-sdk-esdk-2.3.0.zip cd target/ umask a+rx sh ./qcs8275-iq-8275-evk-pro-sku/sdk/qcom-wayland-x86_64-qcom-multimedia-image-armv8-2a-qcs8275-iq-8275-evk-pro-sku-toolchain-ext-1.8-ver.1.0.sh ``` -------------------------------- ### Initialize LiteRT and Setup Camera Source: https://github.com/google-ai-edge/litert/blob/main/tensor/wasm/demo/segmentation_demo.html Requests WebGPU adapter and device, loads the LiteRT WASM module, and sets up the live camera feed. Ensure your browser supports WebGPU. ```typescript import { createLiteRT } from '../tensor_wasm.js'; async function runDemo() { const infoDiv = document.getElementById('info'); // Request WebGPU adapter and device if (!navigator.gpu) { infoDiv.textContent = "Error: WebGPU is not supported by this browser."; return; } const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); // Load the LiteRT WebAssembly sandbox module const litert = await createLiteRT({ preinitializedWebGPUDevice: device }); infoDiv.textContent = "WebAssembly & WebGPU initialized. Setting up camera feed..."; // Load selfie multiclass segmentation model const modelUrl = "selfie_multiclass_256x256.tflite"; const response = await fetch(modelUrl); const modelBytes = await response.arrayBuffer(); // Setup live camera feed const video = document.getElementById('webcam'); const stream = await navigator.mediaDevices.getUserMedia({ video: { width: 512, height: 512 } }); video.srcObject = stream; await video.play(); ``` -------------------------------- ### Download and Prepare Ubuntu Image Files Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/IOT_DEVICE_SETUP.md This snippet downloads the Ubuntu firmware, DTB, and image files, then organizes them into an 'image' directory. Ensure you are in the IOT_DIR before executing. ```bash cd ${IOT_DIR} mkdir image wget https://artifacts.codelinaro.org/artifactory/qli-ci/flashable-binaries/ubuntu-fw/QCS8300/QLI.1.7-Ver.1.1/QLI.1.7-Ver.1.1-ubuntu-QCS8300-nhlos-bins.tar.gz tar -xvzf ./QLI.1.7-Ver.1.1-ubuntu-QCS8300-nhlos-bins.tar.gz cp -r ./QLI.1.7-Ver.1.1-ubuntu-QCS8300-nhlos-bins/* ./image/ wget https://people.canonical.com/~platform/images/qualcomm-iot/ubuntu-24.04/ubuntu-24.04-x08/ubuntu-desktop-24.04/dtb.bin mv ./dtb.bin ./image/ wget https://people.canonical.com/~platform/images/qualcomm-iot/ubuntu-24.04/ubuntu-24.04-x08/ubuntu-desktop-24.04/iot-qualcomm-dragonwing-classic-desktop-2404-x08-20260210.4096b.img.xz unxz ./iot-qualcomm-dragonwing-classic-desktop-2404-x08-20260210.4096b.img.xz mv ./iot-qualcomm-dragonwing-classic-desktop-2404-x08-20260210.4096b.img ./image/ wget https://people.canonical.com/~platform/images/qualcomm-iot/ubuntu-24.04/ubuntu-24.04-x08/ubuntu-desktop-24.04/rawprogram0.xml mv ./rawprogram0.xml ./image/ ``` -------------------------------- ### Build Gemma3 LiteRT Example with Bazel Source: https://github.com/google-ai-edge/litert/blob/main/tensor/examples/gemma3/README.md Build the litert_main executable from the repository root using Bazel. ```sh bazel build //tensor/examples/gemma3:litert_main ``` -------------------------------- ### Install Dependencies Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/models/modify/model_maker/image_classification.ipynb Install the required system library and the tflite-model-maker package. ```python !sudo apt -y install libportaudio2 !pip install -q tflite-model-maker ``` -------------------------------- ### Constructor: AudioPropertiesStart Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/python/tflite_support/metadata_schema_py_generated/AudioPropertiesStart.md Initializes the AudioPropertiesStart object with a builder instance. ```APIDOC ## Constructor: AudioPropertiesStart ### Description Initializes a new instance of the AudioPropertiesStart class, which is part of the LiteRT metadata schema generation. ### Method Constructor ### Parameters #### Arguments - **builder** (object) - Required - The builder instance used to construct the metadata schema object. ### Request Example ```python import tflite_support.metadata_schema_py_generated as schema # Example usage audio_props = schema.AudioPropertiesStart(builder) ``` ``` -------------------------------- ### Install Bazelisk Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/PREREQUISITES.md Download and install the Bazelisk package for x86_64 Linux. ```bash wget https://github.com/bazelbuild/bazelisk/releases/download/v1.28.1/bazelisk-amd64.deb sudo dpkg -i ./bazelisk-amd64.deb ``` -------------------------------- ### Install @litertjs/tfjs-interop dependencies Source: https://github.com/google-ai-edge/litert/blob/main/litert/js/packages/tfjs_interop/README.md Install the required peer dependencies for the package. ```bash npm install @litertjs/core @litertjs/tfjs-interop @tensorflow/tfjs @tensorflow/tfjs-backend-webgpu ``` -------------------------------- ### Install Generated Wheel Source: https://github.com/google-ai-edge/litert/blob/main/tflite/tools/pip_package/README.md Install the resulting wheel file using pip. ```sh pip install --upgrade ``` -------------------------------- ### Build Segmentation Example with CMake on Host Source: https://github.com/google-ai-edge/litert/blob/main/tensor/examples/segmentation/README.md Configures and builds the segmentation example using CMake on the host machine. Set LITERT_ENABLE_GPU to ON for GPU acceleration. ```bash cmake -S litert -B cmake_build/segmentation_host \ -DCMAKE_BUILD_TYPE=Release \ -DLITERT_ENABLE_GPU=ON cmake --build cmake_build/segmentation_host \ --target litert_tensor_segmentation_example \ --parallel ``` -------------------------------- ### Install Dependencies Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/performance/quantization_debugger.ipynb Install the required nightly TensorFlow version and updated datasets. ```bash # Quantization debugger is available from TensorFlow 2.7.0 !pip uninstall -y tensorflow !pip install tf-nightly !pip install tensorflow_datasets --upgrade # imagenet_v2 needs latest checksum ``` -------------------------------- ### Build and run sample app using stable delegate Source: https://github.com/google-ai-edge/litert/blob/main/tflite/delegates/utils/experimental/sample_stable_delegate/README.md Builds and runs a sample application that demonstrates the usage of the sample stable delegate with a TensorFlow Lite model. ```bash bazel run -c opt \ //tensorflow/lite/delegates/utils/experimental/sample_stable_delegate:sample_app_using_stable_delegate \ tensorflow/lite/testdata/add.tflite ``` -------------------------------- ### Installation Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/python/tflite_support.md Instructions on how to install the TensorFlow Lite Support Library using pip. ```APIDOC ## Installation Install the pip package: ``` pip install tflite-support ``` ``` -------------------------------- ### Install TFLite Model Maker Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/python/tflite_model_maker.md Use pip to install the library in your environment. ```bash pip install tflite-model-maker ``` -------------------------------- ### Compile and Build Tools with CMake Source: https://github.com/google-ai-edge/litert/blob/main/litert/vendors/qualcomm/doc/HTP_INSTRUCTIONS.md Initializes CMake build with a default preset and builds the apply_plugin_main tool, QNN compiler plugin, and Litert runtime shared library. This step may download TensorFlow. ```bash cd ${LITERT}/litert # This takes a while to download tensorflow cmake --preset default cmake --build cmake_build --target apply_plugin_main qnn_compiler_plugin litert_runtime_c_api_shared_lib -j8 ``` -------------------------------- ### Stats Start Min Vector Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/api_docs/python/tflite_support/metadata_schema_py_generated.md Function to start a minimum vector for statistics. ```APIDOC ## Stats Start Min Vector ### Function Signature `StatsStartMinVector()` ### Description Initializes a vector to store minimum values for statistics. ``` -------------------------------- ### Copy Prebuilt Library Source: https://github.com/google-ai-edge/litert/blob/main/litert/cc_sdk/README.md Move the prebuilt libLiteRt.so file into the SDK directory structure. ```bash cp /libLiteRt.so /litert_cc_sdk/ ``` -------------------------------- ### Android Recommendation Example Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/recommendation/overview.md Link to the Android sample application demonstrating personalized recommendations. ```markdown [Android example](https://github.com/tensorflow/examples/tree/master/lite/examples/recommendation/android) ``` -------------------------------- ### Install TFLite Support Library Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/models/modify/model_maker/speech_recognition.ipynb Install the required library for accessing TFLite metadata. ```bash ! pip install -q tflite_support ``` -------------------------------- ### Run Segmentation Example with Bazel on Host (GPU) Source: https://github.com/google-ai-edge/litert/blob/main/tensor/examples/segmentation/README.md Executes the segmentation example on the host machine using Bazel, leveraging the GPU accelerator. Adjust DYLD_LIBRARY_PATH for macOS and LD_LIBRARY_PATH for Linux. ```bash DYLD_LIBRARY_PATH=$PWD/bazel-bin/tensor/examples/segmentation/segmentation_example.runfiles/litert_prebuilts/macos_arm64 \ bazel-bin/tensor/examples/segmentation/segmentation_example \ --image_path=tensor/examples/segmentation/image.jpeg \ --core_model_path=tensor/examples/segmentation/selfie_multiclass_256x256.tflite \ --output_dir=/tmp ``` -------------------------------- ### Build Installable Package Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/guide/build_cmake.md Configure the build to generate an installable package for use with find_package. ```sh cmake ../tensorflow_src/tensorflow/lite -DTFLITE_ENABLE_INSTALL=ON \ -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \ -DSYSTEM_FARMHASH=ON \ -DSYSTEM_PTHREADPOOL=ON \ -Dabsl_DIR=/lib/cmake/absl \ -DEigen3_DIR=/share/eigen3/cmake \ -DFlatBuffers_DIR=/lib/cmake/flatbuffers \ -Dgemmlowp_DIR=/lib/cmake/gemmlowp \ -DNEON_2_SSE_DIR=/lib/cmake/NEON_2_SSE \ -Dcpuinfo_DIR=/share/cpuinfo \ -Druy_DIR=/lib/cmake/ruy ``` -------------------------------- ### Install Executable Targets Source: https://github.com/google-ai-edge/litert/blob/main/litert/tools/CMakeLists.txt Installs specified tool executables to the bin directory at runtime. ```cmake install(TARGETS run_model analyze_model apply_plugin_main extract_bytecode RUNTIME DESTINATION bin ) ``` -------------------------------- ### Initialize quantization debugger Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/performance/quantization_debugger.ipynb Sets up the QuantizationDebugger using the converter and a debug dataset. ```python converter = tf.lite.TFLiteConverter.from_keras_model(model) converter.optimizations = [tf.lite.Optimize.DEFAULT] converter.representative_dataset = representative_dataset(ds) # my_debug_dataset should have the same format as my_representative_dataset debugger = tf.lite.experimental.QuantizationDebugger( converter=converter, debug_dataset=representative_dataset(ds)) ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/google-ai-edge/litert/blob/main/litert/js/demos/depth_anything/README.md Creates and activates a Python virtual environment to manage dependencies. ```bash python -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate` ``` -------------------------------- ### Install Bazelisk on macOS Source: https://github.com/google-ai-edge/litert/blob/main/g3doc/instructions/BUILD_INSTRUCTIONS.md Installs Bazelisk on macOS using the Homebrew package manager. ```bash # macOS (via Homebrew) brew install bazelisk ``` -------------------------------- ### Install Conversion Dependencies Source: https://github.com/google-ai-edge/litert/blob/main/litert/js/demos/depth_anything/README.md Installs the necessary Python packages for model conversion and quantization. ```bash pip install litert-torch ai-edge-quantizer transformers huggingface-hub torch pillow requests ``` -------------------------------- ### Recommendation Model Training Tutorial Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/recommendation/overview.md Follow this tutorial to train a recommendation model using your own datasets. ```markdown [tutorial](https://github.com/tensorflow/examples/tree/master/lite/examples/recommendation/ml/ondevice_recommendation.ipynb) ``` -------------------------------- ### Push Assets to Android Device for Segmentation Example Source: https://github.com/google-ai-edge/litert/blob/main/tensor/examples/segmentation/README.md Pushes the built example binary, model, image, and GPU accelerator to a specified directory on the Android device. ```bash DEVICE_DIR=/data/local/tmp/litert_segmentation RUNFILES=bazel-bin/tensor/examples/segmentation/segmentation_example.runfiles GPU_ACCELERATOR_SO=$(find "$RUNFILES" -path '*/android_arm64/libLiteRtClGlAccelerator.so' -print -quit) adb shell "rm -rf $DEVICE_DIR && mkdir -p $DEVICE_DIR" adb push bazel-bin/tensor/examples/segmentation/segmentation_example "$DEVICE_DIR/" adb push tensor/examples/segmentation/image.jpeg "$DEVICE_DIR/" adb push tensor/examples/segmentation/selfie_multiclass_256x256.tflite "$DEVICE_DIR/" adb push "$GPU_ACCELERATOR_SO" "$DEVICE_DIR/" ``` -------------------------------- ### Build Intel OpenVINO Compiler Plugin, Dispatch Library, and Benchmark Tool Source: https://github.com/google-ai-edge/litert/blob/main/docker_build/README.md Use this command to build specific components for the Intel OpenVINO vendor, including the compiler plugin, dispatch library, and the benchmark tool. Ensure Bazel environment is set up. ```bash source /setup_bazel_env.sh bazel ${EXTRA_STARTUP} build //litert/vendors/intel_openvino/compiler:libLiteRtCompilerPlugin_IntelOpenvino.so bazel ${EXTRA_STARTUP} build //litert/vendors/intel_openvino/dispatch:dispatch_api_so bazel ${EXTRA_STARTUP} build //litert/tools:benchmark_model ``` -------------------------------- ### Install EdgeTPU Compiler Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/models/modify/model_maker/object_detection.ipynb Installs the EdgeTPU compiler using apt-get. Ensure you have the necessary permissions. ```bash ! curl https://packages.cloud.google.com/apt/doc/apt_key.gpg | sudo apt-key add - ``` ```bash ! echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list ``` ```bash ! sudo apt-get update ``` ```bash ! sudo apt-get install edgetpu-compiler ``` -------------------------------- ### Display Label Image Sample Help Source: https://github.com/google-ai-edge/litert/blob/main/tflite/examples/label_image/README.md View all supported command-line options for the label_image sample by running it with the '-h' flag. ```bash sargo:/data/local/tmp $ ./label_image -h ``` -------------------------------- ### Install Orbax Export Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/jax_conversion/jax_to_tflite.ipynb Install the Orbax export library, which is used for exporting Jax models. ```python !pip install orbax-export --upgrade ``` -------------------------------- ### Run Label Image Sample with XNNPACK Delegate Source: https://github.com/google-ai-edge/litert/blob/main/tflite/examples/label_image/README.md Run the label_image sample using the XNNPACK delegate. Enable it by setting '-x 1'. ```bash adb shell \ "/data/local/tmp/label_image \ -m /data/local/tmp/mobilenet_v1_1.0_224.tflite \ -i /data/local/tmp/grace_hopper.bmp \ -l /data/local/tmp/labels.txt -x 1" ``` -------------------------------- ### Install required dependencies Source: https://github.com/google-ai-edge/litert/blob/main/tflite/g3doc/examples/jax_conversion/jax_to_tflite_resnet50.ipynb Install the necessary libraries for model export, JAX, and transformer models. ```bash !pip install orbax-export !pip install tf-nightly !pip install --upgrade jax jaxlib !pip install transformers flax ``` -------------------------------- ### Install TensorFlow Nightly Source: https://github.com/google-ai-edge/litert/blob/main/tflite/examples/experimental_new_converter/Keras_LSTM_fusion_Codelab.ipynb Install the latest nightly build of TensorFlow to access the newest features. ```python !pip install tf-nightly ``` -------------------------------- ### Build LiteRT for Host Source: https://github.com/google-ai-edge/litert/blob/main/g3doc/instructions/CMAKE_BUILD_INSTRUCTIONS.md Compile the project for the host environment. ```bash # For Release build: cmake --build cmake_build -j # For Debug build: cmake --build cmake_build_debug -j ``` -------------------------------- ### Install Model Tester Source: https://github.com/google-ai-edge/litert/blob/main/litert/js/README.md Install the LiteRT.js model tester web application using npm. ```bash npm i @litertjs/model-tester ```