2021年4月11日 星期日

Edge AI - Run tensorflow lite micro speech expample on NXP FRDM-K66F.

 Step to build tf-lite micro speach example for nxp_k66f

1. Clone tensorflow code

  $>git clone https://github.com/tensorflow/tensorflow.git

  

2. Install mbed-cli 

     $>sudo apt install python3 python3-pip git mercurial

     $>python3 -m pip install mbed-cli


3. Install ARM cross compile toolchain.(In this project I use GNU Arm Embedded Toolchain)

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads


4. Configure mbed cli

  $>mbed config -G  GCC_ARM_PATH=/YOUR_COMPILER_INSTALL_PATH/gcc-arm-none-eabi-9-2020-q2-update/bin


5. Generate mbed project for nxp_k66f

  $>cd tensorflow

  $>make -f tensorflow/lite/micro/tools/make/Makefile TARGET=mbed TAGS="nxp_k66f" generate_micro_speech_mbed_project


6.  Create mbed project 

  $>cd tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed

  $>mbed new  .


7. Configure porject usin C++ 11

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\"")'

 

8 Connect the USB cable to nxp_k66f



9. Compile and flash project, after flash complete reset the board.

mbed compile --target K66F --toolchain GCC_ARM --profile release --flash


10. Connect to nxp_k66f serial port with baudrate 14400.


11. Saying Yes and NO and will print repsonse word in serial port, since nxp_k66f has onboard microphone you can direct speak to it and see the result in terminal.


12. Test result 



I want using this sample code to build a IOT switch that can control with speach, So  in next article I will try to retrain model with 'ON' and 'OFF' key word and try to deploy to nxp_k66f


Ref

Mbed

https://os.mbed.com/docs/mbed-os/v6.9/build-tools/install-and-set-up.html

Tensorflow lite

https://github.com/tensorflow/tensorflow/tree/114b8ef31ac66155ec9b0590bc7115125f7fe61e/tensorflow/lite/micro/examples/micro_speech#deploy-to-nxp-frdm-k66f

NXP_K66F user guide

https://www.nxp.com/docs/en/user-guide/FRDMK66FUG.pdf


2021年3月3日 星期三

Docker useful command.

1. List running docker machine 

docker ps

2.  Attach to specific docker machine

docker exec -it docker_helloworld -u admin -p admin

3. Copy file from/to docker machine 

docker cp test.txt  docker_helloworld :test.txt  


Reference:

https://docs.docker.com/

2020年12月27日 星期日

Testing the tests: What should we do when the test case self is buggy?

Nowadays, software testing is widely using to ensure quality and prevent bug, like unit test/AB test…. etc, But increasingly test case will causing some unwanted problem like the test case is buggy so the testing will failed. And causing developer waste time chasing down problems that potentially didn’t really exist

Facebook provide a method to detect the test case bug:

1. Using ML technology  to predict what test case to run 

2. All end-to-end tests will have some degree of flakiness, So make a index about how reliable in these test case

3. Assert that a test is sufficiently reliable and provide a scale to illustrate which tests are less reliable than they should be. 

Software testing is a good tool to ensure the product quality, with more complicated code base and more complicated test case, it need carefully consider introduce method that test the test case to prevent waste time and increase testing quality.


2020年11月13日 星期五

Performance tuning- Leveraging modern CPU branch predict mechanism.

In modern CPU the branch predictor is complicated and the deeper pipeline causing the cost of miss branch prediction higher.

How can we leveraging the modern CPU branch predictor, In [1] example code, the branch miss rate can  be reduce by just sorting input data before exciting original algorithm. 



Conclusion 

1. Adding pattern to your algorithm(sorted data).

2. Using likely()/unlikely() marco to help branch prediction more accuracy.


Reference:

3. Linux likely() unlikely() MARCO.

2020年6月22日 星期一

Machine Learning Foundations NLP(2): Using the Sequencing APIs

Using the Sequencing APIs

Sequencing is use to format sentence array using token,
For example:

"I have a car"
"Car have a door"
 
Tokenize: [I:1] [have:2] [a:3] [car:4] [door:5]
 
then these two sentence can be represent to:
[1 2 3 4] 
[4 2 3 5]

Sequencing is useful to represent sentence data and take as input for a neuron network.

Code

Result:

Reference:






2020年6月17日 星期三

Machine Learning Foundations NLP(1): Tokenization for Natural Language Processing

Tokenization for Natural Language Processing


Tokenize is mean to break down a sentence to server work, for example:

I have a car. -> I / have / a/ car

Tensorflow provide a tokenize tool:Tokenizer, it can easily to use for tokenize input sentence.


Code:



Result:

{'have': 1, 'a': 2, 'i': 3, 'he': 4, 'apple': 5, 'bike': 6, 'pen': 7, 'car': 8}



Reference:

Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing



Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...