Merge pull request #40299 from HimaxWiseEyePlus:master

PiperOrigin-RevId: 316991274
Change-Id: Idd33c89606556b4d25fffbec698ff40016ed64e3
This commit is contained in:
TensorFlower Gardener 2020-06-17 16:45:55 -07:00
commit ec4cbff879
7 changed files with 402 additions and 0 deletions

View File

@ -17,6 +17,7 @@ of the device.
- [Deploy to ARC EM SDP](#deploy-to-arc-em-sdp)
- [Deploy to Arduino](#deploy-to-arduino)
- [Deploy to ESP32](#deploy-to-esp32)
- [Deploy to Himax WE1 EVB](#deploy-to-himax-we1-evb)
- [Deploy to SparkFun Edge](#deploy-to-sparkfun-edge)
- [Deploy to STM32F746](#deploy-to-STM32F746)
- [Run the tests on a development machine](#run-the-tests-on-a-development-machine)
@ -191,6 +192,105 @@ The previous two commands can be combined:
idf.py --port /dev/ttyUSB0 flash monitor
```
## Deploy to Himax WE1 EVB
The following instructions will help you build and deploy this example to
[HIMAX WE1 EVB](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_board_brief)
board. To undstand more about using this board, please check
[HIMAX WE1 EVB user guide](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide).
### Initial Setup
To use the HIMAX WE1 EVB, please make sure following software are installed:
#### MetaWare Development Toolkit
See
[Install the Synopsys DesignWare ARC MetaWare Development Toolkit](/tensorflow/lite/micro/tools/make/targets/arc/README.md#install-the-synopsys-designware-arc-metaware-development-toolkit)
section for instructions on toolchain installation.
#### Make Tool version
A `'make'` tool is required for deploying Tensorflow Lite Micro applications on
HIMAX WE1 EVB, See
[Check make tool version](/tensorflow/lite/micro/tools/make/targets/arc/README.md#make-tool)
section for proper environment.
#### Serial Terminal Emulation Application
There are 2 main purposes for HIMAX WE1 EVB Debug UART port
- print application output
- burn application to flash by using xmodem send application binary
You can use any terminal emulation program (like [PuTTY](https://www.putty.org/)
or [minicom](https://linux.die.net/man/1/minicom)).
### Generate Example Project
The example project for HIMAX WE1 EVB platform can be generated with the
following command:
Download related third party data
```
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=himax_we1_evb third_party_downloads
```
Generate hello world project
```
make -f tensorflow/lite/micro/tools/make/Makefile generate_hello_world_make_project TARGET=himax_we1_evb TAGS=no_arc_mli
```
### Build and Burn Example
Following the Steps to run hello world example at HIMAX WE1 EVB platform.
1. Go to the generated example project directory.
```
cd tensorflow/lite/micro/tools/make/gen/himax_we1_evb_arc/prj/hello_world/make
```
2. Build the example using
```
make app
```
3. After example build finish, copy ELF file and map file to image generate
tool directory. \
image generate tool directory located at
`'tensorflow/lite/micro/tools/make/downloads/himax_we1_sdk/image_gen_linux_v3/'`
```
cp hello_world.elf himax_we1_evb.map ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/
```
4. Go to flash image generate tool directory.
```
cd ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/
```
5. run image generate tool, generate flash image file.
* Before running image generate tool, by typing `sudo chmod +x image_gen`
and `sudo chmod +x sign_tool` to make sure it is executable.
```
image_gen -e hello_world.elf -m himax_we1_evb.map -o out.img
```
6. Download flash image file to HIMAX WE1 EVB by UART:
* more detail about download image through UART can be found at
[HIMAX WE1 EVB update Flash image](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide#flash-image-update)
After these steps, press reset button on the HIMAX WE1 EVB, you will see
application output in the serial terminal.
## Deploy to SparkFun Edge
The following instructions will help you build and deploy this sample on the

View File

@ -10,6 +10,7 @@ This uses the experimental int8 quantized version of the person detection model.
- [Getting started](#getting-started)
- [Running on ARC EM SDP](#running-on-arc-em-sdp)
- [Running on Arduino](#running-on-arduino)
- [Running on HIMAX WE1 EVB](#running-on-himax-we1-evb)
- [Running on SparkFun Edge](#running-on-sparkfun-edge)
- [Run the tests on a development machine](#run-the-tests-on-a-development-machine)
- [Debugging image capture](#debugging-image-capture)
@ -260,6 +261,105 @@ From the log, we can see that it took around 170 ms to capture and read the
image data from the camera module, 180 ms to decode the JPEG and convert it to
greyscale, and 18.6 seconds to run inference.
## Running on HIMAX WE1 EVB
The following instructions will help you build and deploy this example to
[HIMAX WE1 EVB](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_board_brief)
board. To undstand more about using this board, please check
[HIMAX WE1 EVB user guide](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide).
### Initial Setup
To use the HIMAX WE1 EVB, please make sure following software are installed:
#### MetaWare Development Toolkit
See
[Install the Synopsys DesignWare ARC MetaWare Development Toolkit](/tensorflow/lite/micro/tools/make/targets/arc/README.md#install-the-synopsys-designware-arc-metaware-development-toolkit)
section for instructions on toolchain installation.
#### Make Tool version
A `'make'` tool is required for deploying Tensorflow Lite Micro applications on
HIMAX WE1 EVB, See
[Check make tool version](/tensorflow/lite/micro/tools/make/targets/arc/README.md#make-tool)
section for proper environment.
#### Serial Terminal Emulation Application
There are 2 main purposes for HIMAX WE1 EVB Debug UART port
- print application output
- burn application to flash by using xmodem send application binary
You can use any terminal emulation program (like [PuTTY](https://www.putty.org/)
or [minicom](https://linux.die.net/man/1/minicom)).
### Generate Example Project
The example project for HIMAX WE1 EVB platform can be generated with the
following command:
Download related third party data
```
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=himax_we1_evb third_party_downloads
```
Generate person detection project
```
make -f tensorflow/lite/micro/tools/make/Makefile generate_person_detection_int8_make_project TARGET=himax_we1_evb
```
### Build and Burn Example
Following the Steps to run person detection example at HIMAX WE1 EVB platform.
1. Go to the generated example project directory.
```
cd tensorflow/lite/micro/tools/make/gen/himax_we1_evb_arc/prj/person_detection_int8/make
```
2. Build the example using
```
make app
```
3. After example build finish, copy ELF file and map file to image generate
tool directory. \
image generate tool directory located at
`'tensorflow/lite/micro/tools/make/downloads/himax_we1_sdk/image_gen_linux_v3/'`
```
cp person_detection_int8.elf himax_we1_evb.map ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/
```
4. Go to flash image generate tool directory.
```
cd ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/
```
5. run image generate tool, generate flash image file.
* Before running image generate tool, by typing `sudo chmod +x image_gen`
and `sudo chmod +x sign_tool` to make sure it is executable.
```
image_gen -e person_detection_int8.elf -m himax_we1_evb.map -o out.img
```
6. Download flash image file to HIMAX WE1 EVB by UART:
* more detail about download image through UART can be found at
[HIMAX WE1 EVB update Flash image](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide#flash-image-update)
After these steps, press reset button on the HIMAX WE1 EVB, you will see
application output in the serial terminal.
## Running on SparkFun Edge
The following instructions will help you build and deploy this sample on the

View File

@ -0,0 +1,33 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/lite/micro/examples/person_detection_experimental/detection_responder.h"
#include "hx_drv_tflm.h"
// This dummy implementation writes person and no person scores to the error
// console. Real applications will want to take some custom action instead, and
// should implement their own versions of this function.
void RespondToDetection(tflite::ErrorReporter* error_reporter,
int8_t person_score, int8_t no_person_score) {
if (person_score > no_person_score) {
hx_drv_led_on(HX_DRV_LED_GREEN);
} else {
hx_drv_led_off(HX_DRV_LED_GREEN);
}
TF_LITE_REPORT_ERROR(error_reporter, "person score:%d no person score %d",
person_score, no_person_score);
}

View File

@ -0,0 +1,41 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/lite/micro/examples/person_detection_experimental/image_provider.h"
#include "hx_drv_tflm.h"
#include "tensorflow/lite/micro/examples/person_detection_experimental/model_settings.h"
hx_drv_sensor_image_config_t g_pimg_config;
TfLiteStatus GetImage(tflite::ErrorReporter* error_reporter, int image_width,
int image_height, int channels, int8_t* image_data) {
static bool is_initialized = false;
if (!is_initialized) {
if (hx_drv_sensor_initial(&g_pimg_config) != HX_DRV_LIB_PASS) {
return kTfLiteError;
}
is_initialized = true;
}
hx_drv_sensor_capture(&g_pimg_config);
hx_drv_image_rescale((uint8_t*)g_pimg_config.raw_address,
g_pimg_config.img_width, g_pimg_config.img_height,
image_data, image_width, image_height);
return kTfLiteOk;
}

View File

@ -0,0 +1,32 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Implementation for the DebugLog() function that prints to the UART on the
// SparkFun Edge microcontroller. The same should work for other targets using
// the Ambiq Apollo 3.
#include "tensorflow/lite/micro/debug_log.h"
#include "hx_drv_tflm.h"
extern "C" void DebugLog(const char* s) {
static bool is_initialized = false;
if (!is_initialized) {
hx_drv_uart_initial();
is_initialized = true;
}
hx_drv_uart_print("%s", s);
}

View File

@ -0,0 +1,91 @@
# Settings for himax WE_1 evb.
ifeq ($(TARGET), himax_we1_evb)
CC_TOOL = ccac
AR_TOOL = arac
CXX_TOOL = ccac
LD_TOOL := ccac
TARGET_ARCH := arc
#ARC_TOOLCHAIN := mwdt
BUILD_ARC_MLI := false
ARC_MLI_PRE_COMPILED_TARGET := himax_arcem9d_r16
include $(MAKEFILE_DIR)/targets/arc/arc_common.inc
#download SDK & MLI
HIMAX_WE1_SDK_NAME := himax_we1_sdk
$(eval $(call add_third_party_download,$(HIMAX_WE1_SDK_URL),$(HIMAX_WE1_SDK_MD5),$(HIMAX_WE1_SDK_NAME),))
#export path of toolchain
#export PATH := $(MAKEFILE_DIR)/downloads/$(HIMAX_WE1_SDK_NAME)/image_gen_linux_v3/:$(PATH)
TCF_FILE := $(PWD)/$(MAKEFILE_DIR)/downloads/$(HIMAX_WE1_SDK_NAME)/arcem9d_wei_r16.tcf
LCF_FILE := $(PWD)/$(MAKEFILE_DIR)/downloads/$(HIMAX_WE1_SDK_NAME)/memory.lcf
ARCLIB_FILE := $(PWD)/$(MAKEFILE_DIR)/downloads/$(HIMAX_WE1_SDK_NAME)/libembarc.a
LIB_HEADER_FILE := $(PWD)/$(MAKEFILE_DIR)/downloads/$(HIMAX_WE1_SDK_NAME)/hx_drv_tflm.h
DEFAULT_HEAPSZ := 8192
DEFAULT_STACKSZ := 8192
TCF_FILE_NAME = $(notdir $(TCF_FILE))
ARC_TARGET_FILES_DIRS = $(dir $(TCF_FILE_NAME))
MAKE_PROJECT_FILES += $(TCF_FILE_NAME)
LCF_FILE_NAME = $(notdir $(LCF_FILE))
ARC_TARGET_FILES_DIRS += $(dir $(LCF_FILE))
MAKE_PROJECT_FILES += $(LCF_FILE_NAME)
ARCLIB_FILE_NAME = $(notdir $(ARCLIB_FILE))
ARC_TARGET_FILES_DIRS += $(dir $(ARCLIB_FILE))
MAKE_PROJECT_FILES += $(ARCLIB_FILE_NAME)
LIB_HEADER_FILE_NAME = $(notdir $(LIB_HEADER_FILE))
ARC_TARGET_FILES_DIRS += $(dir $(LIB_HEADER_FILE))
MAKE_PROJECT_FILES += $(LIB_HEADER_FILE_NAME)
# Need a pointer to the TCF and lcf file
PLATFORM_FLAGS = \
-DNDEBUG \
-g \
-DCPU_ARC \
-Hnosdata \
-DTF_LITE_STATIC_MEMORY \
-tcf=$(TCF_FILE_NAME) \
-Hnocopyr \
-Hpurge \
-Hcl \
-fslp-vectorize-aggressive \
-ffunction-sections \
-fdata-sections \
-tcf_core_config \
CXXFLAGS += -fno-rtti -DSCRATCH_MEM_Z_SIZE=0x10000 $(PLATFORM_FLAGS)
CCFLAGS += $(PLATFORM_FLAGS)
INCLUDES+= \
-I $(MAKEFILE_DIR)/downloads/$(WEI_SDK_NAME) \
-I $(MAKEFILE_DIR)/downloads/kissfft
GENERATED_PROJECT_INCLUDES += \
-I. \
-I./third_party/kissfft
LDFLAGS += \
-Hheap=8192 \
-tcf=$(TCF_FILE_NAME) \
-Hnocopyr \
-m \
-Hldopt=-Coutput=$(TARGET).map \
$(LCF_FILE_NAME) \
-Hldopt=-Bgrouplib $(ARCLIB_FILE_NAME)
CXXFLAGS := $(filter-out -std=c++11,$(CXXFLAGS))
CCFLAGS := $(filter-out -std=c11,$(CCFLAGS))
MICROLITE_LIBS := $(filter-out -lm,$(MICROLITE_LIBS))
endif

View File

@ -85,3 +85,8 @@ XTENSA_HIFI4_MD5 :="f234764928f9a42901df33a27e118c8b"
ETHOSU_URL := "https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/snapshot/ethos-u-core-driver-bcb5aaa99756f1b5c1295b079ebdd60996bc75a5.tar.gz"
ETHOSU_MD5 := "d2073c8d88fc167fd5c46b5dcda58ea1"
HIMAX_WE1_SDK_URL ="https://www.himax.com.tw/we-i/himax_we1_sdk_v02.zip"
HIMAX_WE1_SDK_MD5 ="9a4b2f29b16052764e437b64bdcba816"