├── .github └── workflows │ ├── ci.yml │ ├── issue_comment.yml │ ├── new_issues.yml │ ├── new_prs.yml │ └── upload_component.yml ├── .gitignore ├── .gitlab-ci.yml ├── .gitmodules ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── examples ├── hello_world │ ├── CMakeLists.txt │ ├── README.md │ ├── main │ │ ├── CMakeLists.txt │ │ ├── constants.cc │ │ ├── constants.h │ │ ├── idf_component.yml │ │ ├── main.cc │ │ ├── main_functions.cc │ │ ├── main_functions.h │ │ ├── model.cc │ │ ├── model.h │ │ ├── output_handler.cc │ │ └── output_handler.h │ └── sdkconfig.defaults ├── micro_speech │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── main │ │ ├── CMakeLists.txt │ │ ├── audio_preprocessor_int8_model_data.h │ │ ├── audio_provider.cc │ │ ├── audio_provider.h │ │ ├── command_responder.cc │ │ ├── command_responder.h │ │ ├── feature_provider.cc │ │ ├── feature_provider.h │ │ ├── idf_component.yml │ │ ├── main.cc │ │ ├── main_functions.cc │ │ ├── main_functions.h │ │ ├── micro_features_generator.cc │ │ ├── micro_features_generator.h │ │ ├── micro_model_settings.h │ │ ├── model.cc │ │ ├── model.h │ │ ├── no_micro_features_data.cc │ │ ├── no_micro_features_data.h │ │ ├── recognize_commands.cc │ │ ├── recognize_commands.h │ │ ├── ringbuf.c │ │ ├── ringbuf.h │ │ ├── yes_micro_features_data.cc │ │ └── yes_micro_features_data.h │ ├── sdkconfig.defaults │ └── test_data │ │ ├── CMakeLists.txt │ │ ├── no_1000ms.wav │ │ ├── no_30ms.wav │ │ ├── noise_1000ms.wav │ │ ├── silence_1000ms.wav │ │ ├── yes_1000ms.wav │ │ └── yes_30ms.wav └── person_detection │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── main │ ├── CMakeLists.txt │ ├── Kconfig.projbuild │ ├── app_camera_esp.c │ ├── app_camera_esp.h │ ├── detection_responder.cc │ ├── detection_responder.h │ ├── esp_cli.c │ ├── esp_cli.h │ ├── esp_main.h │ ├── idf_component.yml │ ├── image_provider.cc │ ├── image_provider.h │ ├── main.cc │ ├── main_functions.cc │ ├── main_functions.h │ ├── model_settings.cc │ ├── model_settings.h │ ├── person_detect_model_data.cc │ └── person_detect_model_data.h │ ├── partitions.csv │ ├── sdkconfig.defaults │ ├── sdkconfig.defaults.esp32s2 │ ├── sdkconfig.defaults.esp32s3 │ └── static_images │ ├── CMakeLists.txt │ └── sample_images │ ├── README.md │ ├── image0 │ ├── image1 │ ├── image2 │ ├── image3 │ ├── image4 │ ├── image5 │ ├── image6 │ ├── image7 │ ├── image8 │ └── image9 ├── idf_component.yml ├── scripts ├── build_examples.sh ├── gh_sync_req.txt └── sync_from_tflite_micro.sh ├── signal ├── micro │ └── kernels │ │ ├── delay.cc │ │ ├── delay_flexbuffers_generated_data.h │ │ ├── energy.cc │ │ ├── energy_flexbuffers_generated_data.h │ │ ├── fft_auto_scale_common.cc │ │ ├── fft_auto_scale_kernel.cc │ │ ├── fft_auto_scale_kernel.h │ │ ├── fft_flexbuffers_generated_data.h │ │ ├── filter_bank.cc │ │ ├── filter_bank_flexbuffers_generated_data.h │ │ ├── filter_bank_log.cc │ │ ├── filter_bank_log_flexbuffers_generated_data.h │ │ ├── filter_bank_spectral_subtraction.cc │ │ ├── filter_bank_spectral_subtraction_flexbuffers_generated_data.h │ │ ├── filter_bank_square_root.cc │ │ ├── filter_bank_square_root.h │ │ ├── filter_bank_square_root_common.cc │ │ ├── framer.cc │ │ ├── framer_flexbuffers_generated_data.h │ │ ├── irfft.cc │ │ ├── irfft.h │ │ ├── overlap_add.cc │ │ ├── overlap_add_flexbuffers_generated_data.h │ │ ├── pcan.cc │ │ ├── pcan_flexbuffers_generated_data.h │ │ ├── rfft.cc │ │ ├── rfft.h │ │ ├── stacker.cc │ │ ├── stacker_flexbuffers_generated_data.h │ │ ├── window.cc │ │ └── window_flexbuffers_generated_data.h └── src │ ├── circular_buffer.cc │ ├── circular_buffer.h │ ├── complex.h │ ├── energy.cc │ ├── energy.h │ ├── fft_auto_scale.cc │ ├── fft_auto_scale.h │ ├── filter_bank.cc │ ├── filter_bank.h │ ├── filter_bank_log.cc │ ├── filter_bank_log.h │ ├── filter_bank_spectral_subtraction.cc │ ├── filter_bank_spectral_subtraction.h │ ├── filter_bank_square_root.cc │ ├── filter_bank_square_root.h │ ├── irfft.h │ ├── irfft_float.cc │ ├── irfft_int16.cc │ ├── irfft_int32.cc │ ├── kiss_fft_wrappers │ ├── kiss_fft_common.h │ ├── kiss_fft_float.cc │ ├── kiss_fft_float.h │ ├── kiss_fft_int16.cc │ ├── kiss_fft_int16.h │ ├── kiss_fft_int32.cc │ └── kiss_fft_int32.h │ ├── log.cc │ ├── log.h │ ├── max_abs.cc │ ├── max_abs.h │ ├── msb.h │ ├── msb_32.cc │ ├── msb_64.cc │ ├── overlap_add.cc │ ├── overlap_add.h │ ├── pcan_argc_fixed.cc │ ├── pcan_argc_fixed.h │ ├── rfft.h │ ├── rfft_float.cc │ ├── rfft_int16.cc │ ├── rfft_int32.cc │ ├── square_root.h │ ├── square_root_32.cc │ ├── square_root_64.cc │ ├── window.cc │ └── window.h ├── tensorflow ├── compiler │ └── mlir │ │ └── lite │ │ ├── core │ │ ├── api │ │ │ ├── error_reporter.cc │ │ │ └── error_reporter.h │ │ └── c │ │ │ ├── builtin_op_data.h │ │ │ └── tflite_types.h │ │ ├── kernels │ │ └── internal │ │ │ └── compatibility_macros.h │ │ └── schema │ │ ├── schema_generated.h │ │ ├── schema_utils.cc │ │ └── schema_utils.h └── lite │ ├── builtin_op_data.h │ ├── builtin_ops.h │ ├── c │ ├── builtin_op_data.h │ ├── c_api_types.h │ └── common.h │ ├── context_util.h │ ├── core │ ├── api │ │ ├── error_reporter.h │ │ ├── flatbuffer_conversions.cc │ │ ├── flatbuffer_conversions.h │ │ ├── tensor_utils.cc │ │ └── tensor_utils.h │ ├── c │ │ ├── builtin_op_data.h │ │ ├── c_api_types.h │ │ ├── common.cc │ │ └── common.h │ └── macros.h │ ├── kernels │ ├── internal │ │ ├── common.cc │ │ ├── common.h │ │ ├── compatibility.h │ │ ├── cppmath.h │ │ ├── max.h │ │ ├── min.h │ │ ├── optimized │ │ │ └── neon_check.h │ │ ├── portable_tensor.h │ │ ├── portable_tensor_utils.cc │ │ ├── portable_tensor_utils.h │ │ ├── quantization_util.cc │ │ ├── quantization_util.h │ │ ├── reference │ │ │ ├── add.h │ │ │ ├── add_n.h │ │ │ ├── arg_min_max.h │ │ │ ├── batch_matmul.h │ │ │ ├── batch_to_space_nd.h │ │ │ ├── binary_function.h │ │ │ ├── broadcast_args.h │ │ │ ├── broadcast_to.h │ │ │ ├── ceil.h │ │ │ ├── comparisons.cc │ │ │ ├── comparisons.h │ │ │ ├── concatenation.h │ │ │ ├── conv.h │ │ │ ├── cumsum.h │ │ │ ├── depth_to_space.h │ │ │ ├── depthwiseconv_float.h │ │ │ ├── depthwiseconv_uint8.h │ │ │ ├── dequantize.h │ │ │ ├── div.h │ │ │ ├── elu.h │ │ │ ├── exp.h │ │ │ ├── fill.h │ │ │ ├── floor.h │ │ │ ├── floor_div.h │ │ │ ├── floor_mod.h │ │ │ ├── fully_connected.h │ │ │ ├── hard_swish.h │ │ │ ├── integer_ops │ │ │ │ ├── add.h │ │ │ │ ├── conv.h │ │ │ │ ├── depthwise_conv.h │ │ │ │ ├── fully_connected.h │ │ │ │ ├── l2normalization.h │ │ │ │ ├── logistic.h │ │ │ │ ├── mean.h │ │ │ │ ├── mul.h │ │ │ │ ├── pooling.h │ │ │ │ ├── tanh.h │ │ │ │ └── transpose_conv.h │ │ │ ├── l2normalization.h │ │ │ ├── leaky_relu.h │ │ │ ├── log_softmax.h │ │ │ ├── logistic.h │ │ │ ├── lstm_cell.h │ │ │ ├── maximum_minimum.h │ │ │ ├── mul.h │ │ │ ├── neg.h │ │ │ ├── pad.h │ │ │ ├── pooling.h │ │ │ ├── portable_tensor_utils.cc │ │ │ ├── portable_tensor_utils.h │ │ │ ├── portable_tensor_utils_impl.h │ │ │ ├── prelu.h │ │ │ ├── process_broadcast_shapes.h │ │ │ ├── quantize.h │ │ │ ├── reduce.h │ │ │ ├── requantize.h │ │ │ ├── resize_bilinear.h │ │ │ ├── resize_nearest_neighbor.h │ │ │ ├── round.h │ │ │ ├── select.h │ │ │ ├── slice.h │ │ │ ├── softmax.h │ │ │ ├── space_to_batch_nd.h │ │ │ ├── space_to_depth.h │ │ │ ├── strided_slice.h │ │ │ ├── sub.h │ │ │ ├── tanh.h │ │ │ ├── transpose.h │ │ │ └── transpose_conv.h │ │ ├── runtime_shape.cc │ │ ├── runtime_shape.h │ │ ├── strided_slice_logic.h │ │ ├── tensor_ctypes.cc │ │ ├── tensor_ctypes.h │ │ ├── tensor_utils.cc │ │ └── types.h │ ├── kernel_util.cc │ ├── kernel_util.h │ ├── op_macros.h │ └── padding.h │ ├── micro │ ├── arena_allocator │ │ ├── ibuffer_allocator.h │ │ ├── non_persistent_arena_buffer_allocator.cc │ │ ├── non_persistent_arena_buffer_allocator.h │ │ ├── persistent_arena_buffer_allocator.cc │ │ ├── persistent_arena_buffer_allocator.h │ │ ├── recording_single_arena_buffer_allocator.cc │ │ ├── recording_single_arena_buffer_allocator.h │ │ ├── single_arena_buffer_allocator.cc │ │ └── single_arena_buffer_allocator.h │ ├── compatibility.h │ ├── compression.h │ ├── debug_log.cc │ ├── debug_log.h │ ├── esp │ │ └── micro_time.cc │ ├── fake_micro_context.cc │ ├── fake_micro_context.h │ ├── flatbuffer_utils.cc │ ├── flatbuffer_utils.h │ ├── hexdump.cc │ ├── hexdump.h │ ├── kernels │ │ ├── activation_utils.h │ │ ├── activations.cc │ │ ├── activations.h │ │ ├── activations_common.cc │ │ ├── add.cc │ │ ├── add.h │ │ ├── add_common.cc │ │ ├── add_n.cc │ │ ├── arg_min_max.cc │ │ ├── assign_variable.cc │ │ ├── batch_matmul.cc │ │ ├── batch_matmul.h │ │ ├── batch_matmul_common.cc │ │ ├── batch_to_space_nd.cc │ │ ├── broadcast_args.cc │ │ ├── broadcast_to.cc │ │ ├── call_once.cc │ │ ├── cast.cc │ │ ├── ceil.cc │ │ ├── circular_buffer.cc │ │ ├── circular_buffer.h │ │ ├── circular_buffer_common.cc │ │ ├── circular_buffer_flexbuffers_generated_data.h │ │ ├── comparisons.cc │ │ ├── concatenation.cc │ │ ├── conv.cc │ │ ├── conv.h │ │ ├── conv_common.cc │ │ ├── conv_test.h │ │ ├── cumsum.cc │ │ ├── decompress.cc │ │ ├── decompress.h │ │ ├── decompress_common.cc │ │ ├── depth_to_space.cc │ │ ├── depthwise_conv.cc │ │ ├── depthwise_conv.h │ │ ├── depthwise_conv_common.cc │ │ ├── dequantize.cc │ │ ├── dequantize.h │ │ ├── dequantize_common.cc │ │ ├── detection_postprocess.cc │ │ ├── detection_postprocess_flexbuffers_generated_data.h │ │ ├── div.cc │ │ ├── elementwise.cc │ │ ├── elu.cc │ │ ├── embedding_lookup.cc │ │ ├── esp_nn │ │ │ ├── README.md │ │ │ ├── add.cc │ │ │ ├── conv.cc │ │ │ ├── depthwise_conv.cc │ │ │ ├── fully_connected.cc │ │ │ ├── mul.cc │ │ │ ├── pooling.cc │ │ │ └── softmax.cc │ │ ├── ethosu.cc │ │ ├── ethosu.h │ │ ├── exp.cc │ │ ├── expand_dims.cc │ │ ├── fill.cc │ │ ├── floor.cc │ │ ├── floor_div.cc │ │ ├── floor_mod.cc │ │ ├── fully_connected.cc │ │ ├── fully_connected.h │ │ ├── fully_connected_common.cc │ │ ├── gather.cc │ │ ├── gather_nd.cc │ │ ├── hard_swish.cc │ │ ├── hard_swish.h │ │ ├── hard_swish_common.cc │ │ ├── if.cc │ │ ├── kernel_runner.cc │ │ ├── kernel_runner.h │ │ ├── kernel_util.cc │ │ ├── kernel_util.h │ │ ├── l2_pool_2d.cc │ │ ├── l2norm.cc │ │ ├── leaky_relu.cc │ │ ├── leaky_relu.h │ │ ├── leaky_relu_common.cc │ │ ├── log_softmax.cc │ │ ├── logical.cc │ │ ├── logical.h │ │ ├── logical_common.cc │ │ ├── logistic.cc │ │ ├── logistic.h │ │ ├── logistic_common.cc │ │ ├── lstm_eval.cc │ │ ├── lstm_eval.h │ │ ├── lstm_eval_common.cc │ │ ├── lstm_eval_test.h │ │ ├── lstm_shared.h │ │ ├── maximum_minimum.cc │ │ ├── maximum_minimum.h │ │ ├── micro_ops.h │ │ ├── micro_tensor_utils.cc │ │ ├── micro_tensor_utils.h │ │ ├── mirror_pad.cc │ │ ├── mul.cc │ │ ├── mul.h │ │ ├── mul_common.cc │ │ ├── neg.cc │ │ ├── pack.cc │ │ ├── pad.cc │ │ ├── pad.h │ │ ├── pad_common.cc │ │ ├── pooling.cc │ │ ├── pooling.h │ │ ├── pooling_common.cc │ │ ├── prelu.cc │ │ ├── prelu.h │ │ ├── prelu_common.cc │ │ ├── quantize.cc │ │ ├── quantize.h │ │ ├── quantize_common.cc │ │ ├── read_variable.cc │ │ ├── reduce.cc │ │ ├── reduce.h │ │ ├── reduce_common.cc │ │ ├── reshape.cc │ │ ├── reshape.h │ │ ├── reshape_common.cc │ │ ├── resize_bilinear.cc │ │ ├── resize_nearest_neighbor.cc │ │ ├── round.cc │ │ ├── select.cc │ │ ├── shape.cc │ │ ├── slice.cc │ │ ├── softmax.cc │ │ ├── softmax.h │ │ ├── softmax_common.cc │ │ ├── space_to_batch_nd.cc │ │ ├── space_to_depth.cc │ │ ├── split.cc │ │ ├── split_v.cc │ │ ├── squared_difference.cc │ │ ├── squeeze.cc │ │ ├── strided_slice.cc │ │ ├── strided_slice.h │ │ ├── strided_slice_common.cc │ │ ├── sub.cc │ │ ├── sub.h │ │ ├── sub_common.cc │ │ ├── svdf.cc │ │ ├── svdf.h │ │ ├── svdf_common.cc │ │ ├── tanh.cc │ │ ├── transpose.cc │ │ ├── transpose.h │ │ ├── transpose_common.cc │ │ ├── transpose_conv.cc │ │ ├── transpose_conv.h │ │ ├── unidirectional_sequence_lstm.cc │ │ ├── unidirectional_sequence_lstm.h │ │ ├── unpack.cc │ │ ├── var_handle.cc │ │ ├── while.cc │ │ └── zeros_like.cc │ ├── memory_helpers.cc │ ├── memory_helpers.h │ ├── memory_planner │ │ ├── greedy_memory_planner.cc │ │ ├── greedy_memory_planner.h │ │ ├── linear_memory_planner.cc │ │ ├── linear_memory_planner.h │ │ ├── memory_plan_struct.h │ │ ├── micro_memory_planner.h │ │ ├── non_persistent_buffer_planner_shim.cc │ │ └── non_persistent_buffer_planner_shim.h │ ├── micro_allocation_info.cc │ ├── micro_allocation_info.h │ ├── micro_allocator.cc │ ├── micro_allocator.h │ ├── micro_arena_constants.h │ ├── micro_common.h │ ├── micro_context.cc │ ├── micro_context.h │ ├── micro_graph.h │ ├── micro_interpreter.cc │ ├── micro_interpreter.h │ ├── micro_interpreter_context.cc │ ├── micro_interpreter_context.h │ ├── micro_interpreter_graph.cc │ ├── micro_interpreter_graph.h │ ├── micro_log.cc │ ├── micro_log.h │ ├── micro_mutable_op_resolver.h │ ├── micro_op_resolver.cc │ ├── micro_op_resolver.h │ ├── micro_profiler.cc │ ├── micro_profiler.h │ ├── micro_profiler_interface.h │ ├── micro_resource_variable.cc │ ├── micro_resource_variable.h │ ├── micro_time.cc │ ├── micro_time.h │ ├── micro_utils.cc │ ├── micro_utils.h │ ├── mock_micro_graph.cc │ ├── mock_micro_graph.h │ ├── recording_micro_allocator.cc │ ├── recording_micro_allocator.h │ ├── recording_micro_interpreter.h │ ├── span.h │ ├── static_vector.h │ ├── system_setup.cc │ ├── system_setup.h │ ├── test_helper_custom_ops.cc │ ├── test_helper_custom_ops.h │ ├── test_helpers.cc │ ├── test_helpers.h │ ├── testing │ │ └── micro_test.h │ └── tflite_bridge │ │ ├── flatbuffer_conversions_bridge.cc │ │ ├── flatbuffer_conversions_bridge.h │ │ ├── micro_error_reporter.cc │ │ └── micro_error_reporter.h │ ├── portable_type_to_tflitetype.h │ └── schema │ ├── schema_generated.h │ └── schema_utils.h └── third_party ├── flatbuffers ├── LICENSE └── include │ └── flatbuffers │ ├── allocator.h │ ├── array.h │ ├── base.h │ ├── buffer.h │ ├── buffer_ref.h │ ├── code_generator.h │ ├── code_generators.h │ ├── default_allocator.h │ ├── detached_buffer.h │ ├── file_manager.h │ ├── flatbuffer_builder.h │ ├── flatbuffers.h │ ├── flex_flat_util.h │ ├── flexbuffers.h │ ├── grpc.h │ ├── hash.h │ ├── idl.h │ ├── minireflect.h │ ├── reflection.h │ ├── reflection_generated.h │ ├── registry.h │ ├── stl_emulation.h │ ├── string.h │ ├── struct.h │ ├── table.h │ ├── util.h │ ├── vector.h │ ├── vector_downward.h │ └── verifier.h ├── gemmlowp ├── LICENSE ├── fixedpoint │ ├── fixedpoint.h │ ├── fixedpoint_neon.h │ └── fixedpoint_sse.h └── internal │ └── detect_platform.h ├── kissfft ├── COPYING ├── _kiss_fft_guts.h ├── kiss_fft.c ├── kiss_fft.h └── tools │ ├── kiss_fftr.c │ └── kiss_fftr.h └── ruy └── ruy └── profiler └── instrumentation.h /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # YAML schema for GitHub Actions: 2 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions 3 | # 4 | # Helpful YAML parser to clarify YAML syntax: 5 | # https://yaml-online-parser.appspot.com/ 6 | # 7 | # 8 | # This file contains the workflows that are run periodically to build the examples. 9 | 10 | name: CI 11 | 12 | on: 13 | workflow_dispatch: 14 | push: 15 | branches: 16 | - master 17 | pull_request: 18 | 19 | jobs: 20 | build: 21 | strategy: 22 | matrix: 23 | idf_ver: ["release-v4.4", "release-v5.0", "release-v5.3"] 24 | idf_target: ["esp32", "esp32s2", "esp32s3"] 25 | include: 26 | - idf_ver: "release-v4.4" 27 | idf_target: "esp32c3" 28 | - idf_ver: "release-v5.0" 29 | idf_target: "esp32c2" 30 | runs-on: ubuntu-22.04 31 | container: espressif/idf:${{ matrix.idf_ver }} 32 | steps: 33 | - uses: actions/checkout@v1 34 | with: 35 | submodules: recursive 36 | - name: Build for ${{ matrix.idf_target }} 37 | env: 38 | IDF_TARGET: ${{ matrix.idf_target }} 39 | shell: bash 40 | working-directory: examples 41 | run: | 42 | . ${IDF_PATH}/export.sh 43 | ../scripts/build_examples.sh ${IDF_TARGET} 44 | -------------------------------------------------------------------------------- /.github/workflows/issue_comment.yml: -------------------------------------------------------------------------------- 1 | name: Sync issue comments to JIRA 2 | 3 | # This workflow will be triggered when new issue comment is created (including PR comments) 4 | on: issue_comment 5 | 6 | jobs: 7 | sync_issue_comments_to_jira: 8 | name: Sync Issue Comments to Jira 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Sync issue comments to JIRA 13 | uses: espressif/github-actions/sync_issues_to_jira@master 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | JIRA_PASS: ${{ secrets.JIRA_PASS }} 17 | JIRA_PROJECT: TFMIC 18 | JIRA_COMPONENT: GitHub 19 | JIRA_URL: ${{ secrets.JIRA_URL }} 20 | JIRA_USER: ${{ secrets.JIRA_USER }} 21 | -------------------------------------------------------------------------------- /.github/workflows/new_issues.yml: -------------------------------------------------------------------------------- 1 | name: Sync issues to Jira 2 | 3 | # This workflow will be triggered when a new issue is opened 4 | on: issues 5 | 6 | jobs: 7 | sync_issues_to_jira: 8 | name: Sync issues to Jira 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Sync GitHub issues to Jira project 13 | uses: espressif/github-actions/sync_issues_to_jira@master 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | JIRA_PASS: ${{ secrets.JIRA_PASS }} 17 | JIRA_PROJECT: TFMIC 18 | JIRA_COMPONENT: GitHub 19 | JIRA_URL: ${{ secrets.JIRA_URL }} 20 | JIRA_USER: ${{ secrets.JIRA_USER }} 21 | -------------------------------------------------------------------------------- /.github/workflows/new_prs.yml: -------------------------------------------------------------------------------- 1 | name: Sync remain PRs to Jira 2 | 3 | # This workflow will be triggered every hour, to sync remaining PRs (i.e. PRs with zero comment) to Jira project 4 | # Note that, PRs can also get synced when new PR comment is created 5 | on: 6 | schedule: 7 | - cron: "0 * * * *" 8 | 9 | jobs: 10 | sync_prs_to_jira: 11 | name: Sync PRs to Jira 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@master 15 | - name: Sync PRs to Jira project 16 | uses: espressif/github-actions/sync_issues_to_jira@master 17 | with: 18 | cron_job: true 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 21 | JIRA_PASS: ${{ secrets.JIRA_PASS }} 22 | JIRA_PROJECT: TFMIC 23 | JIRA_COMPONENT: GitHub 24 | JIRA_URL: ${{ secrets.JIRA_URL }} 25 | JIRA_USER: ${{ secrets.JIRA_USER }} 26 | -------------------------------------------------------------------------------- /.github/workflows/upload_component.yml: -------------------------------------------------------------------------------- 1 | name: Upload component to IDF Component Registry 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | upload_components: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@master 13 | - name: Upload esp-tflite-micro 14 | uses: espressif/upload-components-ci-action@v1 15 | with: 16 | namespace: "espressif" 17 | name: "esp-tflite-micro" 18 | version: ${{ github.ref_name }} 19 | api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | managed_components 3 | sdkconfig 4 | sdkconfig.old 5 | dependencies.lock 6 | *.old 7 | *.o 8 | *.s 9 | .DS_Store 10 | *.orig 11 | *.swp 12 | *.out 13 | *.lock 14 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/.gitmodules -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | --- 4 | minimum_pre_commit_version: 3.3.0 5 | default_install_hook_types: [pre-commit,commit-msg] 6 | 7 | repos: 8 | - repo: https://github.com/pre-commit/pre-commit-hooks 9 | rev: v4.3.0 10 | hooks: 11 | - id: trailing-whitespace 12 | - id: end-of-file-fixer 13 | - id: check-executables-have-shebangs 14 | - id: mixed-line-ending 15 | args: ['-f=lf'] 16 | - id: double-quote-string-fixer 17 | 18 | - repo: https://github.com/astral-sh/ruff-pre-commit 19 | # Ruff version. 20 | rev: v0.0.280 21 | hooks: 22 | - id: ruff 23 | args: [--fix, --exit-non-zero-on-fix] 24 | 25 | - repo: https://github.com/pycqa/isort 26 | rev: 5.11.5 27 | hooks: 28 | - id: isort 29 | name: isort (python) 30 | 31 | - repo: https://github.com/pre-commit/mirrors-mypy 32 | rev: 'v1.1.1' # Use the sha / tag you want to point at 33 | hooks: 34 | - id: mypy 35 | additional_dependencies: [] 36 | 37 | - repo: https://github.com/espressif/conventional-precommit-linter 38 | rev: v1.2.1 39 | hooks: 40 | - id: conventional-precommit-linter 41 | stages: [commit-msg] 42 | -------------------------------------------------------------------------------- /examples/hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 3 | project(hello_world) 4 | -------------------------------------------------------------------------------- /examples/hello_world/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Main component of TF Micro project 'micro_speech'. 4 | # 5 | 6 | idf_component_register( 7 | SRCS main.cc main_functions.cc constants.cc output_handler.cc model.cc 8 | PRIV_REQUIRES spi_flash 9 | INCLUDE_DIRS "") 10 | -------------------------------------------------------------------------------- /examples/hello_world/main/constants.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "constants.h" 17 | 18 | // This is a small number so that it's easy to read the logs 19 | const int kInferencesPerCycle = 20; 20 | -------------------------------------------------------------------------------- /examples/hello_world/main/constants.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ 18 | 19 | // This constant represents the range of x values our model was trained on, 20 | // which is from 0 to (2 * Pi). We approximate Pi to avoid requiring additional 21 | // libraries. 22 | const float kXrange = 2.f * 3.14159265359f; 23 | 24 | // This constant determines the number of inferences to perform across the range 25 | // of x values defined above. Since each inference takes time, the higher this 26 | // number, the more time it will take to run through the entire range. The value 27 | // of this constant can be tuned so that one full cycle takes a desired amount 28 | // of time. Since different devices take different amounts of time to perform 29 | // inference, this value should be defined per-device. 30 | extern const int kInferencesPerCycle; 31 | 32 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ 33 | -------------------------------------------------------------------------------- /examples/hello_world/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | espressif/esp-tflite-micro: 3 | version: "*" 4 | override_path: "../../../" 5 | -------------------------------------------------------------------------------- /examples/hello_world/main/main.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "main_functions.h" 20 | 21 | extern "C" void app_main(void) { 22 | setup(); 23 | while (true) { 24 | loop(); 25 | 26 | // trigger one inference every 500ms 27 | vTaskDelay(pdMS_TO_TICKS(500)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/hello_world/main/main_functions.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_ 18 | 19 | // Expose a C friendly interface for main functions. 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // Initializes all data needed for the example. The name is important, and needs 25 | // to be setup() for Arduino compatibility. 26 | void setup(); 27 | 28 | // Runs one iteration of data gathering and inference. This should be called 29 | // repeatedly from the application code. The name needs to be loop() for Arduino 30 | // compatibility. 31 | void loop(); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_ 38 | -------------------------------------------------------------------------------- /examples/hello_world/main/model.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Automatically created from a TensorFlow Lite flatbuffer using the command: 17 | // xxd -i model.tflite > model.cc 18 | 19 | // This is a standard TensorFlow Lite model file that has been converted into a 20 | // C data array, so it can be easily compiled into a binary for devices that 21 | // don't have a file system. 22 | 23 | // See train/README.md for a full description of the creation process. 24 | 25 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ 26 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ 27 | 28 | extern const unsigned char g_model[]; 29 | extern const int g_model_len; 30 | 31 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ 32 | -------------------------------------------------------------------------------- /examples/hello_world/main/output_handler.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "output_handler.h" 17 | #include "tensorflow/lite/micro/micro_log.h" 18 | 19 | void HandleOutput(float x_value, float y_value) { 20 | // Log the current X and Y values 21 | MicroPrintf("x_value: %f, y_value: %f", static_cast(x_value), 22 | static_cast(y_value)); 23 | } 24 | -------------------------------------------------------------------------------- /examples/hello_world/main/output_handler.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ 18 | 19 | #include "tensorflow/lite/c/common.h" 20 | 21 | // Called by the main loop to produce some output based on the x and y values 22 | void HandleOutput(float x_value, float y_value); 23 | 24 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ 25 | -------------------------------------------------------------------------------- /examples/hello_world/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 16 | CONFIG_FLASHMODE_QIO=y 17 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 18 | CONFIG_INT_WDT= 19 | CONFIG_TASK_WDT= 20 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 21 | -------------------------------------------------------------------------------- /examples/micro_speech/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | set(EXTRA_COMPONENT_DIRS test_data) 3 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 4 | project(micro_speech) 5 | -------------------------------------------------------------------------------- /examples/micro_speech/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Main component of TF Micro project 'micro_speech'. 4 | # 5 | 6 | idf_component_register( 7 | SRCS main.cc main_functions.cc audio_provider.cc feature_provider.cc 8 | no_micro_features_data.cc yes_micro_features_data.cc 9 | model.cc recognize_commands.cc command_responder.cc 10 | micro_features_generator.cc ringbuf.c 11 | PRIV_REQUIRES spi_flash driver esp_timer test_data 12 | INCLUDE_DIRS "") 13 | 14 | # Reduce the level of paranoia to be able to compile sources 15 | target_compile_options(${COMPONENT_LIB} PRIVATE 16 | -Wno-maybe-uninitialized 17 | -Wno-missing-field-initializers 18 | -Wno-error=sign-compare 19 | -Wno-error=double-promotion 20 | -Wno-type-limits) 21 | -------------------------------------------------------------------------------- /examples/micro_speech/main/command_responder.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "command_responder.h" 17 | #include "tensorflow/lite/micro/micro_log.h" 18 | 19 | // The default implementation writes out the name of the recognized command 20 | // to the error console. Real applications will want to take some custom 21 | // action instead, and should implement their own versions of this function. 22 | void RespondToCommand(int32_t current_time, const char* found_command, 23 | float score, bool is_new_command) { 24 | if (is_new_command) { 25 | MicroPrintf("Heard %s (%.4f) @%dms", found_command, score, current_time); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/micro_speech/main/command_responder.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Provides an interface to take an action based on an audio command. 17 | 18 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_ 19 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_ 20 | 21 | #include "tensorflow/lite/c/common.h" 22 | 23 | // Called every time the results of an audio recognition run are available. The 24 | // human-readable name of any recognized command is in the `found_command` 25 | // argument, `score` has the numerical confidence, and `is_new_command` is set 26 | // if the previous command was different to this one. 27 | void RespondToCommand(int32_t current_time, const char* found_command, 28 | float score, bool is_new_command); 29 | 30 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_ 31 | -------------------------------------------------------------------------------- /examples/micro_speech/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | espressif/esp-tflite-micro: 3 | version: "*" 4 | override_path: "../../../" 5 | -------------------------------------------------------------------------------- /examples/micro_speech/main/main.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "esp_log.h" 21 | #include "esp_system.h" 22 | #include "freertos/FreeRTOS.h" 23 | #include "freertos/task.h" 24 | #include "main_functions.h" 25 | 26 | void tf_main(void) { 27 | setup(); 28 | while (true) { 29 | loop(); 30 | } 31 | } 32 | 33 | extern "C" void app_main() { 34 | xTaskCreate((TaskFunction_t)&tf_main, "tensorflow", 8 * 1024, NULL, 8, NULL); 35 | vTaskDelete(NULL); 36 | } 37 | -------------------------------------------------------------------------------- /examples/micro_speech/main/main_functions.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_ 18 | 19 | // Expose a C friendly interface for main functions. 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // Initializes all data needed for the example. The name is important, and needs 25 | // to be setup() for Arduino compatibility. 26 | void setup(); 27 | 28 | // Runs one iteration of data gathering and inference. This should be called 29 | // repeatedly from the application code. The name needs to be loop() for Arduino 30 | // compatibility. 31 | void loop(); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_ 38 | -------------------------------------------------------------------------------- /examples/micro_speech/main/micro_features_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_ 18 | 19 | #include "tensorflow/lite/c/common.h" 20 | #include "micro_model_settings.h" 21 | 22 | using Features = int8_t[kFeatureCount][kFeatureSize]; 23 | 24 | // Sets up any resources needed for the feature generation pipeline. 25 | TfLiteStatus InitializeMicroFeatures(); 26 | 27 | // Converts audio sample data into a more compact form that's appropriate for 28 | // feeding into a neural network. 29 | // TfLiteStatus GenerateMicroFeatures(const int16_t* input, int input_size, 30 | // int output_size, int8_t* output, 31 | // size_t* num_samples_read); 32 | 33 | TfLiteStatus GenerateFeatures(const int16_t* audio_data, 34 | const size_t audio_data_size, 35 | Features* features_output); 36 | 37 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_ 38 | -------------------------------------------------------------------------------- /examples/micro_speech/main/micro_model_settings.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_MODEL_SETTINGS_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_MODEL_SETTINGS_H_ 18 | 19 | // The following values are derived from values used during model training. 20 | // If you change the way you preprocess the input, update all these constants. 21 | constexpr int kMaxAudioSampleSize = 512; 22 | constexpr int kAudioSampleFrequency = 16000; 23 | constexpr int kFeatureSize = 40; 24 | constexpr int kFeatureCount = 49; 25 | constexpr int kFeatureElementCount = (kFeatureSize * kFeatureCount); 26 | constexpr int kFeatureStrideMs = 20; 27 | constexpr int kFeatureDurationMs = 30; 28 | 29 | // Variables for the model's output categories. 30 | constexpr int kCategoryCount = 4; 31 | constexpr const char* kCategoryLabels[kCategoryCount] = { 32 | "silence", 33 | "unknown", 34 | "yes", 35 | "no", 36 | }; 37 | 38 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_MODEL_SETTINGS_H_ 39 | -------------------------------------------------------------------------------- /examples/micro_speech/main/model.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This is a standard TensorFlow Lite FlatBuffer model file that has been 17 | // converted into a C data array, so it can be easily compiled into a binary 18 | // for devices that don't have a file system. It was created using the command: 19 | // xxd -i model.tflite > model.cc 20 | 21 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_ 22 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_ 23 | 24 | extern const unsigned char g_model[]; 25 | extern const int g_model_len; 26 | 27 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_ 28 | -------------------------------------------------------------------------------- /examples/micro_speech/main/no_micro_features_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_ 18 | 19 | extern const int g_no_micro_f9643d42_nohash_4_width; 20 | extern const int g_no_micro_f9643d42_nohash_4_height; 21 | extern const signed char g_no_micro_f9643d42_nohash_4_data[]; 22 | 23 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_ 24 | -------------------------------------------------------------------------------- /examples/micro_speech/main/yes_micro_features_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_ 18 | 19 | extern const int g_yes_micro_f2e59fea_nohash_1_width; 20 | extern const int g_yes_micro_f2e59fea_nohash_1_height; 21 | extern const signed char g_yes_micro_f2e59fea_nohash_1_data[]; 22 | 23 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_ 24 | -------------------------------------------------------------------------------- /examples/micro_speech/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 16 | CONFIG_FLASHMODE_QIO=y 17 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 18 | CONFIG_INT_WDT= 19 | CONFIG_TASK_WDT= 20 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 21 | -------------------------------------------------------------------------------- /examples/micro_speech/test_data/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register( 2 | SRCS "" 3 | INCLUDE_DIRS "" 4 | EMBED_FILES "no_30ms.wav" 5 | "no_1000ms.wav" 6 | "noise_1000ms.wav" 7 | "silence_1000ms.wav" 8 | "yes_30ms.wav" 9 | "yes_1000ms.wav" 10 | ) 11 | -------------------------------------------------------------------------------- /examples/micro_speech/test_data/no_1000ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/micro_speech/test_data/no_1000ms.wav -------------------------------------------------------------------------------- /examples/micro_speech/test_data/no_30ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/micro_speech/test_data/no_30ms.wav -------------------------------------------------------------------------------- /examples/micro_speech/test_data/noise_1000ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/micro_speech/test_data/noise_1000ms.wav -------------------------------------------------------------------------------- /examples/micro_speech/test_data/silence_1000ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/micro_speech/test_data/silence_1000ms.wav -------------------------------------------------------------------------------- /examples/micro_speech/test_data/yes_1000ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/micro_speech/test_data/yes_1000ms.wav -------------------------------------------------------------------------------- /examples/micro_speech/test_data/yes_30ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/micro_speech/test_data/yes_30ms.wav -------------------------------------------------------------------------------- /examples/person_detection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | set(EXTRA_COMPONENT_DIRS static_images) 4 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 5 | 6 | function(add_bsp SDKCONFIG BSP TARGET) 7 | string(REGEX MATCH "CONFIG_${BSP}=y" REGEX_RESULT ${SDKCONFIG}) 8 | if (REGEX_RESULT) 9 | set(ENV{${BSP}} "${TARGET}") 10 | endif() 11 | endfunction() 12 | 13 | # 1. Define all variables used in main/idf_component.yml 14 | set(ENV{TFLITE_USE_BSP_S3_EYE} "false") 15 | set(ENV{TFLITE_USE_BSP_KORVO_2} "false") 16 | set(ENV{TFLITE_USE_BSP_KALUGA} "false") 17 | 18 | # 2. Set correct var to 'target' 19 | # This is a workaround idf-component-manager limitation, where only 20 | # target and idf_version can be in the if-clause 21 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/sdkconfig) 22 | file(READ ${CMAKE_CURRENT_LIST_DIR}/sdkconfig SDKCONFIG_RULE) 23 | 24 | add_bsp("${SDKCONFIG_RULE}" "TFLITE_USE_BSP_S3_EYE" "esp32s3") 25 | add_bsp("${SDKCONFIG_RULE}" "TFLITE_USE_BSP_KORVO_2" "esp32s3") 26 | add_bsp("${SDKCONFIG_RULE}" "TFLITE_USE_BSP_KALUGA" "esp32s2") 27 | endif() 28 | 29 | project(person_detection) 30 | -------------------------------------------------------------------------------- /examples/person_detection/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Main component of TF Micro project 'person_detection'. 4 | # 5 | 6 | idf_component_register( 7 | SRCS 8 | "detection_responder.cc" 9 | "image_provider.cc" 10 | "main.cc" 11 | "main_functions.cc" 12 | "model_settings.cc" 13 | "person_detect_model_data.cc" 14 | "app_camera_esp.c" 15 | "esp_cli.c" 16 | 17 | PRIV_REQUIRES console static_images spi_flash 18 | INCLUDE_DIRS "") 19 | -------------------------------------------------------------------------------- /examples/person_detection/main/detection_responder.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Provides an interface to take an action based on the output from the person 17 | // detection model. 18 | 19 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_DETECTION_RESPONDER_H_ 20 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_DETECTION_RESPONDER_H_ 21 | 22 | #include "tensorflow/lite/c/common.h" 23 | 24 | // Called every time the results of a person detection run are available. The 25 | // `person_score` has the numerical confidence that the captured image contains 26 | // a person, and `no_person_score` has the numerical confidence that the image 27 | // does not contain a person. Typically if person_score > no person score, the 28 | // image is considered to contain a person. This threshold may be adjusted for 29 | // particular applications. 30 | void RespondToDetection(float person_score, float no_person_score); 31 | 32 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_DETECTION_RESPONDER_H_ 33 | -------------------------------------------------------------------------------- /examples/person_detection/main/esp_cli.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | int esp_cli_start(); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /examples/person_detection/main/esp_main.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sdkconfig.h" 16 | 17 | // Enable this to do inference on embedded images 18 | // #define CLI_ONLY_INFERENCE 1 19 | 20 | // Enable this to get cpu stats 21 | #define COLLECT_CPU_STATS 1 22 | 23 | #if !defined(CLI_ONLY_INFERENCE) 24 | // Enable display support if BSP is enabled in menuconfig 25 | #if (CONFIG_TFLITE_USE_BSP) 26 | #define DISPLAY_SUPPORT 1 27 | #endif 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | extern void run_inference(void *ptr); 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /examples/person_detection/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | espressif/esp-tflite-micro: 3 | version: "*" 4 | override_path: "../../../" 5 | 6 | espressif/esp32-camera: "~2.0.5" 7 | 8 | espressif/esp32_s3_eye: 9 | version: "3.*" 10 | rules: 11 | - if: "target == $TFLITE_USE_BSP_S3_EYE" 12 | 13 | espressif/esp32_s3_korvo_2: 14 | version: "2.*" 15 | rules: 16 | - if: "target == $TFLITE_USE_BSP_KORVO_2" 17 | 18 | espressif/esp32_s2_kaluga_kit: 19 | version: "3.*" 20 | rules: 21 | - if: "target == $TFLITE_USE_BSP_KALUGA" 22 | -------------------------------------------------------------------------------- /examples/person_detection/main/main.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "main_functions.h" 17 | #include "esp_log.h" 18 | #include "esp_system.h" 19 | #include "freertos/FreeRTOS.h" 20 | #include "freertos/task.h" 21 | 22 | #include "esp_main.h" 23 | 24 | #if CLI_ONLY_INFERENCE 25 | #include "esp_cli.h" 26 | #endif 27 | 28 | void tf_main(void) { 29 | setup(); 30 | #if CLI_ONLY_INFERENCE 31 | esp_cli_start(); 32 | vTaskDelay(portMAX_DELAY); 33 | #else 34 | while (true) { 35 | loop(); 36 | } 37 | #endif 38 | } 39 | 40 | extern "C" void app_main() { 41 | xTaskCreate((TaskFunction_t)&tf_main, "tf_main", 4 * 1024, NULL, 8, NULL); 42 | vTaskDelete(NULL); 43 | } 44 | -------------------------------------------------------------------------------- /examples/person_detection/main/main_functions.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MAIN_FUNCTIONS_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MAIN_FUNCTIONS_H_ 18 | 19 | // Expose a C friendly interface for main functions. 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // Initializes all data needed for the example. The name is important, and needs 25 | // to be setup() for Arduino compatibility. 26 | void setup(); 27 | 28 | // Runs one iteration of data gathering and inference. This should be called 29 | // repeatedly from the application code. The name needs to be loop() for Arduino 30 | // compatibility. 31 | void loop(); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MAIN_FUNCTIONS_H_ 38 | -------------------------------------------------------------------------------- /examples/person_detection/main/model_settings.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "model_settings.h" 17 | 18 | const char* kCategoryLabels[kCategoryCount] = { 19 | "notperson", 20 | "person", 21 | }; 22 | -------------------------------------------------------------------------------- /examples/person_detection/main/model_settings.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MODEL_SETTINGS_H_ 17 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MODEL_SETTINGS_H_ 18 | 19 | // Keeping these as constant expressions allow us to allocate fixed-sized arrays 20 | // on the stack for our working memory. 21 | 22 | // All of these values are derived from the values used during model training, 23 | // if you change your model you'll need to update these constants. 24 | constexpr int kNumCols = 96; 25 | constexpr int kNumRows = 96; 26 | constexpr int kNumChannels = 1; 27 | 28 | constexpr int kMaxImageSize = kNumCols * kNumRows * kNumChannels; 29 | 30 | constexpr int kCategoryCount = 2; 31 | constexpr int kPersonIndex = 1; 32 | constexpr int kNotAPersonIndex = 0; 33 | extern const char* kCategoryLabels[kCategoryCount]; 34 | 35 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MODEL_SETTINGS_H_ 36 | -------------------------------------------------------------------------------- /examples/person_detection/main/person_detect_model_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This is a standard TensorFlow Lite model file that has been converted into a 17 | // C data array, so it can be easily compiled into a binary for devices that 18 | // don't have a file system. It was created using the command: 19 | // xxd -i person_detect.tflite > person_detect_model_data.cc 20 | 21 | #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_DETECT_MODEL_DATA_H_ 22 | #define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_DETECT_MODEL_DATA_H_ 23 | 24 | extern const unsigned char g_person_detect_model_data[]; 25 | extern const int g_person_detect_model_data_len; 26 | 27 | #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_DETECT_MODEL_DATA_H_ 28 | -------------------------------------------------------------------------------- /examples/person_detection/partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 0x180000, 6 | -------------------------------------------------------------------------------- /examples/person_detection/sdkconfig.defaults.esp32s2: -------------------------------------------------------------------------------- 1 | # Default configurations for ESP32-S2 2 | 3 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 4 | 5 | CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y 6 | CONFIG_ESP32S2_SPIRAM_SUPPORT=y 7 | 8 | CONFIG_ESP32S2_INSTRUCTION_CACHE_16KB=y 9 | CONFIG_ESP32S2_DATA_CACHE_16KB=y 10 | 11 | # ESP32-S2 has limited performance, which will starve the IDLE_TASK 12 | # So we must disable the task WDT 13 | CONFIG_ESP_TASK_WDT_EN=n 14 | 15 | # display driver dettings 16 | CONFIG_LV_COLOR_16_SWAP=y 17 | CONFIG_LV_MEM_CUSTOM=y 18 | CONFIG_LV_MEMCPY_MEMSET_STD=y 19 | CONFIG_LV_USE_PERF_MONITOR=y 20 | CONFIG_LV_SPRINTF_CUSTOM=y 21 | -------------------------------------------------------------------------------- /examples/person_detection/sdkconfig.defaults.esp32s3: -------------------------------------------------------------------------------- 1 | # Default configurations for ESP32-S3 2 | 3 | CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y 4 | 5 | CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y 6 | CONFIG_ESP32S3_SPIRAM_SUPPORT=y 7 | CONFIG_SPIRAM_MODE_OCT=y 8 | 9 | CONFIG_CAMERA_CORE1=y 10 | 11 | CONFIG_ ESP32S3_INSTRUCTION_CACHE_32KB=y 12 | CONFIG_ESP32S3_DATA_CACHE_64KB=y 13 | CONFIG_ESP32S3_DATA_CACHE_8WAYS=y 14 | CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y 15 | 16 | CONFIG_CAMERA_MODULE_ESP_S3_EYE=y 17 | # CONFIG_ESPTOOLPY_NO_STUB=y 18 | # CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y 19 | 20 | # display driver dettings 21 | CONFIG_LV_COLOR_16_SWAP=y 22 | CONFIG_LV_MEM_CUSTOM=y 23 | CONFIG_LV_MEMCPY_MEMSET_STD=y 24 | CONFIG_LV_USE_PERF_MONITOR=y 25 | CONFIG_LV_SPRINTF_CUSTOM=y 26 | -------------------------------------------------------------------------------- /examples/person_detection/static_images/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Main component of TF Micro project 'person_detection'. 4 | # 5 | 6 | idf_component_register( 7 | SRCS "" 8 | INCLUDE_DIRS "" 9 | EMBED_FILES "sample_images/image0" 10 | "sample_images/image1" 11 | "sample_images/image2" 12 | "sample_images/image3" 13 | "sample_images/image4" 14 | "sample_images/image5" 15 | "sample_images/image6" 16 | "sample_images/image7" 17 | "sample_images/image8" 18 | "sample_images/image9") 19 | -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/README.md: -------------------------------------------------------------------------------- 1 | # About Images 2 | 3 | - The images embedded here are 96x96 greyscale images. 4 | - These can be viewed at https://rawpixels.net 5 | 6 | ## Image descriptions: 7 | 8 | - image0: A person 9 | - image1: A dog 10 | - image2: A person 11 | - image3: A Monkey 12 | - image4: A person 13 | - image5: A cat 14 | - image6: A person (not in focus) 15 | - image7: Portrait of a person 16 | - image8: A person 17 | - image9: A person 18 | -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image0 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image1 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image2 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image3 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image4 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image5 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image6 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image7 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image8 -------------------------------------------------------------------------------- /examples/person_detection/static_images/sample_images/image9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-tflite-micro/772214721682ef2d3eed09cafea777edad55541f/examples/person_detection/static_images/sample_images/image9 -------------------------------------------------------------------------------- /idf_component.yml: -------------------------------------------------------------------------------- 1 | description: TensorFlow Lite Micro component for ESP-IDF 2 | url: https://github.com/espressif/tflite-micro-esp-examples 3 | repository: https://github.com/espressif/tflite-micro-esp-examples.git 4 | issues: https://github.com/espressif/tflite-micro-esp-examples/issues 5 | documentation: https://github.com/espressif/tflite-micro-esp-examples#readme 6 | 7 | dependencies: 8 | idf: 9 | version: ">=4.4" 10 | espressif/esp-nn: 11 | version: "^1.1.0" 12 | files: 13 | exclude: 14 | - scripts 15 | - .gitlab-ci.yml 16 | - .github 17 | -------------------------------------------------------------------------------- /scripts/gh_sync_req.txt: -------------------------------------------------------------------------------- 1 | # Python requirements for sync_from_github 2 | image 3 | numpy 4 | -------------------------------------------------------------------------------- /signal/micro/kernels/delay_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_DELAY_FLEXBUFFERS_GENERATED_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_DELAY_FLEXBUFFERS_GENERATED_DATA_H_ 18 | 19 | extern const int g_gen_data_size_3_delay; 20 | extern const unsigned char g_gen_data_3_delay[]; 21 | 22 | extern const int g_gen_data_size_5_delay; 23 | extern const unsigned char g_gen_data_5_delay[]; 24 | 25 | #endif // SIGNAL_MICRO_KERNELS_DELAY_FLEXBUFFERS_GENERATED_DATA_H_ 26 | -------------------------------------------------------------------------------- /signal/micro/kernels/energy_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_ENERGY_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_ENERGY_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_start_index_2_end_index_4; 20 | extern const unsigned char g_gen_data_start_index_2_end_index_4[]; 21 | 22 | extern const int g_gen_data_size_start_index_0_end_index_4; 23 | extern const unsigned char g_gen_data_start_index_0_end_index_4[]; 24 | 25 | extern const int g_gen_data_size_start_index_4_end_index_8; 26 | extern const unsigned char g_gen_data_start_index_4_end_index_8[]; 27 | 28 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_ENERGY_FLEXBUFFERS_DATA_H_ 29 | -------------------------------------------------------------------------------- /signal/micro/kernels/fft_auto_scale_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef SIGNAL_MICRO_KERNELS_FFT_AUTO_SCALE_KERNEL_H_ 16 | #define SIGNAL_MICRO_KERNELS_FFT_AUTO_SCALE_KERNEL_H_ 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | 20 | namespace tflite { 21 | 22 | TfLiteStatus FftAutoScalePrepare(TfLiteContext* context, TfLiteNode* node); 23 | 24 | } // namespace tflite 25 | 26 | #endif // SIGNAL_MICRO_KERNELS_FFT_AUTO_SCALE_KERNEL_H_ 27 | -------------------------------------------------------------------------------- /signal/micro/kernels/fft_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FFT_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FFT_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_fft_length_64_float; 20 | extern const unsigned char g_gen_data_fft_length_64_float[]; 21 | 22 | extern const int g_gen_data_size_fft_length_64_int16; 23 | extern const unsigned char g_gen_data_fft_length_64_int16[]; 24 | 25 | extern const int g_gen_data_size_fft_length_64_int32; 26 | extern const unsigned char g_gen_data_fft_length_64_int32[]; 27 | 28 | extern const int g_gen_data_size_fft_length_512_float; 29 | extern const unsigned char g_gen_data_fft_length_512_float[]; 30 | 31 | extern const int g_gen_data_size_fft_length_512_int16; 32 | extern const unsigned char g_gen_data_fft_length_512_int16[]; 33 | 34 | extern const int g_gen_data_size_fft_length_512_int32; 35 | extern const unsigned char g_gen_data_fft_length_512_int32[]; 36 | 37 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FFT_FLEXBUFFERS_DATA_H_ 38 | -------------------------------------------------------------------------------- /signal/micro/kernels/filter_bank_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_filter_bank_32_channel; 20 | extern const unsigned char g_gen_data_filter_bank_32_channel[]; 21 | 22 | extern const int g_gen_data_size_filter_bank_16_channel; 23 | extern const unsigned char g_gen_data_filter_bank_16_channel[]; 24 | 25 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_FLEXBUFFERS_DATA_H_ 26 | -------------------------------------------------------------------------------- /signal/micro/kernels/filter_bank_log_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_LOG_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_LOG_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_filter_bank_log_scale_1600_correction_bits_3; 20 | extern const unsigned char 21 | g_gen_data_filter_bank_log_scale_1600_correction_bits_3[]; 22 | 23 | extern const int g_gen_data_size_filter_bank_log_scale_32768_correction_bits_5; 24 | extern const unsigned char 25 | g_gen_data_filter_bank_log_scale_32768_correction_bits_5[]; 26 | 27 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_LOG_FLEXBUFFERS_DATA_H_ 28 | -------------------------------------------------------------------------------- /signal/micro/kernels/filter_bank_spectral_subtraction_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_SPECTRAL_SUBTRACTION_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_SPECTRAL_SUBTRACTION_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_filter_bank_spectral_subtraction_32_channel; 20 | extern const unsigned char 21 | g_gen_data_filter_bank_spectral_subtraction_32_channel[]; 22 | extern const int g_gen_data_size_filter_bank_spectral_subtraction_16_channel; 23 | extern const unsigned char 24 | g_gen_data_filter_bank_spectral_subtraction_16_channel[]; 25 | 26 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FILTER_BANK_SPECTRAL_SUBTRACTION_FLEXBUFFERS_DATA_H_ 27 | -------------------------------------------------------------------------------- /signal/micro/kernels/filter_bank_square_root.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef SIGNAL_MICRO_KERNELS_FILTER_BANK_SQUARE_ROOT_H_ 16 | #define SIGNAL_MICRO_KERNELS_FILTER_BANK_SQUARE_ROOT_H_ 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | 20 | namespace tflite { 21 | 22 | TfLiteStatus FilterBankSquareRootPrepare(TfLiteContext* context, 23 | TfLiteNode* node); 24 | 25 | } // namespace tflite 26 | 27 | #endif // SIGNAL_MICRO_KERNELS_FILTER_BANK_SQUARE_ROOT_H_ 28 | -------------------------------------------------------------------------------- /signal/micro/kernels/framer_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FRAMER_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FRAMER_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_3_1_0_framer; 20 | extern const unsigned char g_gen_data_3_1_0_framer[]; 21 | 22 | extern const int g_gen_data_size_5_2_1_framer; 23 | extern const unsigned char g_gen_data_5_2_1_framer[]; 24 | 25 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_FRAMER_FLEXBUFFERS_DATA_H_ 26 | -------------------------------------------------------------------------------- /signal/micro/kernels/irfft.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef SIGNAL_MICRO_KERNELS_IRFFT_H_ 16 | #define SIGNAL_MICRO_KERNELS_IRFFT_H_ 17 | 18 | #include "tensorflow/lite/micro/micro_common.h" 19 | 20 | namespace tflite { 21 | namespace tflm_signal { 22 | 23 | TFLMRegistration* Register_IRFFT(); 24 | TFLMRegistration* Register_IRFFT_FLOAT(); 25 | TFLMRegistration* Register_IRFFT_INT16(); 26 | TFLMRegistration* Register_IRFFT_INT32(); 27 | 28 | } // namespace tflm_signal 29 | } // namespace tflite 30 | 31 | #endif // SIGNAL_MICRO_KERNELS_IRFFT_H_ 32 | -------------------------------------------------------------------------------- /signal/micro/kernels/overlap_add_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_OVERLAP_ADD_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_OVERLAP_ADD_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_overlap_add_float; 20 | extern const unsigned char g_gen_data_overlap_add_float[]; 21 | 22 | extern const int g_gen_data_size_overlap_add_int16; 23 | extern const unsigned char g_gen_data_overlap_add_int16[]; 24 | 25 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_OVERLAP_ADD_FLEXBUFFERS_DATA_H_ 26 | -------------------------------------------------------------------------------- /signal/micro/kernels/pcan_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | #ifndef SIGNAL_MICRO_KERNELS_PCAN_FLEXBUFFERS_GENERATED_DATA_H_ 2 | #define SIGNAL_MICRO_KERNELS_PCAN_FLEXBUFFERS_GENERATED_DATA_H_ 3 | 4 | extern const int g_gen_data_size_snr_shift_6_test; 5 | extern const unsigned char g_gen_data_snr_shift_6_test[]; 6 | 7 | #endif // SIGNAL_MICRO_KERNELS_PCAN_FLEXBUFFERS_GENERATED_DATA_H_ 8 | -------------------------------------------------------------------------------- /signal/micro/kernels/rfft.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef SIGNAL_MICRO_KERNELS_RFFT_H_ 16 | #define SIGNAL_MICRO_KERNELS_RFFT_H_ 17 | 18 | #include "tensorflow/lite/micro/micro_common.h" 19 | 20 | namespace tflite { 21 | namespace tflm_signal { 22 | 23 | TFLMRegistration* Register_RFFT(); 24 | TFLMRegistration* Register_RFFT_FLOAT(); 25 | TFLMRegistration* Register_RFFT_INT16(); 26 | TFLMRegistration* Register_RFFT_INT32(); 27 | 28 | } // namespace tflm_signal 29 | } // namespace tflite 30 | 31 | #endif // SIGNAL_MICRO_KERNELS_RFFT_H_ 32 | -------------------------------------------------------------------------------- /signal/micro/kernels/stacker_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_STACKER_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_STACKER_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_stacker_3_channels_step_1; 20 | extern const unsigned char g_gen_data_stacker_3_channels_step_1[]; 21 | 22 | extern const int g_gen_data_size_stacker_10_channels_step_2; 23 | extern const unsigned char g_gen_data_stacker_10_channels_step_2[]; 24 | 25 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_STACKER_FLEXBUFFERS_DATA_H_ 26 | -------------------------------------------------------------------------------- /signal/micro/kernels/window_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_WINDOW_FLEXBUFFERS_DATA_H_ 17 | #define SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_WINDOW_FLEXBUFFERS_DATA_H_ 18 | 19 | extern const int g_gen_data_size_window_shift_12; 20 | extern const unsigned char g_gen_data_window_shift_12[]; 21 | 22 | extern const int g_gen_data_size_window_shift_8; 23 | extern const unsigned char g_gen_data_window_shift_8[]; 24 | 25 | #endif // SIGNAL_MICRO_KERNELS_TEST_DATA_GENERATION_GENERATE_WINDOW_FLEXBUFFERS_DATA_H_ 26 | -------------------------------------------------------------------------------- /signal/src/complex.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_COMPLEX_H_ 17 | #define SIGNAL_SRC_COMPLEX_H_ 18 | 19 | #include 20 | 21 | // We would use the standard complex type in complex.h, but there's 22 | // no guarantee that all architectures will support it. 23 | template 24 | struct Complex { 25 | T real; 26 | T imag; 27 | }; 28 | 29 | #endif // SIGNAL_SRC_COMPLEX_H_ 30 | -------------------------------------------------------------------------------- /signal/src/energy.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #include "signal/src/energy.h" 16 | 17 | #include "signal/src/complex.h" 18 | 19 | namespace tflite { 20 | namespace tflm_signal { 21 | void SpectrumToEnergy(const Complex* input, int start_index, 22 | int end_index, uint32_t* output) { 23 | for (int i = start_index; i < end_index; i++) { 24 | const int16_t real = input[i].real; // 15 bits 25 | const int16_t imag = input[i].imag; // 15 bits 26 | // 31 bits 27 | output[i] = (static_cast(real) * real) + 28 | (static_cast(imag) * imag); 29 | } 30 | } 31 | 32 | } // namespace tflm_signal 33 | } // namespace tflite 34 | -------------------------------------------------------------------------------- /signal/src/energy.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_ENERGY_H_ 17 | #define SIGNAL_ENERGY_H_ 18 | 19 | #include 20 | 21 | #include "signal/src/complex.h" 22 | 23 | namespace tflite { 24 | namespace tflm_signal { 25 | // TODO(b/286250473): remove namespace once de-duped libraries above 26 | 27 | // Calculates the power spectrum from a DFT output between start and end indices 28 | // 29 | // * `start_index` and `end_index` must valid indices into `input` 30 | // * `output` must be the same size as `input`. Only the values at indices 31 | // `start_index` and `end_index` inclusive should be considered valid. 32 | void SpectrumToEnergy(const Complex* input, int start_index, 33 | int end_index, uint32_t* output); 34 | 35 | } // namespace tflm_signal 36 | } // namespace tflite 37 | 38 | #endif // SIGNAL_ENERGY_H_ 39 | -------------------------------------------------------------------------------- /signal/src/fft_auto_scale.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/fft_auto_scale.h" 17 | 18 | #include 19 | #include 20 | 21 | #include "signal/src/max_abs.h" 22 | #include "signal/src/msb.h" 23 | 24 | // TODO(b/286250473): remove namespace once de-duped libraries 25 | namespace tflite { 26 | namespace tflm_signal { 27 | 28 | int FftAutoScale(const int16_t* input, int size, int16_t* output) { 29 | const int16_t max = MaxAbs16(input, size); 30 | int scale_bits = (sizeof(int16_t) * 8) - MostSignificantBit32(max) - 1; 31 | if (scale_bits <= 0) { 32 | scale_bits = 0; 33 | } 34 | for (int i = 0; i < size; i++) { 35 | // (input[i] << scale_bits) is undefined if input[i] is negative. 36 | // Multiply explicitly to make the code portable. 37 | output[i] = input[i] * (1 << scale_bits); 38 | } 39 | return scale_bits; 40 | } 41 | } // namespace tflm_signal 42 | } // namespace tflite 43 | -------------------------------------------------------------------------------- /signal/src/fft_auto_scale.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_FFT_AUTO_SCALE_H_ 17 | #define SIGNAL_SRC_FFT_AUTO_SCALE_H_ 18 | 19 | #include 20 | #include 21 | 22 | // TODO(b/286250473): remove namespace once de-duped libraries 23 | namespace tflite { 24 | namespace tflm_signal { 25 | 26 | // Auto scales `input` and write the result to `output` 27 | // Elements in `input` are left shifted to maximize the amplitude without 28 | // clipping, 29 | // * both `input` and `output` must be of size `size` 30 | int FftAutoScale(const int16_t* input, int size, int16_t* output); 31 | 32 | } // namespace tflm_signal 33 | } // namespace tflite 34 | 35 | #endif // SIGNAL_SRC_FFT_AUTO_SCALE_H_ 36 | -------------------------------------------------------------------------------- /signal/src/filter_bank_log.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/filter_bank_log.h" 17 | 18 | #include "signal/src/log.h" 19 | 20 | namespace tflite { 21 | namespace tflm_signal { 22 | 23 | void FilterbankLog(const uint32_t* input, int num_channels, 24 | int32_t output_scale, uint32_t correction_bits, 25 | int16_t* output) { 26 | for (int i = 0; i < num_channels; ++i) { 27 | const uint32_t scaled = input[i] << correction_bits; 28 | if (scaled > 1) { 29 | const uint32_t log_value = Log32(scaled, output_scale); 30 | output[i] = ((log_value < static_cast(INT16_MAX)) 31 | ? log_value 32 | : static_cast(INT16_MAX)); 33 | } else { 34 | output[i] = 0; 35 | } 36 | } 37 | } 38 | 39 | } // namespace tflm_signal 40 | } // namespace tflite 41 | -------------------------------------------------------------------------------- /signal/src/filter_bank_log.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_FILTER_BANK_LOG_H_ 17 | #define SIGNAL_SRC_FILTER_BANK_LOG_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | namespace tflm_signal { 23 | // TODO(b/286250473): remove namespace once de-duped libraries above 24 | 25 | // Apply natural log to each element in array `input` of size `num_channels` 26 | // with pre-shift and post scaling. 27 | // The operation is roughly equivalent to: 28 | // `output` = min(Log(`input` << `correction_bits`) * `output_scale`, INT16_MAX) 29 | // Where: 30 | // If (input << `correction_bits`) is 1 or 0, the function returns 0 31 | void FilterbankLog(const uint32_t* input, int num_channels, 32 | int32_t output_scale, uint32_t correction_bits, 33 | int16_t* output); 34 | 35 | } // namespace tflm_signal 36 | } // namespace tflite 37 | 38 | #endif // SIGNAL_SRC_FILTER_BANK_LOG_H_ 39 | -------------------------------------------------------------------------------- /signal/src/filter_bank_square_root.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/filter_bank_square_root.h" 17 | 18 | #include "signal/src/square_root.h" 19 | 20 | namespace tflite { 21 | namespace tflm_signal { 22 | 23 | void FilterbankSqrt(const uint64_t* input, int num_channels, 24 | int scale_down_bits, uint32_t* output) { 25 | for (int i = 0; i < num_channels; ++i) { 26 | output[i] = Sqrt64(input[i]) >> scale_down_bits; 27 | } 28 | } 29 | 30 | } // namespace tflm_signal 31 | } // namespace tflite 32 | -------------------------------------------------------------------------------- /signal/src/filter_bank_square_root.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_FILTER_BANK_SQUARE_ROOT_H_ 17 | #define SIGNAL_SRC_FILTER_BANK_SQUARE_ROOT_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | namespace tflm_signal { 23 | // TODO(b/286250473): remove namespace once de-duped libraries above 24 | 25 | // Apply square root to each element in `input`, then shift right by 26 | // `scale_down_bits` before writing the result to `output`, 27 | // `input` and `output` must both be of size `num_channels` 28 | void FilterbankSqrt(const uint64_t* input, int num_channels, 29 | int scale_down_bits, uint32_t* output); 30 | 31 | } // namespace tflm_signal 32 | } // namespace tflite 33 | 34 | #endif // SIGNAL_SRC_FILTER_BANK_SQUARE_ROOT_H_ 35 | -------------------------------------------------------------------------------- /signal/src/irfft_int16.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "signal/src/complex.h" 20 | #include "signal/src/irfft.h" 21 | #include "signal/src/kiss_fft_wrappers/kiss_fft_int16.h" 22 | 23 | // TODO(b/286250473): remove namespace once de-duped libraries 24 | namespace tflite { 25 | namespace tflm_signal { 26 | 27 | size_t IrfftInt16GetNeededMemory(int32_t fft_length) { 28 | size_t state_size = 0; 29 | kiss_fft_fixed16::kiss_fftr_alloc(fft_length, 1, nullptr, &state_size); 30 | return state_size; 31 | } 32 | 33 | void* IrfftInt16Init(int32_t fft_length, void* state, size_t state_size) { 34 | return kiss_fft_fixed16::kiss_fftr_alloc(fft_length, 1, state, &state_size); 35 | } 36 | 37 | void IrfftInt16Apply(void* state, const Complex* input, 38 | int16_t* output) { 39 | kiss_fft_fixed16::kiss_fftri( 40 | static_cast(state), 41 | reinterpret_cast(input), 42 | reinterpret_cast(output)); 43 | } 44 | 45 | } // namespace tflm_signal 46 | } // namespace tflite 47 | -------------------------------------------------------------------------------- /signal/src/irfft_int32.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "signal/src/complex.h" 20 | #include "signal/src/irfft.h" 21 | #include "signal/src/kiss_fft_wrappers/kiss_fft_int32.h" 22 | 23 | // TODO(b/286250473): remove namespace once de-duped libraries 24 | namespace tflite { 25 | namespace tflm_signal { 26 | 27 | size_t IrfftInt32GetNeededMemory(int32_t fft_length) { 28 | size_t state_size = 0; 29 | kiss_fft_fixed32::kiss_fftr_alloc(fft_length, 1, nullptr, &state_size); 30 | return state_size; 31 | } 32 | 33 | void* IrfftInt32Init(int32_t fft_length, void* state, size_t state_size) { 34 | return kiss_fft_fixed32::kiss_fftr_alloc(fft_length, 1, state, &state_size); 35 | } 36 | 37 | void IrfftInt32Apply(void* state, const Complex* input, 38 | int32_t* output) { 39 | kiss_fft_fixed32::kiss_fftri( 40 | static_cast(state), 41 | reinterpret_cast(input), 42 | reinterpret_cast(output)); 43 | } 44 | 45 | } // namespace tflm_signal 46 | } // namespace tflite 47 | -------------------------------------------------------------------------------- /signal/src/kiss_fft_wrappers/kiss_fft_float.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/kiss_fft_wrappers/kiss_fft_common.h" 17 | 18 | #undef FIXED_POINT 19 | namespace kiss_fft_float { 20 | #include "kiss_fft.c" 21 | #include "tools/kiss_fftr.c" 22 | } // namespace kiss_fft_float 23 | -------------------------------------------------------------------------------- /signal/src/kiss_fft_wrappers/kiss_fft_float.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_FLOAT_H_ 17 | #define SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_FLOAT_H_ 18 | 19 | #include "signal/src/kiss_fft_wrappers/kiss_fft_common.h" 20 | 21 | // Wrap floating point kiss fft in its own namespace. Enables us to link an 22 | // application with different kiss fft resolutions 23 | // (16/32 bit integer, float, double) without getting a linker error. 24 | #undef FIXED_POINT 25 | namespace kiss_fft_float { 26 | #include "kiss_fft.h" 27 | #include "tools/kiss_fftr.h" 28 | } // namespace kiss_fft_float 29 | #undef FIXED_POINT 30 | 31 | #endif // SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_FLOAT_H_ 32 | -------------------------------------------------------------------------------- /signal/src/kiss_fft_wrappers/kiss_fft_int16.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/kiss_fft_wrappers/kiss_fft_common.h" 17 | 18 | #define FIXED_POINT 16 19 | namespace kiss_fft_fixed16 { 20 | #include "kiss_fft.c" 21 | #include "tools/kiss_fftr.c" 22 | } // namespace kiss_fft_fixed16 23 | #undef FIXED_POINT 24 | -------------------------------------------------------------------------------- /signal/src/kiss_fft_wrappers/kiss_fft_int16.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_INT16_H_ 17 | #define SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_INT16_H_ 18 | 19 | #include "signal/src/kiss_fft_wrappers/kiss_fft_common.h" 20 | // Wrap floating point kiss fft in its own namespace. Enables us to link an 21 | // application with different kiss fft resolutions 22 | // (16/32 bit integer, float, double) without getting a linker error. 23 | #define FIXED_POINT 16 24 | namespace kiss_fft_fixed16 { 25 | #include "kiss_fft.h" 26 | #include "tools/kiss_fftr.h" 27 | } // namespace kiss_fft_fixed16 28 | #undef FIXED_POINT 29 | 30 | #endif // SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_INT16_H_ 31 | -------------------------------------------------------------------------------- /signal/src/kiss_fft_wrappers/kiss_fft_int32.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/kiss_fft_wrappers/kiss_fft_common.h" 17 | 18 | #define FIXED_POINT 32 19 | namespace kiss_fft_fixed32 { 20 | #include "kiss_fft.c" 21 | #include "tools/kiss_fftr.c" 22 | } // namespace kiss_fft_fixed32 23 | #undef FIXED_POINT 24 | -------------------------------------------------------------------------------- /signal/src/kiss_fft_wrappers/kiss_fft_int32.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_INT32_H_ 17 | #define SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_INT32_H_ 18 | 19 | #include "signal/src/kiss_fft_wrappers/kiss_fft_common.h" 20 | 21 | // Wrap floating point kiss fft in its own namespace. Enables us to link an 22 | // application with different kiss fft resolutions 23 | // (16/32 bit integer, float, double) without getting a linker error. 24 | #define FIXED_POINT 32 25 | namespace kiss_fft_fixed32 { 26 | #include "kiss_fft.h" 27 | #include "tools/kiss_fftr.h" 28 | } // namespace kiss_fft_fixed32 29 | #undef FIXED_POINT 30 | 31 | #endif // SIGNAL_SRC_KISS_FFT_WRAPPERS_KISS_FFT_INT32_H_ 32 | -------------------------------------------------------------------------------- /signal/src/log.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_LOG_H_ 17 | #define SIGNAL_SRC_LOG_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | namespace tflm_signal { 23 | // TODO(b/286250473): remove namespace once de-duped libraries above 24 | 25 | // Natural logarithm of an integer. The result is multiplied by out_scale 26 | uint32_t Log32(uint32_t x, uint32_t out_scale); 27 | 28 | } // namespace tflm_signal 29 | } // namespace tflite 30 | #endif // SIGNAL_SRC_LOG_H_ 31 | -------------------------------------------------------------------------------- /signal/src/max_abs.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_MAX_ABS_H_ 17 | #define SIGNAL_SRC_MAX_ABS_H_ 18 | 19 | #include 20 | 21 | // TODO(b/286250473): remove namespace once de-duped libraries 22 | namespace tflite { 23 | namespace tflm_signal { 24 | 25 | // Returns the maximum absolute value of the `size` elements in `input` 26 | int16_t MaxAbs16(const int16_t* input, int size); 27 | 28 | } // namespace tflm_signal 29 | } // namespace tflite 30 | 31 | #endif // SIGNAL_SRC_MAX_ABS_H_ 32 | -------------------------------------------------------------------------------- /signal/src/msb.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_MSB_H_ 17 | #define SIGNAL_SRC_MSB_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | namespace tflm_signal { 23 | // TODO(b/286250473): remove namespace once de-duped libraries above 24 | 25 | // Index of the most significant bit 26 | uint32_t MostSignificantBit32(uint32_t x); 27 | uint32_t MostSignificantBit64(uint64_t x); 28 | 29 | } // namespace tflm_signal 30 | } // namespace tflite 31 | 32 | #endif // SIGNAL_SRC_MSB_H_ 33 | -------------------------------------------------------------------------------- /signal/src/msb_32.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/msb.h" 17 | 18 | #if defined(XTENSA) 19 | #include 20 | #endif 21 | 22 | namespace tflite { 23 | namespace tflm_signal { 24 | // TODO(b/286250473): remove namespace once de-duped libraries above 25 | 26 | // TODO(b/291167350): can allow __builtin_clz to be used in more cases here 27 | uint32_t MostSignificantBit32(uint32_t x) { 28 | #if defined(XTENSA) 29 | // XT_NSAU returns the number of left shifts needed to put the MSB in the 30 | // leftmost position. Returns 32 if the argument is 0. 31 | return 32 - XT_NSAU(x); 32 | #elif defined(__GNUC__) 33 | if (x) { 34 | return 32 - __builtin_clz(x); 35 | } 36 | return 32; 37 | #else 38 | uint32_t temp = 0; 39 | while (x) { 40 | x = x >> 1; 41 | ++temp; 42 | } 43 | return temp; 44 | #endif 45 | } 46 | 47 | } // namespace tflm_signal 48 | } // namespace tflite 49 | -------------------------------------------------------------------------------- /signal/src/msb_64.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/msb.h" 17 | 18 | #if defined(XTENSA) 19 | #include 20 | #endif 21 | 22 | namespace tflite { 23 | namespace tflm_signal { 24 | // TODO(b/286250473): remove namespace once de-duped libraries above 25 | 26 | uint32_t MostSignificantBit64(uint64_t x) { 27 | #if defined(XTENSA) 28 | // XT_NSAU returns the number of left shifts needed to put the MSB in the 29 | // leftmost position. Returns 32 if the argument is 0. 30 | uint32_t upper = 64 - XT_NSAU((uint32_t)(x >> 32)); 31 | if (upper != 32) { 32 | return upper; 33 | } 34 | // Only if the upper bits are all clear do we want to look at the lower bits. 35 | return 32 - XT_NSAU((uint32_t)x); 36 | #elif defined(__GNUC__) 37 | if (x) { 38 | return 64 - __builtin_clzll(x); 39 | } 40 | return 64; 41 | #else 42 | uint32_t temp = 0; 43 | while (x) { 44 | x = x >> 1; 45 | ++temp; 46 | } 47 | return temp; 48 | #endif 49 | } 50 | 51 | } // namespace tflm_signal 52 | } // namespace tflite 53 | -------------------------------------------------------------------------------- /signal/src/pcan_argc_fixed.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_MICRO_KERNELS__SRC_PCAN_AGC_FIXED_H 17 | #define SIGNAL_MICRO_KERNELS__SRC_PCAN_AGC_FIXED_H 18 | #include 19 | 20 | #include "msb.h" 21 | #include "tensorflow/lite/kernels/internal/compatibility.h" 22 | 23 | namespace tflite { 24 | namespace tflm_signal { 25 | 26 | #define kPcanSnrBits 12 27 | #define kPcanOutputBits 6 28 | 29 | int16_t WideDynamicFunction(const uint32_t x, const int16_t* lut); 30 | 31 | uint32_t PcanShrink(const uint32_t x); 32 | 33 | void ApplyPcanAutoGainControlFixed(const int16_t* gain_lut, int32_t snr_shift, 34 | const uint32_t* noise_estimate, 35 | uint32_t* filterbank_output, 36 | int num_channels); 37 | 38 | } // namespace tflm_signal 39 | } // namespace tflite 40 | 41 | #endif // SIGNAL_MICRO_KERNELS__PCAN_AGC_FIXED_H 42 | -------------------------------------------------------------------------------- /signal/src/rfft_float.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "signal/src/complex.h" 20 | #include "signal/src/kiss_fft_wrappers/kiss_fft_float.h" 21 | #include "signal/src/rfft.h" 22 | 23 | // TODO(b/286250473): remove namespace once de-duped libraries 24 | namespace tflm_signal { 25 | 26 | size_t RfftFloatGetNeededMemory(int32_t fft_length) { 27 | size_t state_size = 0; 28 | kiss_fft_float::kiss_fftr_alloc(fft_length, 0, nullptr, &state_size); 29 | return state_size; 30 | } 31 | 32 | void* RfftFloatInit(int32_t fft_length, void* state, size_t state_size) { 33 | return kiss_fft_float::kiss_fftr_alloc(fft_length, 0, state, &state_size); 34 | } 35 | 36 | void RfftFloatApply(void* state, const float* input, Complex* output) { 37 | kiss_fft_float::kiss_fftr( 38 | static_cast(state), 39 | reinterpret_cast(input), 40 | reinterpret_cast(output)); 41 | } 42 | 43 | } // namespace tflm_signal 44 | -------------------------------------------------------------------------------- /signal/src/rfft_int16.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "signal/src/complex.h" 20 | #include "signal/src/kiss_fft_wrappers/kiss_fft_int16.h" 21 | #include "signal/src/rfft.h" 22 | 23 | // TODO(b/286250473): remove namespace once de-duped libraries 24 | namespace tflm_signal { 25 | 26 | size_t RfftInt16GetNeededMemory(int32_t fft_length) { 27 | size_t state_size = 0; 28 | kiss_fft_fixed16::kiss_fftr_alloc(fft_length, 0, nullptr, &state_size); 29 | return state_size; 30 | } 31 | 32 | void* RfftInt16Init(int32_t fft_length, void* state, size_t state_size) { 33 | return kiss_fft_fixed16::kiss_fftr_alloc(fft_length, 0, state, &state_size); 34 | } 35 | 36 | void RfftInt16Apply(void* state, const int16_t* input, 37 | Complex* output) { 38 | kiss_fft_fixed16::kiss_fftr( 39 | static_cast(state), 40 | reinterpret_cast(input), 41 | reinterpret_cast(output)); 42 | } 43 | 44 | } // namespace tflm_signal 45 | -------------------------------------------------------------------------------- /signal/src/rfft_int32.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "signal/src/complex.h" 20 | #include "signal/src/kiss_fft_wrappers/kiss_fft_int32.h" 21 | #include "signal/src/rfft.h" 22 | 23 | // TODO(b/286250473): remove namespace once de-duped libraries 24 | namespace tflm_signal { 25 | 26 | size_t RfftInt32GetNeededMemory(int32_t fft_length) { 27 | size_t state_size = 0; 28 | kiss_fft_fixed32::kiss_fftr_alloc(fft_length, 0, nullptr, &state_size); 29 | return state_size; 30 | } 31 | 32 | void* RfftInt32Init(int32_t fft_length, void* state, size_t state_size) { 33 | return kiss_fft_fixed32::kiss_fftr_alloc(fft_length, 0, state, &state_size); 34 | } 35 | 36 | void RfftInt32Apply(void* state, const int32_t* input, 37 | Complex* output) { 38 | kiss_fft_fixed32::kiss_fftr( 39 | static_cast(state), 40 | reinterpret_cast(input), 41 | reinterpret_cast(output)); 42 | } 43 | 44 | } // namespace tflm_signal 45 | -------------------------------------------------------------------------------- /signal/src/square_root.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_SQUARE_ROOT_H_ 17 | #define SIGNAL_SRC_SQUARE_ROOT_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | namespace tflm_signal { 23 | // TODO(b/286250473): remove namespace once de-duped libraries above 24 | 25 | // Square root 26 | uint16_t Sqrt32(uint32_t num); 27 | uint32_t Sqrt64(uint64_t num); 28 | 29 | } // namespace tflm_signal 30 | } // namespace tflite 31 | 32 | #endif // SIGNAL_SRC_SQUARE_ROOT_H_ 33 | -------------------------------------------------------------------------------- /signal/src/square_root_32.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/msb.h" 17 | #include "signal/src/square_root.h" 18 | 19 | namespace tflite { 20 | namespace tflm_signal { 21 | 22 | uint16_t Sqrt32(uint32_t num) { 23 | if (num == 0) { 24 | return 0; 25 | }; 26 | uint32_t res = 0; 27 | int max_bit_number = 32 - MostSignificantBit32(num); 28 | max_bit_number |= 1; 29 | uint32_t bit = 1u << (31 - max_bit_number); 30 | int iterations = (31 - max_bit_number) / 2 + 1; 31 | while (iterations--) { 32 | if (num >= res + bit) { 33 | num -= res + bit; 34 | res = (res >> 1U) + bit; 35 | } else { 36 | res >>= 1U; 37 | } 38 | bit >>= 2U; 39 | } 40 | // Do rounding - if we have the bits. 41 | if (num > res && res != 0xFFFF) ++res; 42 | return res; 43 | } 44 | 45 | } // namespace tflm_signal 46 | } // namespace tflite 47 | -------------------------------------------------------------------------------- /signal/src/square_root_64.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/msb.h" 17 | #include "signal/src/square_root.h" 18 | 19 | namespace tflite { 20 | namespace tflm_signal { 21 | 22 | uint32_t Sqrt64(uint64_t num) { 23 | // Take a shortcut and just use 32 bit operations if the upper word is all 24 | // clear. This will cause a slight off by one issue for numbers close to 2^32, 25 | // but it probably isn't going to matter (and gives us a big performance win). 26 | if ((num >> 32) == 0) { 27 | return Sqrt32(static_cast(num)); 28 | } 29 | uint64_t res = 0; 30 | int max_bit_number = 64 - MostSignificantBit64(num); 31 | max_bit_number |= 1; 32 | uint64_t bit = UINT64_C(1) << (63 - max_bit_number); 33 | int iterations = (63 - max_bit_number) / 2 + 1; 34 | while (iterations--) { 35 | if (num >= res + bit) { 36 | num -= res + bit; 37 | res = (res >> 1U) + bit; 38 | } else { 39 | res >>= 1U; 40 | } 41 | bit >>= 2U; 42 | } 43 | // Do rounding - if we have the bits. 44 | if (num > res && res != 0xFFFFFFFFLL) ++res; 45 | return res; 46 | } 47 | 48 | } // namespace tflm_signal 49 | } // namespace tflite 50 | -------------------------------------------------------------------------------- /signal/src/window.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "signal/src/window.h" 17 | 18 | #include 19 | 20 | // TODO(b/286250473): remove namespace once de-duped libraries 21 | namespace tflm_signal { 22 | 23 | void ApplyWindow(const int16_t* input, const int16_t* window, int size, 24 | int shift, int16_t* output) { 25 | for (int i = 0; i < size; ++i) { 26 | int32_t raw = (static_cast(input[i]) * window[i]) >> shift; 27 | if (raw < INT16_MIN) { 28 | output[i] = INT16_MIN; 29 | } else if (raw > INT16_MAX) { 30 | output[i] = INT16_MAX; 31 | } else { 32 | output[i] = static_cast(raw); 33 | } 34 | } 35 | } 36 | } // namespace tflm_signal 37 | -------------------------------------------------------------------------------- /signal/src/window.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef SIGNAL_SRC_WINDOW_H_ 17 | #define SIGNAL_SRC_WINDOW_H_ 18 | 19 | #include 20 | 21 | namespace tflm_signal { 22 | 23 | // Applies a window function to an input signal 24 | // 25 | // * `input` and `window` must be both of size `size` elements and are 26 | // multiplied element-by element. 27 | // * `shift` is a right shift to apply before writing the result to `output`. 28 | void ApplyWindow(const int16_t* input, const int16_t* window, int size, 29 | int shift, int16_t* output); 30 | } // namespace tflm_signal 31 | #endif // SIGNAL_SRC_WINDOW_H_ 32 | -------------------------------------------------------------------------------- /tensorflow/compiler/mlir/lite/core/api/error_reporter.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #include "tensorflow/compiler/mlir/lite/core/api/error_reporter.h" 16 | 17 | #include 18 | 19 | namespace tflite { 20 | 21 | int ErrorReporter::Report(const char* format, ...) { 22 | va_list args; 23 | va_start(args, format); 24 | int code = Report(format, args); 25 | va_end(args); 26 | return code; 27 | } 28 | 29 | // TODO(aselle): Make the name of ReportError on context the same, so 30 | // we can use the ensure functions w/o a context and w/ a reporter. 31 | int ErrorReporter::ReportError(void*, const char* format, ...) { 32 | va_list args; 33 | va_start(args, format); 34 | int code = Report(format, args); 35 | va_end(args); 36 | return code; 37 | } 38 | 39 | } // namespace tflite 40 | -------------------------------------------------------------------------------- /tensorflow/compiler/mlir/lite/kernels/internal/compatibility_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_COMPILER_MLIR_LITE_KERNELS_INTERNAL_COMPATABILITY_MACROS_H_ 17 | #define TENSORFLOW_COMPILER_MLIR_LITE_KERNELS_INTERNAL_COMPATABILITY_MACROS_H_ 18 | 19 | #include "tensorflow/lite/kernels/internal/compatibility.h" // IWYU pragma: keep 20 | 21 | #endif // TENSORFLOW_COMPILER_MLIR_LITE_KERNELS_INTERNAL_COMPATABILITY_MACROS_H_ 22 | -------------------------------------------------------------------------------- /tensorflow/compiler/mlir/lite/schema/schema_generated.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_GENERATED_H_ 16 | #define TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_GENERATED_H_ 17 | 18 | // This file should only be used by the make build to redirect schema_utils.cc 19 | // usage of the generated schema to the proper location. 20 | #include "tensorflow/lite/schema/schema_generated.h" // IWYU pragma: keep 21 | 22 | #endif // TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ 23 | -------------------------------------------------------------------------------- /tensorflow/compiler/mlir/lite/schema/schema_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_UTILS_H_ 16 | #define TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_UTILS_H_ 17 | 18 | #include "flatbuffers/flatbuffers.h" 19 | #include "tensorflow/compiler/mlir/lite/schema/schema_generated.h" 20 | 21 | namespace tflite { 22 | 23 | // The following methods are introduced to resolve op builtin code shortage 24 | // problem. The new builtin operator will be assigned to the extended builtin 25 | // code field in the flatbuffer schema. Those methods helps to hide builtin code 26 | // details. 27 | BuiltinOperator GetBuiltinCode(const OperatorCode *op_code); 28 | 29 | BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code); 30 | 31 | } // namespace tflite 32 | 33 | #endif // TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_UTILS_H_ 34 | -------------------------------------------------------------------------------- /tensorflow/lite/builtin_op_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | // Compatibility shim for new location of interface definitions. 16 | 17 | #ifndef TENSORFLOW_LITE_BUILTIN_OP_DATA_H_ 18 | #define TENSORFLOW_LITE_BUILTIN_OP_DATA_H_ 19 | 20 | #include "tensorflow/lite/core/c/builtin_op_data.h" 21 | 22 | #endif // TENSORFLOW_LITE_BUILTIN_OP_DATA_H_ 23 | -------------------------------------------------------------------------------- /tensorflow/lite/c/builtin_op_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_ 16 | #define TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_ 17 | 18 | /// For documentation, see 19 | /// third_party/tensorflow/lite/core/c/builtin_op_data.h 20 | 21 | #include "tensorflow/lite/core/c/builtin_op_data.h" 22 | 23 | #endif // TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_ 24 | -------------------------------------------------------------------------------- /tensorflow/lite/c/c_api_types.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_C_C_API_TYPES_H_ 16 | #define TENSORFLOW_LITE_C_C_API_TYPES_H_ 17 | 18 | /// \file 19 | /// 20 | /// C API types for TensorFlow Lite. 21 | /// 22 | /// For documentation, see tensorflow/lite/core/c/c_api_types.h 23 | 24 | #include "tensorflow/lite/core/c/c_api_types.h" 25 | 26 | #endif // TENSORFLOW_LITE_C_C_API_TYPES_H_ 27 | -------------------------------------------------------------------------------- /tensorflow/lite/c/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | /// \file 17 | /// 18 | /// This file defines common C types and APIs for implementing operations, 19 | /// delegates and other constructs in TensorFlow Lite. The actual operations and 20 | /// delegates can be defined using C++, but the interface between the 21 | /// interpreter and the operations are C. 22 | /// 23 | /// For documentation, see tensorflow/lite/core/c/common.h. 24 | /// 25 | /// See also c_api_opaque.h which has more ABI-stable variants of some of these 26 | /// APIs. 27 | 28 | #ifndef TENSORFLOW_LITE_C_COMMON_H_ 29 | #define TENSORFLOW_LITE_C_COMMON_H_ 30 | 31 | #include "tensorflow/lite/core/c/common.h" 32 | 33 | #endif // TENSORFLOW_LITE_C_COMMON_H_ 34 | -------------------------------------------------------------------------------- /tensorflow/lite/core/api/error_reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ 16 | #define TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ 17 | 18 | #include "tensorflow/compiler/mlir/lite/core/api/error_reporter.h" // IWYU pragma: export 19 | 20 | #endif // TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ 21 | -------------------------------------------------------------------------------- /tensorflow/lite/core/api/tensor_utils.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/core/api/tensor_utils.h" 17 | 18 | #include 19 | 20 | #include "tensorflow/lite/core/c/common.h" 21 | 22 | namespace tflite { 23 | 24 | TfLiteStatus ResetVariableTensor(TfLiteTensor* tensor) { 25 | if (!tensor->is_variable) { 26 | return kTfLiteOk; 27 | } 28 | // TODO(b/115961645): Implement - If a variable tensor has a buffer, reset it 29 | // to the value of the buffer. 30 | int value = 0; 31 | if (tensor->type == kTfLiteInt8) { 32 | value = tensor->params.zero_point; 33 | } 34 | // TODO(b/139446230): Provide a platform header to better handle these 35 | // specific scenarios. 36 | #if defined(__ANDROID__) || defined(__x86_64__) || defined(__i386__) || \ 37 | defined(__i386) || defined(__x86__) || defined(__X86__) || \ 38 | defined(_X86_) || defined(_M_IX86) || defined(_M_X64) 39 | memset(tensor->data.raw, value, tensor->bytes); 40 | #else 41 | char* raw_ptr = tensor->data.raw; 42 | for (size_t i = 0; i < tensor->bytes; ++i) { 43 | *raw_ptr = value; 44 | raw_ptr++; 45 | } 46 | #endif 47 | return kTfLiteOk; 48 | } 49 | 50 | } // namespace tflite 51 | -------------------------------------------------------------------------------- /tensorflow/lite/core/api/tensor_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ 17 | #define TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ 18 | 19 | #include "tensorflow/lite/core/c/common.h" 20 | 21 | namespace tflite { 22 | 23 | // Resets a variable tensor to the default value. 24 | TfLiteStatus ResetVariableTensor(TfLiteTensor* tensor); 25 | 26 | } // namespace tflite 27 | 28 | #endif // TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ 29 | -------------------------------------------------------------------------------- /tensorflow/lite/core/c/builtin_op_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | /// WARNING: Users of TensorFlow Lite should not include this file directly, 16 | /// but should instead include 17 | /// "third_party/tensorflow/lite/c/builtin_op_data.h". 18 | /// Only the TensorFlow Lite implementation itself should include this 19 | /// file directly. 20 | #ifndef TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_ 21 | #define TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_ 22 | 23 | #include "tensorflow/compiler/mlir/lite/core/c/builtin_op_data.h" // IWYU pragma: export 24 | #include "tensorflow/lite/core/c/common.h" // IWYU pragma: export 25 | 26 | #endif // TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_ 27 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/cppmath.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | #if defined(TF_LITE_USE_GLOBAL_CMATH_FUNCTIONS) || \ 23 | (defined(__ANDROID__) && !defined(__NDK_MAJOR__)) || defined(__ZEPHYR__) 24 | #define TF_LITE_GLOBAL_STD_PREFIX 25 | #else 26 | #define TF_LITE_GLOBAL_STD_PREFIX std 27 | #endif 28 | 29 | #define DECLARE_STD_GLOBAL_SWITCH1(tf_name, std_name) \ 30 | template \ 31 | inline T tf_name(const T x) { \ 32 | return TF_LITE_GLOBAL_STD_PREFIX::std_name(x); \ 33 | } 34 | 35 | DECLARE_STD_GLOBAL_SWITCH1(TfLiteRound, round) 36 | DECLARE_STD_GLOBAL_SWITCH1(TfLiteExpm1, expm1) 37 | 38 | } // namespace tflite 39 | 40 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ 41 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/max.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | #if defined(TF_LITE_USE_GLOBAL_MAX) || defined(__ZEPHYR__) 23 | inline float TfLiteMax(const float& x, const float& y) { 24 | return std::max(x, y); 25 | } 26 | #else 27 | template 28 | inline T TfLiteMax(const T& x, const T& y) { 29 | return std::fmax(x, y); 30 | } 31 | #endif 32 | 33 | } // namespace tflite 34 | 35 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ 36 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/min.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | #if defined(TF_LITE_USE_GLOBAL_MIN) || defined(__ZEPHYR__) 23 | inline float TfLiteMin(const float& x, const float& y) { 24 | return std::min(x, y); 25 | } 26 | #else 27 | template 28 | inline T TfLiteMin(const T& x, const T& y) { 29 | return std::fmin(x, y); 30 | } 31 | #endif 32 | 33 | } // namespace tflite 34 | 35 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ 36 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/optimized/neon_check.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ 17 | 18 | // TFLM does not need to utilize any Neon optimizations. 19 | 20 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ 21 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/ceil.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ 17 | 18 | #include 19 | 20 | #include "tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | 24 | namespace reference_ops { 25 | 26 | inline void Ceil(const RuntimeShape& input_shape, const float* input_data, 27 | const RuntimeShape& output_shape, float* output_data) { 28 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 29 | 30 | for (int i = 0; i < flat_size; ++i) { 31 | output_data[i] = std::ceil(input_data[i]); 32 | } 33 | } 34 | 35 | } // namespace reference_ops 36 | } // namespace tflite 37 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ 38 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/elu.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ELU_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ELU_H_ 17 | 18 | #include "tensorflow/lite/kernels/internal/cppmath.h" 19 | #include "tensorflow/lite/kernels/internal/types.h" 20 | 21 | namespace tflite { 22 | 23 | namespace reference_ops { 24 | 25 | inline void Elu(const RuntimeShape& input_shape, const float* input_data, 26 | const RuntimeShape& output_shape, float* output_data) { 27 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 28 | for (int i = 0; i < flat_size; ++i) { 29 | const float val = input_data[i]; 30 | output_data[i] = val < 0.0f ? TfLiteExpm1(val) : val; 31 | } 32 | } 33 | 34 | } // namespace reference_ops 35 | } // namespace tflite 36 | 37 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ELU_H_ 38 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/exp.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ 17 | 18 | #include 19 | 20 | #include "ruy/profiler/instrumentation.h" // from @ruy 21 | #include "tensorflow/lite/kernels/internal/types.h" 22 | 23 | namespace tflite { 24 | namespace reference_ops { 25 | 26 | template 27 | inline void Exp(const T* input_data, const size_t num_elements, 28 | T* output_data) { 29 | ruy::profiler::ScopeLabel label("Exp"); 30 | for (size_t idx = 0; idx < num_elements; ++idx) { 31 | output_data[idx] = std::exp(input_data[idx]); 32 | } 33 | } 34 | 35 | } // namespace reference_ops 36 | } // namespace tflite 37 | 38 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ 39 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/fill.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FILL_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FILL_H_ 17 | 18 | #include 19 | 20 | #include "tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | namespace reference_ops { 24 | 25 | template 26 | void Fill(const RuntimeShape& value_shape, const T* value_data, 27 | const RuntimeShape& output_shape, T* output_data) { 28 | TFLITE_DCHECK_EQ(value_shape.DimensionsCount(), 0); 29 | const int flat_size = output_shape.FlatSize(); 30 | for (int i = 0; i < flat_size; ++i) { 31 | output_data[i] = *value_data; 32 | } 33 | } 34 | 35 | } // namespace reference_ops 36 | } // namespace tflite 37 | 38 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FILL_H_ 39 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/floor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ 17 | 18 | #include 19 | 20 | #include "tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | 24 | namespace reference_ops { 25 | 26 | template 27 | inline void Floor(const RuntimeShape& input_shape, const T* input_data, 28 | const RuntimeShape& output_shape, T* output_data) { 29 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 30 | 31 | for (int i = 0; i < flat_size; i++) { 32 | int offset = i; 33 | output_data[offset] = 34 | static_cast(std::floor(static_cast(input_data[offset]))); 35 | } 36 | } 37 | 38 | } // namespace reference_ops 39 | } // namespace tflite 40 | 41 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ 42 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/floor_div.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_DIV_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_DIV_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "tensorflow/lite/kernels/internal/types.h" 22 | 23 | namespace tflite { 24 | namespace reference_ops { 25 | 26 | template 27 | T FloorDiv(T input1, T input2) { 28 | return std::floor(std::divides()(static_cast(input1), 29 | static_cast(input2))); 30 | } 31 | 32 | } // namespace reference_ops 33 | } // namespace tflite 34 | 35 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_DIV_H_ 36 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/floor_mod.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_MOD_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_MOD_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace tflite { 22 | 23 | namespace reference_ops { 24 | 25 | template 26 | T FloorMod(T input1, T input2) { 27 | struct FloatMod { 28 | float operator()(const float lhs, const float rhs) const { 29 | return std::fmod(lhs, rhs); 30 | } 31 | }; 32 | using ModFunc = typename std::conditional::value, 33 | std::modulus, FloatMod>::type; 34 | ModFunc mod_func; 35 | T trunc_mod = mod_func(input1, input2); 36 | return (trunc_mod != 0) && ((input2 < 0) != (trunc_mod < 0)) 37 | ? (trunc_mod + input2) 38 | : trunc_mod; 39 | } 40 | 41 | } // namespace reference_ops 42 | } // namespace tflite 43 | 44 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_MOD_H_ 45 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/integer_ops/mean.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_ 17 | 18 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_ 19 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/reference/neg.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ 17 | 18 | #include "tensorflow/lite/kernels/internal/types.h" 19 | 20 | namespace tflite { 21 | 22 | namespace reference_ops { 23 | 24 | template 25 | inline void Negate(const RuntimeShape& input_shape, const T* input_data, 26 | const RuntimeShape& output_shape, T* output_data) { 27 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 28 | 29 | for (int i = 0; i < flat_size; ++i) { 30 | output_data[i] = -input_data[i]; 31 | } 32 | } 33 | 34 | } // namespace reference_ops 35 | } // namespace tflite 36 | 37 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ 38 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/runtime_shape.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/kernels/internal/runtime_shape.h" 17 | 18 | namespace tflite { 19 | 20 | // Defining a constexpr static class member is necessary in C++11 21 | constexpr int tflite::RuntimeShape::kMaxSmallSize; 22 | 23 | } // namespace tflite 24 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/tensor_ctypes.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | RuntimeShape GetTensorShape(const TfLiteTensor* tensor) { 23 | if (tensor == nullptr) { 24 | return RuntimeShape(); 25 | } 26 | 27 | TfLiteIntArray* dims = tensor->dims; 28 | const int dims_size = dims->size; 29 | const int32_t* dims_data = reinterpret_cast(dims->data); 30 | return RuntimeShape(dims_size, dims_data); 31 | } 32 | 33 | RuntimeShape GetTensorShape(std::vector data) { 34 | return RuntimeShape(data.size(), data.data()); 35 | } 36 | 37 | } // namespace tflite 38 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/tensor_ctypes.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 17 | 18 | #include 19 | 20 | #include "tensorflow/lite/core/c/common.h" 21 | #include "tensorflow/lite/core/macros.h" 22 | #include "tensorflow/lite/kernels/internal/types.h" 23 | 24 | namespace tflite { 25 | 26 | template 27 | inline T* GetTensorData(TfLiteTensor* tensor) { 28 | return tensor != nullptr ? reinterpret_cast(tensor->data.raw) : nullptr; 29 | } 30 | 31 | template 32 | inline const T* GetTensorData(const TfLiteTensor* tensor) { 33 | return tensor != nullptr ? reinterpret_cast(tensor->data.raw) 34 | : nullptr; 35 | } 36 | 37 | TFLITE_NOINLINE RuntimeShape GetTensorShape(const TfLiteTensor* tensor); 38 | RuntimeShape GetTensorShape(std::vector data); 39 | 40 | } // namespace tflite 41 | 42 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 43 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/internal/tensor_utils.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ============================================================================== 15 | */ 16 | 17 | // internal/reference/portable_tensor_utils.h has the implementation of the 18 | // functions declared in internal/portable_tensor_utils.h. This somewhat 19 | // confusing setup is derived from how the code is organized in TfLite where it 20 | // is used to select between NEON, SSE and portable implementaitons. See 21 | // https://github.com/tensorflow/tensorflow/blob/d76c23975c4a3a0d7987cfe3f45c76566df06180/tensorflow/lite/kernels/internal/tensor_utils.cc 22 | // for how the code is written in TfLite. 23 | 24 | #include "tensorflow/lite/kernels/internal/portable_tensor_utils.h" 25 | #include "tensorflow/lite/kernels/internal/reference/portable_tensor_utils.h" 26 | -------------------------------------------------------------------------------- /tensorflow/lite/kernels/op_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 16 | #define TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 17 | 18 | #include "tensorflow/lite/micro/micro_log.h" 19 | 20 | #if !defined(TF_LITE_MCU_DEBUG_LOG) 21 | #include 22 | #define TFLITE_ABORT abort() 23 | #else 24 | inline void AbortImpl() { 25 | MicroPrintf("HALTED"); 26 | while (1) { 27 | } 28 | } 29 | #define TFLITE_ABORT AbortImpl(); 30 | #endif 31 | 32 | #if defined(NDEBUG) 33 | #define TFLITE_ASSERT_FALSE (static_cast(0)) 34 | #else 35 | #define TFLITE_ASSERT_FALSE TFLITE_ABORT 36 | #endif 37 | 38 | #define TF_LITE_FATAL(msg) \ 39 | do { \ 40 | MicroPrintf("%s", (msg)); \ 41 | TFLITE_ABORT; \ 42 | } while (0) 43 | 44 | #define TF_LITE_ASSERT(x) \ 45 | do { \ 46 | if (!(x)) TF_LITE_FATAL(#x); \ 47 | } while (0) 48 | 49 | #endif // TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 50 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/compatibility.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ 16 | #define TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ 17 | 18 | // C++ will automatically create class-specific delete operators for virtual 19 | // objects, which by default call the global delete function. For embedded 20 | // applications we want to avoid this, and won't be calling new/delete on these 21 | // objects, so we need to override the default implementation with one that does 22 | // nothing to avoid linking in ::delete(). 23 | // This macro needs to be included in all subclasses of a virtual base class in 24 | // the private section. 25 | #ifdef TF_LITE_STATIC_MEMORY 26 | #define TF_LITE_REMOVE_VIRTUAL_DELETE \ 27 | void operator delete(void* p) {} 28 | #else 29 | #define TF_LITE_REMOVE_VIRTUAL_DELETE 30 | #endif 31 | 32 | #endif // TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ 33 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/debug_log.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ 16 | #define TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ 17 | 18 | #ifdef __cplusplus 19 | #include 20 | #include 21 | #else 22 | #include 23 | #include 24 | #endif // __cplusplus 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif // __cplusplus 29 | 30 | // These functions should be implemented by each target platform, and provide a 31 | // way for strings to be output to some text stream. For more information, see 32 | // the tensorflow/lite/micro/debug_log.cc file. These functions should support 33 | // standard C/C++ stdio style formatting operations. 34 | void DebugLog(const char* format, va_list args); 35 | int DebugVsnprintf(char* buffer, size_t buf_size, const char* format, 36 | va_list vlist); 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif // __cplusplus 41 | 42 | #endif // TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ 43 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/esp/micro_time.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include "tensorflow/lite/micro/micro_time.h" 18 | 19 | namespace tflite { 20 | 21 | uint32_t ticks_per_second() { return 1000000; } 22 | 23 | uint32_t GetCurrentTimeTicks() { return esp_timer_get_time(); } 24 | 25 | } // namespace tflite 26 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/hexdump.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The TensorFlow Authors. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef TENSORFLOW_LITE_MICRO_HEXDUMP_H_ 16 | #define TENSORFLOW_LITE_MICRO_HEXDUMP_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "tensorflow/lite/micro/span.h" 22 | 23 | namespace tflite { 24 | 25 | // Displays the contents of a memory region, formatted in hexadecimal and ASCII 26 | // in a style matching Python's hexdump module, using DebugLog(). 27 | void hexdump(Span region); 28 | 29 | // Writes the contents of a memory region, formatted in hexadecimal and ASCII 30 | // in a style matching Python's hexdump module, to a buffer. Returns the portion 31 | // of the buffer written. 32 | Span hexdump(Span region, Span buffer); 33 | 34 | } // end namespace tflite 35 | 36 | #endif // TENSORFLOW_LITE_MICRO_HEXDUMP_H_ 37 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H 18 | 19 | extern const int g_gen_data_size_circular_buffer_config; 20 | extern const unsigned char g_gen_data_circular_buffer_config[]; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/dequantize.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_DEQUANTIZE_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_DEQUANTIZE_H_ 18 | 19 | #include "tensorflow/lite/c/builtin_op_data.h" 20 | #include "tensorflow/lite/c/common.h" 21 | #include "tensorflow/lite/kernels/internal/types.h" 22 | 23 | namespace tflite { 24 | 25 | struct DequantizeOpData { 26 | tflite::DequantizationParams quantization_params; 27 | // The scaling factor from input to output (aka the 'real multiplier') can 28 | // be represented as a fixed point multiplier plus a left shift. 29 | int32_t output_multiplier; 30 | int output_shift; 31 | int32_t output_zero_point; 32 | }; 33 | 34 | TfLiteStatus DequantizePrepare(TfLiteContext* context, TfLiteNode* node); 35 | 36 | } // namespace tflite 37 | 38 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_DEQUANTIZE_H_ 39 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H 18 | 19 | extern const int g_gen_data_size_none_regular_nms; 20 | extern const unsigned char g_gen_data_none_regular_nms[]; 21 | 22 | extern const int g_gen_data_size_regular_nms; 23 | extern const unsigned char g_gen_data_regular_nms[]; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/esp_nn/README.md: -------------------------------------------------------------------------------- 1 | # Info 2 | 3 | These are the Espressif chipset specific replacement kernels. 4 | The kernels call optimized routines or reference routines depending upon optimization option selected. 5 | 6 | By default optimizations are selected if available. 7 | To change this behaviour, please make the appropriate `ESP-NN` menu selection after running: 8 | 9 | ``` 10 | idf.py menuconfig 11 | ``` 12 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/ethosu.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // 17 | // This is a stub file for non-Ethos platforms 18 | // 19 | #include "tensorflow/lite/micro/micro_common.h" 20 | 21 | namespace tflite { 22 | 23 | TFLMRegistration* Register_ETHOSU() { return nullptr; } 24 | 25 | const char* GetString_ETHOSU() { return ""; } 26 | 27 | } // namespace tflite 28 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/ethosu.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_ETHOSU_H_ 16 | #define TENSORFLOW_LITE_MICRO_KERNELS_ETHOSU_H_ 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | 20 | namespace tflite { 21 | 22 | TFLMRegistration* Register_ETHOSU(); 23 | 24 | const char* GetString_ETHOSU(); 25 | 26 | } // namespace tflite 27 | 28 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_ETHOSU_H_ 29 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/hard_swish.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_HARD_SWISH_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_HARD_SWISH_H_ 18 | 19 | #include "tensorflow/lite/c/builtin_op_data.h" 20 | #include "tensorflow/lite/c/common.h" 21 | 22 | namespace tflite { 23 | 24 | extern const int kHardSwishInputTensor; 25 | extern const int kHardSwishOutputTensor; 26 | 27 | TfLiteStatus HardSwishPrepare(TfLiteContext* context, TfLiteNode* node); 28 | } // namespace tflite 29 | 30 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_HARD_SWISH_H_ 31 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/leaky_relu.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_LEAKY_RELU_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_LEAKY_RELU_H_ 18 | 19 | #include "tensorflow/lite/c/common.h" 20 | 21 | namespace tflite { 22 | 23 | // Input/output tensor index. 24 | extern const int kInputTensor; 25 | extern const int kOutputTensor; 26 | 27 | struct LeakyReluOpData { 28 | // quantization parameters 29 | int32_t output_multiplier_alpha; 30 | int32_t output_shift_alpha; 31 | int32_t output_multiplier_identity; 32 | int32_t output_shift_identity; 33 | int32_t input_zero_point; 34 | int32_t output_zero_point; 35 | }; 36 | 37 | TfLiteStatus CalculateOpDataLeakyRelu(TfLiteContext* context, TfLiteNode* node); 38 | 39 | TfLiteStatus LeakyReluPrepare(TfLiteContext* context, TfLiteNode* node); 40 | 41 | } // namespace tflite 42 | 43 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_LEAKY_RELU_H_ 44 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/logical.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #include "tensorflow/lite/micro/kernels/logical.h" 16 | 17 | #include "tensorflow/lite/c/common.h" 18 | #include "tensorflow/lite/kernels/internal/reference/binary_function.h" 19 | #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" 20 | #include "tensorflow/lite/kernels/op_macros.h" 21 | #include "tensorflow/lite/micro/kernels/kernel_util.h" 22 | 23 | namespace tflite { 24 | namespace { 25 | 26 | TfLiteStatus LogicalOrEval(TfLiteContext* context, TfLiteNode* node) { 27 | return LogicalImpl(context, node, LogicalOr); 28 | } 29 | 30 | TfLiteStatus LogicalAndEval(TfLiteContext* context, TfLiteNode* node) { 31 | return LogicalImpl(context, node, LogicalAnd); 32 | } 33 | 34 | } // namespace 35 | 36 | TFLMRegistration Register_LOGICAL_OR() { 37 | return tflite::micro::RegisterOp(nullptr, nullptr, LogicalOrEval); 38 | } 39 | 40 | TFLMRegistration Register_LOGICAL_AND() { 41 | return tflite::micro::RegisterOp(nullptr, nullptr, LogicalAndEval); 42 | } 43 | 44 | } // namespace tflite 45 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/logical.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_LOGICAL_H_ 16 | #define TENSORFLOW_LITE_MICRO_KERNELS_LOGICAL_H_ 17 | 18 | #include "tensorflow/lite/c/builtin_op_data.h" 19 | #include "tensorflow/lite/c/common.h" 20 | 21 | namespace tflite { 22 | // Input/output tensor index. 23 | extern const int kLogicalInputTensor1; 24 | extern const int kLogicalInputTensor2; 25 | extern const int kLogicalOutputTensor; 26 | 27 | TfLiteStatus LogicalImpl(TfLiteContext* context, TfLiteNode* node, 28 | bool (*func)(bool, bool)); 29 | 30 | bool LogicalOr(bool x, bool y); 31 | bool LogicalAnd(bool x, bool y); 32 | 33 | } // namespace tflite 34 | 35 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_LOGICAL_H_ 36 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/logistic.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_LOGISTIC_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_LOGISTIC_H_ 18 | 19 | #include 20 | 21 | #include "tensorflow/lite/c/builtin_op_data.h" 22 | #include "tensorflow/lite/c/common.h" 23 | 24 | namespace tflite { 25 | extern const int kLogisticInputTensor; 26 | extern const int kLogisticOutputTensor; 27 | 28 | struct OpDataLogistic { 29 | int32_t input_zero_point; 30 | int32_t input_range_radius; 31 | int32_t input_multiplier; 32 | int input_left_shift; 33 | }; 34 | 35 | TfLiteStatus CalculateArithmeticOpDataLogistic(TfLiteContext* context, 36 | TfLiteNode* node, 37 | OpDataLogistic* data); 38 | 39 | TfLiteStatus LogisticPrepare(TfLiteContext* context, TfLiteNode* node); 40 | 41 | } // namespace tflite 42 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_LOGISTIC_H_ 43 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/pad.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_PAD_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_PAD_H_ 18 | 19 | #include "tensorflow/lite/c/common.h" 20 | #include "tensorflow/lite/micro/kernels/kernel_util.h" 21 | 22 | namespace tflite { 23 | 24 | struct OpData { 25 | PadParams params; 26 | int32_t output_zero_point; 27 | }; 28 | 29 | void* PadInit(TfLiteContext* context, const char* buffer, size_t length); 30 | TfLiteStatus PadPrepare(TfLiteContext* context, TfLiteNode* node); 31 | 32 | TFLMRegistration Register_PAD(); 33 | TFLMRegistration Register_PADV2(); 34 | 35 | #if defined(CMSIS_NN) 36 | TFLMRegistration Register_PAD_INT8(); 37 | #else 38 | inline TFLMRegistration Register_PAD_INT8() { return Register_PAD(); } 39 | #endif 40 | 41 | } // namespace tflite 42 | 43 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_PAD_H_ 44 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/prelu.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_PRELU_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_PRELU_H_ 18 | 19 | #include "tensorflow/lite/c/common.h" 20 | #include "tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | 24 | TfLiteStatus CalculatePreluParams(const TfLiteTensor* input, 25 | const TfLiteTensor* alpha, 26 | TfLiteTensor* output, PreluParams* params); 27 | 28 | void BroadcastPrelu4DSlowFloat(const RuntimeShape& unextended_input1_shape, 29 | const float* input1_data, 30 | const RuntimeShape& unextended_input2_shape, 31 | const float* input2_data, 32 | const RuntimeShape& unextended_output_shape, 33 | float* output_data); 34 | 35 | TfLiteStatus PreluPrepare(TfLiteContext* context, TfLiteNode* node); 36 | 37 | } // namespace tflite 38 | 39 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_PRELU_H_ 40 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/quantize.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/micro/kernels/quantize.h" 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | #include "tensorflow/lite/kernels/internal/quantization_util.h" 20 | #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" 21 | #include "tensorflow/lite/kernels/kernel_util.h" 22 | #include "tensorflow/lite/micro/kernels/kernel_util.h" 23 | #include "tensorflow/lite/micro/micro_utils.h" 24 | 25 | namespace tflite { 26 | namespace { 27 | 28 | void* InitQuantizeReference(TfLiteContext* context, const char* buffer, 29 | size_t length) { 30 | TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); 31 | return context->AllocatePersistentBuffer(context, 32 | sizeof(OpDataQuantizeReference)); 33 | } 34 | 35 | } // namespace 36 | 37 | TFLMRegistration Register_QUANTIZE() { 38 | return tflite::micro::RegisterOp( 39 | InitQuantizeReference, PrepareQuantizeReference, EvalQuantizeReference); 40 | } 41 | 42 | } // namespace tflite 43 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/quantize.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ 16 | #define TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | #include "tensorflow/lite/kernels/internal/types.h" 20 | 21 | namespace tflite { 22 | 23 | struct OpDataQuantizeReference { 24 | tflite::QuantizationParams quantization_params; 25 | // The scaling factor from input to output (aka the 'real multiplier') can 26 | // be represented as a fixed point multiplier plus a left shift. 27 | int32_t requantize_output_multiplier; 28 | int requantize_output_shift; 29 | 30 | int32_t input_zero_point; 31 | }; 32 | 33 | TfLiteStatus EvalQuantizeReference(TfLiteContext* context, TfLiteNode* node); 34 | TfLiteStatus PrepareQuantizeReference(TfLiteContext* context, TfLiteNode* node); 35 | } // namespace tflite 36 | 37 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ 38 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/reshape.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/c/builtin_op_data.h" 17 | #include "tensorflow/lite/c/common.h" 18 | 19 | namespace tflite { 20 | 21 | constexpr int kReshapeInputTensor = 0; 22 | constexpr int kReshapeOutputTensor = 0; 23 | 24 | TfLiteStatus PrepareReshapeReference(TfLiteContext* context, TfLiteNode* node); 25 | 26 | } // namespace tflite 27 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/kernels/strided_slice.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_STRIDED_SLICE_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_STRIDED_SLICE_H_ 18 | 19 | #include 20 | 21 | #include "tensorflow/lite/c/builtin_op_data.h" 22 | #include "tensorflow/lite/c/common.h" 23 | #include "tensorflow/lite/micro/micro_common.h" 24 | 25 | namespace tflite { 26 | 27 | constexpr int kStridedSliceInputTensor = 0; 28 | constexpr int kStridedSliceBeginTensor = 1; 29 | constexpr int kStridedSliceEndTensor = 2; 30 | constexpr int kStridedSliceStridesTensor = 3; 31 | constexpr int kStridedSliceOutputTensor = 0; 32 | 33 | void* StridedSliceInit(TfLiteContext* context, const char* buffer, 34 | size_t length); 35 | 36 | TfLiteStatus StridedSlicePrepare(TfLiteContext* context, TfLiteNode* node); 37 | 38 | } // namespace tflite 39 | 40 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_STRIDED_SLICE_H_ 41 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/micro_arena_constants.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_ARENA_CONSTANTS_H_ 17 | #define TENSORFLOW_LITE_MICRO_MICRO_ARENA_CONSTANTS_H_ 18 | 19 | namespace tflite { 20 | 21 | // The default buffer alignment requirement. 22 | // We align tensor buffers to 16-byte boundaries, since this is a common 23 | // requirement for SIMD extensions. 24 | constexpr int MicroArenaBufferAlignment() { return 16; } 25 | 26 | } // namespace tflite 27 | 28 | #endif // TENSORFLOW_LITE_MICRO_MICRO_ARENA_CONSTANTS_H_ 29 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/micro_common.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef THIRD_PARTY_TFLITE_MICRO_TENSORFLOW_LITE_MICRO_MICRO_COMMON_H_ 16 | #define THIRD_PARTY_TFLITE_MICRO_TENSORFLOW_LITE_MICRO_MICRO_COMMON_H_ 17 | 18 | #include "tensorflow/lite/c/common.h" 19 | 20 | // TFLMRegistration defines the API that TFLM kernels need to implement. 21 | // This will be replacing the current TfLiteRegistration_V1 struct with 22 | // something more compatible Embedded enviroment TFLM is used in. 23 | struct TFLMRegistration { 24 | void* (*init)(TfLiteContext* context, const char* buffer, size_t length); 25 | void (*free)(TfLiteContext* context, void* buffer); 26 | TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node); 27 | TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node); 28 | void (*reset)(TfLiteContext* context, void* buffer); 29 | int32_t builtin_code; 30 | const char* custom_name; 31 | }; 32 | 33 | struct TFLMInferenceRegistration { 34 | TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node); 35 | void (*reset)(TfLiteContext* context, void* buffer); 36 | }; 37 | 38 | #endif // THIRD_PARTY_TFLITE_MICRO_TENSORFLOW_LITE_MICRO_MICRO_COMMON_H_ 39 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/micro_profiler_interface.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_PROFILER_INTERFACE_H_ 17 | #define TENSORFLOW_LITE_MICRO_MICRO_PROFILER_INTERFACE_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | 23 | // Interface class that the TFLM framework relies on for profiling. 24 | class MicroProfilerInterface { 25 | public: 26 | virtual ~MicroProfilerInterface() {} 27 | 28 | // Marks the start of a new event and returns an event handle that can be used 29 | // to mark the end of the event via EndEvent. 30 | virtual uint32_t BeginEvent(const char* tag) = 0; 31 | 32 | // Marks the end of an event associated with event_handle. 33 | virtual void EndEvent(uint32_t event_handle) = 0; 34 | }; 35 | 36 | } // namespace tflite 37 | 38 | #endif // TENSORFLOW_LITE_MICRO_MICRO_PROFILER_INTERFACE_H_ 39 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/micro_time.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ 16 | #define TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | // These functions should be implemented by each target platform, and provide an 23 | // accurate tick count along with how many ticks there are per second. 24 | uint32_t ticks_per_second(); 25 | 26 | // Return time in ticks. The meaning of a tick varies per platform. 27 | uint32_t GetCurrentTimeTicks(); 28 | 29 | inline uint32_t TicksToMs(int32_t ticks) { 30 | uint32_t _ticks_per_second = ticks_per_second(); 31 | _ticks_per_second = 32 | _ticks_per_second > 0 ? _ticks_per_second : 1; // zero divide prevention 33 | return static_cast(1000.0f * static_cast(ticks) / 34 | static_cast(_ticks_per_second)); 35 | } 36 | 37 | } // namespace tflite 38 | 39 | #endif // TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ 40 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/system_setup.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/micro/system_setup.h" 17 | 18 | namespace tflite { 19 | 20 | // To add an equivalent function for your own platform, create your own 21 | // implementation file, and place it in a subfolder named after the target. See 22 | // tensorflow/lite/micro/debug_log.cc for a similar example. 23 | void InitializeTarget() {} 24 | 25 | } // namespace tflite 26 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/system_setup.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_ 16 | #define TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_ 17 | 18 | namespace tflite { 19 | 20 | // This should called during initialization of TFLM binaries and tests. It can 21 | // be specialized if there is a need for custom target-specific intialization. 22 | // For more information, see tensorflow/lite/micro/system_setup.cc. 23 | void InitializeTarget(); 24 | 25 | } // namespace tflite 26 | 27 | #endif // TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_ 28 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #include "tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.h" 16 | 17 | #include "tensorflow/lite/c/c_api_types.h" 18 | #include "tensorflow/lite/core/api/error_reporter.h" 19 | #include "tensorflow/lite/core/api/flatbuffer_conversions.h" 20 | #include "tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h" 21 | #include "tensorflow/lite/schema/schema_generated.h" 22 | 23 | namespace tflite { 24 | TfLiteStatus ConvertTensorType(TensorType tensor_type, TfLiteType* type) { 25 | return ConvertTensorType(tensor_type, type, tflite::GetMicroErrorReporter()); 26 | } 27 | 28 | TfLiteStatus CallBuiltinParseFunction(TfLiteBridgeBuiltinParseFunction parser, 29 | const Operator* op, 30 | BuiltinDataAllocator* allocator, 31 | void** builtin_data) { 32 | return parser(op, tflite::GetMicroErrorReporter(), allocator, builtin_data); 33 | } 34 | } // namespace tflite 35 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/tflite_bridge/micro_error_reporter.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "tensorflow/lite/micro/micro_log.h" 23 | 24 | namespace { 25 | uint8_t micro_error_reporter_buffer[sizeof(tflite::MicroErrorReporter)]; 26 | tflite::MicroErrorReporter* error_reporter_ = nullptr; 27 | 28 | } // namespace 29 | 30 | namespace tflite { 31 | ErrorReporter* GetMicroErrorReporter() { 32 | if (error_reporter_ == nullptr) { 33 | error_reporter_ = new (micro_error_reporter_buffer) MicroErrorReporter(); 34 | } 35 | return error_reporter_; 36 | } 37 | 38 | int MicroErrorReporter::Report(const char* format, va_list args) { 39 | VMicroPrintf(format, args); 40 | return 0; 41 | } 42 | 43 | } // namespace tflite 44 | -------------------------------------------------------------------------------- /tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_TFLITE_BRIDGE_MICRO_ERROR_REPORTER_H_ 16 | #define TENSORFLOW_LITE_MICRO_TFLITE_BRIDGE_MICRO_ERROR_REPORTER_H_ 17 | 18 | #include 19 | 20 | #include "tensorflow/lite/core/api/error_reporter.h" 21 | #include "tensorflow/lite/micro/compatibility.h" 22 | 23 | namespace tflite { 24 | // Get a pointer to a singleton global error reporter. 25 | ErrorReporter* GetMicroErrorReporter(); 26 | class MicroErrorReporter : public ErrorReporter { 27 | public: 28 | ~MicroErrorReporter() override {} 29 | int Report(const char* format, va_list args) override; 30 | 31 | private: 32 | TF_LITE_REMOVE_VIRTUAL_DELETE 33 | }; 34 | 35 | } // namespace tflite 36 | 37 | #endif // TENSORFLOW_LITE_MICRO_TFLITE_BRIDGE_MICRO_ERROR_REPORTER_H_ 38 | -------------------------------------------------------------------------------- /tensorflow/lite/schema/schema_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ 16 | #define TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ 17 | 18 | #include "tensorflow/compiler/mlir/lite/schema/schema_utils.h" // IWYU pragma: keep 19 | 20 | #endif // TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ 21 | -------------------------------------------------------------------------------- /third_party/flatbuffers/include/flatbuffers/buffer_ref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_BUFFER_REF_H_ 18 | #define FLATBUFFERS_BUFFER_REF_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | #include "flatbuffers/verifier.h" 22 | 23 | namespace flatbuffers { 24 | 25 | // Convenient way to bundle a buffer and its length, to pass it around 26 | // typed by its root. 27 | // A BufferRef does not own its buffer. 28 | struct BufferRefBase {}; // for std::is_base_of 29 | 30 | template struct BufferRef : BufferRefBase { 31 | BufferRef() : buf(nullptr), len(0), must_free(false) {} 32 | BufferRef(uint8_t *_buf, uoffset_t _len) 33 | : buf(_buf), len(_len), must_free(false) {} 34 | 35 | ~BufferRef() { 36 | if (must_free) free(buf); 37 | } 38 | 39 | const T *GetRoot() const { return flatbuffers::GetRoot(buf); } 40 | 41 | bool Verify() { 42 | Verifier verifier(buf, len); 43 | return verifier.VerifyBuffer(nullptr); 44 | } 45 | 46 | uint8_t *buf; 47 | uoffset_t len; 48 | bool must_free; 49 | }; 50 | 51 | } // namespace flatbuffers 52 | 53 | #endif // FLATBUFFERS_BUFFER_REF_H_ 54 | -------------------------------------------------------------------------------- /third_party/flatbuffers/include/flatbuffers/file_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_FILE_MANAGER_H_ 18 | #define FLATBUFFERS_FILE_MANAGER_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "flatbuffers/util.h" 24 | 25 | namespace flatbuffers { 26 | 27 | // A File interface to write data to file by default or 28 | // save only file names 29 | class FileManager { 30 | public: 31 | FileManager() = default; 32 | virtual ~FileManager() = default; 33 | 34 | virtual bool SaveFile(const std::string &absolute_file_name, 35 | const std::string &content) = 0; 36 | 37 | virtual bool LoadFile(const std::string &absolute_file_name, 38 | std::string *buf) = 0; 39 | 40 | private: 41 | // Copying is not supported. 42 | FileManager(const FileManager &) = delete; 43 | FileManager &operator=(const FileManager &) = delete; 44 | }; 45 | 46 | } // namespace flatbuffers 47 | 48 | #endif // FLATBUFFERS_FILE_MANAGER_H_ 49 | -------------------------------------------------------------------------------- /third_party/flatbuffers/include/flatbuffers/flex_flat_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_FLEX_FLAT_UTIL_H_ 18 | #define FLATBUFFERS_FLEX_FLAT_UTIL_H_ 19 | 20 | #include "flatbuffers/flatbuffers.h" 21 | #include "flatbuffers/flexbuffers.h" 22 | 23 | namespace flexbuffers { 24 | 25 | // Verifies the `nested` flexbuffer within a flatbuffer vector is valid. 26 | inline bool VerifyNestedFlexBuffer( 27 | const flatbuffers::Vector *const nested, 28 | flatbuffers::Verifier &verifier) { 29 | if (!nested) return true; 30 | return verifier.Check(flexbuffers::VerifyBuffer( 31 | nested->data(), nested->size(), verifier.GetFlexReuseTracker())); 32 | } 33 | 34 | } // namespace flexbuffers 35 | 36 | #endif // FLATBUFFERS_FLEX_FLAT_UTIL_H_ 37 | -------------------------------------------------------------------------------- /third_party/flatbuffers/include/flatbuffers/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_STRUCT_H_ 18 | #define FLATBUFFERS_STRUCT_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | 22 | namespace flatbuffers { 23 | 24 | // "structs" are flat structures that do not have an offset table, thus 25 | // always have all members present and do not support forwards/backwards 26 | // compatible extensions. 27 | 28 | class Struct FLATBUFFERS_FINAL_CLASS { 29 | public: 30 | template T GetField(uoffset_t o) const { 31 | return ReadScalar(&data_[o]); 32 | } 33 | 34 | template T GetStruct(uoffset_t o) const { 35 | return reinterpret_cast(&data_[o]); 36 | } 37 | 38 | const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; } 39 | uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; } 40 | 41 | private: 42 | // private constructor & copy constructor: you obtain instances of this 43 | // class by pointing to existing data only 44 | Struct(); 45 | Struct(const Struct &); 46 | Struct &operator=(const Struct &); 47 | 48 | uint8_t data_[1]; 49 | }; 50 | 51 | } // namespace flatbuffers 52 | 53 | #endif // FLATBUFFERS_STRUCT_H_ 54 | -------------------------------------------------------------------------------- /third_party/kissfft/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003-2010 Mark Borgerding 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /third_party/kissfft/tools/kiss_fftr.h: -------------------------------------------------------------------------------- 1 | #ifndef KISS_FTR_H 2 | #define KISS_FTR_H 3 | 4 | #include "kiss_fft.h" 5 | #ifdef __cplusplus 6 | extern "C++" { 7 | #endif 8 | 9 | 10 | /* 11 | 12 | Real optimized version can save about 45% cpu time vs. complex fft of a real seq. 13 | 14 | 15 | 16 | */ 17 | 18 | typedef struct kiss_fftr_state *kiss_fftr_cfg; 19 | 20 | 21 | kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem); 22 | /* 23 | nfft must be even 24 | 25 | If you don't care to allocate space, use mem = lenmem = NULL 26 | */ 27 | 28 | 29 | void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata); 30 | /* 31 | input timedata has nfft scalar points 32 | output freqdata has nfft/2+1 complex points 33 | */ 34 | 35 | void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata); 36 | /* 37 | input freqdata has nfft/2+1 complex points 38 | output timedata has nfft scalar points 39 | */ 40 | 41 | #define kiss_fftr_free free 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif 47 | --------------------------------------------------------------------------------