Fix TensorFlow Lite micro_speech readme and Colab

PiperOrigin-RevId: 261575841
This commit is contained in:
Daniel Situnayake 2019-08-04 10:37:55 -07:00 committed by TensorFlower Gardener
parent ab8b627e0b
commit 80fa48dac2
3 changed files with 71 additions and 69 deletions

View File

@ -18,7 +18,6 @@ detection model, takes up a total of 22KB.
* [Building for Ambiq Micro Apollo3Blue EVB using Make](#building-for-ambiq-micro-apollo3blue-evb-using-make)
* [Additional Apollo3 Instructions](#additional-apollo3-instructions)
* [Building for the Eta Compute ECM3531 EVB using Make](#Building-for-the-Eta-Compute-ECM3531-EVB-using-Make)
* [Building for NXP FRDM K66F EVB using mbed](#Building-for-NXP-FRDM-K66F-using-mbed)
- [Goals](#goals)
@ -380,67 +379,6 @@ To flash a part with JFlash Lite, do the following:
tensorflow/lite/experimental/micro/tools/make/targets/ecm3531 \
    ./flash_program executable_name to load into flash.
## Building for NXP FRDM K66F using mbed
1. Follow the instructions at
[Tensorflow Micro Speech](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/micro_speech#getting-started)
to download the Tensorflow source code and the support libraries
2. Follow instructions from [mbed website](https://os.mbed.com/docs/mbed-os/v5.13/tools/installation-and-setup.html) to setup and install mbed CLI
3. Compile tensorflow with the following command to generate mbed project:
```
make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=mbed TAGS="nxp_k66f" generate_micro_speech_mbed_project
```
4. Go to the location of the generated project. The generated project is usally
in tensorflow/lite/experimental/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed
5. Create a mbed project using the generated files: ```mbed new .```
6. Change the project setting to use C++ 11 rather than C++ 14 using
```
python -c 'import fileinput, glob;
for filename in glob.glob("mbed-os/tools/profiles/*.json"):
for line in fileinput.input(filename, inplace=True):
print line.replace("\"-std=gnu++14\"","\"-std=c++11\", \"-fpermissive\"")'
```
7. To compile project, use the following command:
```
mbed compile --target K66F --toolchain GCC_ARM --profile release
```
8. For some mbed compliers, you may get compile error in mbed_rtc_time.cpp.
Go to mbed-os/platform/mbed_rtc_time.h and comment line 32 and line 37
```
//#if !defined(__GNUC__) || defined(__CC_ARM) || defined(__clang__)
struct timeval {
time_t tv_sec;
int32_t tv_usec;
};
//#endif
```
9. Look at helpful resources from NXP website such as [NXP FRDM-K66F User guide](https://www.nxp.com/docs/en/user-guide/FRDMK66FUG.pdf) and [NXP FRDM-K66F Getting Started](https://www.nxp.com/document/guide/get-started-with-the-frdm-k66f:NGS-FRDM-K66F)
to understand information about the board.
10. Connect USB cable to micro USB port. When ethernet port is face towards you,
The micro USB port is left of the ethernet port.
11. To compile and flash in a single step, add --flash option:
```
mbed compile --target K66F --toolchain GCC_ARM --profile release --flash
```
12. Disconnect USB cable from the device to power down the device and connect
back the power cable to start running the model
13. Connect to serial port with baud rate of 9600 and correct serial device
to view the output from the MCU. In linux, you can run the following screen
command if the serial device is /dev/ttyACM0
```
sudo screen /dev/ttyACM0 9600
```
14. Saying "Yes" will print "Yes" and "No" will print "No" on the serial port
15. A loopback path from microphone to headset jack is enabled. Headset jack is
in black color. If there is no output on the serial port, you can connect
headphone to headphone port to check if audio loopback path is working
## Implement target optimized kernels
The reference kernels in tensorflow/lite/experimental/micro/kernels are

View File

@ -20,8 +20,9 @@ kilobytes of Flash.
- [Deploy to Arduino](#deploy-to-arduino)
- [Deploy to SparkFun Edge](#deploy-to-sparkfun-edge)
- [Deploy to STM32F746](#deploy-to-STM32F746)
- [Deploy to NXP FRDM K66F](#deploy-to-nxp-frdm-k66f)
- [Calculating the input to the neural network](#calculating-the-input-to-the-neural-network)
- [Create your own model](#create-your-own-model)
- [Train your own model](#train-your-own-model)
## Getting started
@ -31,6 +32,7 @@ This code has been tested on the following devices:
* [SparkFun Edge](https://sparkfun.com/products/15170)
* [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense-with-headers)
* [ST Microelectronics STM32F746G Discovery kit](https://os.mbed.com/platforms/ST-Discovery-F746NG/)
* [NXP FRDM K66F](https://www.nxp.com/design/development-boards/freedom-development-boards/mcu-boards/freedom-development-platform-for-kinetis-k66-k65-and-k26-mcus:FRDM-K66F)
This readme contains instructions for building the code on Linux and macOS, and
deploying the code to the above microcontroller platforms and macOS.
@ -112,7 +114,6 @@ to [Arduino](https://www.arduino.cc/) devices.
The sample has been tested with the following devices:
- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense-with-headers)
(this ).
The Arduino Nano 33 BLE Sense is currently the only Arduino with a built-in
microphone. If you're using a different Arduino board and attaching your own
@ -136,7 +137,7 @@ modifications to the code), run this command to generate a zip file containing
the required source files:
```
make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=arduino TAGS="" generate_micro_speech_arduino_library_zip
make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=arduino TAGS="portable_optimized" generate_micro_speech_arduino_library_zip
```
A zip file will be created at the following location:
@ -438,6 +439,69 @@ see will be at least 200.
To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately
followed by the `K` key, then hit the `Y` key.
## Deploy to NXP FRDM K66F
The following instructions will help you build and deploy the sample to the
[NXP FRDM K66F](https://www.nxp.com/design/development-boards/freedom-development-boards/mcu-boards/freedom-development-platform-for-kinetis-k66-k65-and-k26-mcus:FRDM-K66F)
using [ARM Mbed](https://github.com/ARMmbed/mbed-cli).
1. Download [the TensorFlow source code](https://github.com/tensorflow/tensorflow).
2. Follow instructions from [mbed website](https://os.mbed.com/docs/mbed-os/v5.13/tools/installation-and-setup.html) to setup and install mbed CLI.
3. Compile TensorFlow with the following command to generate mbed project:
```
make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=mbed TAGS="nxp_k66f" generate_micro_speech_mbed_project
```
4. Go to the location of the generated project. The generated project is usally
in `tensorflow/lite/experimental/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed`
5. Create a mbed project using the generated files: `mbed new .`
6. Change the project setting to use C++ 11 rather than C++ 14 using:
```
python -c 'import fileinput, glob;
for filename in glob.glob("mbed-os/tools/profiles/*.json"):
for line in fileinput.input(filename, inplace=True):
print line.replace("\"-std=gnu++14\"","\"-std=c++11\", \"-fpermissive\"")'
```
7. To compile project, use the following command:
```
mbed compile --target K66F --toolchain GCC_ARM --profile release
```
8. For some mbed compliers, you may get compile error in mbed_rtc_time.cpp.
Go to `mbed-os/platform/mbed_rtc_time.h` and comment line 32 and line 37:
```
//#if !defined(__GNUC__) || defined(__CC_ARM) || defined(__clang__)
struct timeval {
time_t tv_sec;
int32_t tv_usec;
};
//#endif
```
9. Look at helpful resources from NXP website such as [NXP FRDM-K66F User guide](https://www.nxp.com/docs/en/user-guide/FRDMK66FUG.pdf) and [NXP FRDM-K66F Getting Started](https://www.nxp.com/document/guide/get-started-with-the-frdm-k66f:NGS-FRDM-K66F)
to understand information about the board.
10. Connect USB cable to micro USB port. When ethernet port is face towards you,
The micro USB port is left of the ethernet port.
11. To compile and flash in a single step, add the `--flash` option:
```
mbed compile --target K66F --toolchain GCC_ARM --profile release --flash
```
12. Disconnect USB cable from the device to power down the device and connect
back the power cable to start running the model.
13. Connect to serial port with baud rate of 9600 and correct serial device
to view the output from the MCU. In linux, you can run the following screen
command if the serial device is `/dev/ttyACM0`:
```
sudo screen /dev/ttyACM0 9600
```
14. Saying "Yes" will print "Yes" and "No" will print "No" on the serial port.
15. A loopback path from microphone to headset jack is enabled. Headset jack is
in black color. If there is no output on the serial port, you can connect
headphone to headphone port to check if audio loopback path is working.
## Calculating the input to the neural network
The TensorFlow Lite model doesn't take in raw audio sample data. Instead it

View File

@ -36,12 +36,12 @@
"\n",
"The model is designed to be used with [Google Colaboratory](https://colab.research.google.com).\n",
"\n",
"<table class=\\\"tfo-notebook-buttons\\\" align=\\\"left\\\">\n",
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\\\"_blank\\\" href=\\\"https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/train_speech_model.ipynb\\\"><img src=\\\"https://www.tensorflow.org/images/colab_logo_32px.png\\\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/train_speech_model.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\\\"_blank\\\" href=\\\"https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/train_speech_model.ipynb\\\"><img src=\\\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\\\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/train_speech_model.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>\n",
"\n",
@ -116,7 +116,7 @@
"source": [
"# Install the nightly build\n",
"!pip install -q tf-nightly-gpu==1.15.0.dev20190729\n",
"!git clone https://github.com/dansitu/tensorflow"
"!git clone https://github.com/tensorflow/tensorflow"
],
"execution_count": 0,
"outputs": []