> 文档中心 > 在OpenHarmony上,使用tensorflow lite推理Yamnet实现语音分类

在OpenHarmony上,使用tensorflow lite推理Yamnet实现语音分类


TensorFlow Lite C++ minimal example

This example shows how you can build a simple TensorFlow Lite application.

Step 1. Install CMake tool

It requires CMake 3.16 or higher. On Ubuntu, you can simply run the following
command.

sudo apt-get install cmake

Or you can follow
the official cmake installation guide

Step 2. Clone TensorFlow repository

git clone https://github.com/tensorflow/tensorflow.git tensorflowgit checkout origin/r2.10

Step 3. Create CMake build directory and run CMake tool

# move current directory to tensorflow_root/tensorflow/lite/examplesmkdir build_yamnetcd build_yamnetcmake -DCMAKE_TOOLCHAIN_FILE=/home/yons/data/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake -DTFLITE_ENABLE_XNNPACK=OFF ../tensorflow/lite/examples/yamnet# enter tensorflow root path, patch differentcd ../patch -p0 build_yamnet/flatbuffers/include/flatbuffers/util.h flatbuffers_util_h.diffpatch -p0 build_yamnet/flatbuffers/src/util.cpp flatbuffers_util_cpp.diffpatch -p0 build_yamnet/cpuinfo/CMakeLists.txt  cpuinfo.diff# re cmake configuration and buildcd build_yamnetcmake -DCMAKE_TOOLCHAIN_FILE=/home/yons/data/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake -DTFLITE_ENABLE_XNNPACK=OFF ../tensorflow/lite/examples/yamnetcmake --build ./ -j20

Step 4. copy binary file and related file to openHarmony device through device

  • make sure that connect to device.
hdc list targetshdc shell
# In the build_yamnet directoryhdc file send yamnet /datahdc file send yamnet_class_map.txt /datahdc file send miaow_16k.wav /datahdc file send golden_whistle.wav  /datahdc file send speech_whistling2.wav /data# copy libc++_shared.so from ohos-sdk cross compile toolchainhdc file send libc++_shared.so /data

Step 5. execute binary programation in OHOS

hdc shellcd dataexport LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH./yamnet wav_filepath# 从上面三个文件选一golden_whistle.wavmiaow_16k.wavspeech_whistling2.wav

Step 5. result

在OpenHarmony上,使用tensorflow lite推理Yamnet实现语音分类

more detail

医疗百科