|
| 1 | +Face Detect Example |
| 2 | +============================================== |
| 3 | +Example shows very basic implementation of the classic object detection via sliding window paradigm. |
| 4 | +Small binary NN classifier for 36x36 grayscale images outputs positive decision for the images of face, and negative decision on other images. To process bigger image pyramid scaling and sliding is organized. |
| 5 | +Such approach still useful for deeply embedded applications as a compact and efficient way of triggering a bigger job. Activation function and the Layer 2 are quite unspecific kind of layers and was implemented in the research activity. |
| 6 | +MLI provides useful data manipulation and helper operations for implementation of such layers. |
| 7 | + |
| 8 | + |
| 9 | +Quick Start |
| 10 | +-------------- |
| 11 | + |
| 12 | +Example supports building with [MetaWare Development tools](https://www.synopsys.com/dw/ipdir.php?ds=sw_metaware) and [ARC GNU toolchain](https://www.synopsys.com/dw/ipdir.php?ds=sw_jtag_gnu) and running with MetaWare Debuger on [nSim simulator](https://www.synopsys.com/dw/ipdir.php?ds=sim_nSIM). |
| 13 | + |
| 14 | +### Build with MetaWare Development tools |
| 15 | + |
| 16 | + Build requirements: |
| 17 | + - MetaWare Development tools version 2018.12 or higher |
| 18 | + - gmake |
| 19 | + |
| 20 | +Here we will consider building for [/hw/em9d.tcf](/hw/em9d.tcf) template. This template is a default template for this example. Other templated can be also used. |
| 21 | + |
| 22 | +0. embARC MLI Library must be built for required hardware configuration first. See [embARC MLI Library building and quick start](/README.md#building-and-quick-start). |
| 23 | + |
| 24 | +1. Open command line and change working directory to `./examples/example_face_detect` |
| 25 | + |
| 26 | +2. Clean previous build artifacts (optional) |
| 27 | + |
| 28 | + gmake clean |
| 29 | + |
| 30 | +3. Build example |
| 31 | + |
| 32 | + gmake TCF_FILE=../../hw/em9d.tcf |
| 33 | + |
| 34 | +### Run example with MetaWare Debuger on nSim simulator. |
| 35 | + |
| 36 | +Example application requires path to a BMP file of 80x60 resolution and 24 bit depth (RGB) as an input parameter. |
| 37 | + |
| 38 | + gmake run TCF_FILE=../../hw/em9d.tcf RUN_ARGS=grace_hopper.bmp |
| 39 | + |
| 40 | +Application will create `result.bmp` file in the working directory. It's a 'grayed' version of input file with framed faces which was found in run. Expected console output is next: |
| 41 | + |
| 42 | + Detection step #0 |
| 43 | + Found a face at ([X:22, Y:17]; [X:58, Y:53]) |
| 44 | + Detection step #1 |
| 45 | + Detection step #2 |
| 46 | + Detection step #3 |
| 47 | + Detection step #4 |
| 48 | + Found a face at ([X:13, Y:11]; [X:55, Y:53]) |
| 49 | + Detection step #5 |
| 50 | + Detection step #6 |
| 51 | + Detection step #7 |
| 52 | + Detection step #8 |
| 53 | + |
| 54 | + |
| 55 | +### Build with ARC GNU toolchain |
| 56 | + |
| 57 | +Here we will consider building with ARC GNU toolchain. As a platform for the assembly, we use the [IoT Devkit](https://embarc.org/embarc_osp/doc/build/html/board/iotdk.html) from [the embARC Open Software Platform (OSP)](https://embarc.org/embarc_osp/doc/build/html/introduction/introduction.html#) |
| 58 | + |
| 59 | + Build requirements: |
| 60 | + - ARC GNU toolchain version 2018.09 or higher |
| 61 | + - embARC MLI Library prebuilt with MetaWare Development tools for IoT Devkit hardware configuration |
| 62 | + - gmake |
| 63 | + |
| 64 | +0. Prebuilt embARC MLI Library must be copyied into the `./examples/prebuilt` folder. |
| 65 | + |
| 66 | +1. Open command line and change working directory to `./examples/example_face_detect` |
| 67 | + |
| 68 | +2. Clean previous build artifacts (optional) |
| 69 | + |
| 70 | + gmake TOOLCHAIN=gnu clean |
| 71 | + |
| 72 | +3. Build example |
| 73 | + |
| 74 | + gmake TOOLCHAIN=gnu |
| 75 | + |
| 76 | + Notes: IoT Devkit hardware configuration is specifed in Makefile. Additionally used memory.x linkscript file for GNU linker. |
| 77 | + |
| 78 | +### Run example with MetaWare Debuger on nSim simulator. |
| 79 | + |
| 80 | + Run requirements: |
| 81 | + - MetaWare Development tools version 2018.12 or higher |
| 82 | + - arcem9d.tcf file with hardware configuration of IoT Devkit for setup nSim. |
| 83 | + |
| 84 | +0. Copy the [arcem9d.tcf](https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/blob/master/board/iotdk/configs/10/tcf/arcem9d.tcf) file into example folder. |
| 85 | + |
| 86 | +1. Run example |
| 87 | + |
| 88 | + gmake run TOOLCHAIN=gnu TCF_FILE=arcem9d.tcf |
| 89 | + |
| 90 | + Notes: Example built by ARC GNU tools is run using mdb_com_gnu script file. Modify this file to customize the example input argument (path to the image). |
| 91 | + |
| 92 | +### Run example without MetaWare Development tools |
| 93 | + |
| 94 | +See documentation on [IoT Devkit](https://embarc.org/embarc_osp/doc/build/html/board/iotdk.html) on how to run executable built with [ARC GNU](https://embarc.org/toolchain/index.html) and [ARC open source development tools](https://embarc.org/embarc_osp/doc/build/html/index.html) on IoT Devkit. |
| 95 | + |
| 96 | +Example Structure |
| 97 | +-------------------- |
| 98 | +Structure of example application may be divided logically on three parts: |
| 99 | + |
| 100 | +* **Application.** Implements resources allocation, reading and writing BMP files and invoking face search by pre-defined sliding scheme: |
| 101 | + * bmp_file_io.c |
| 102 | + * bmp_file_io.h |
| 103 | + * main.c |
| 104 | +* **Sliding window and rescaling code.** Various helper functions to scale input image and slide trigger classifiyer over it. |
| 105 | + * sliding_scan.c |
| 106 | + * sliding_scan.h |
| 107 | +* **Inference Module.** Uses embARC MLI Library to process input according to pre-defined graph. All model related constants are pre-defined and model coefficients is declared in the separate compile unit |
| 108 | + * face_trigger_constants.h |
| 109 | + * face_trigger_model.c |
| 110 | + * face_trigger_model.h |
| 111 | + |
| 112 | + |
| 113 | +Example structure contains test image of [Grace Hopper](https://en.wikipedia.org/wiki/Grace_Hopper). |
| 114 | + |
| 115 | +Example structure also contains auxiliary files for development tools: |
| 116 | + * arcem9d.lcf - linkscript file for MetaWare linker. |
| 117 | + * memory.x - linkscript file for GNU linker. |
| 118 | + * mdb_com_gnu - command script file for MetaWare Debugger. |
| 119 | + |
| 120 | + |
| 121 | +Data Memory Requirements |
| 122 | +---------------------------- |
| 123 | + |
| 124 | +Example uses statically allocated memory for model weights and intermediate results (activations) and structures. For images on the application level (outside of the model) |
| 125 | +example allocates memory dynamically befor processing. |
| 126 | + |
| 127 | +| Data | Size | |
| 128 | +| :-----------------------------------------------: | :-------------------: | |
| 129 | +| Weights (*.mli_model* section) | 3056 bytes | |
| 130 | +| Activations (*.Xdata* and *.Ydata* sections) | 5664 bytes | |
| 131 | +| Structures (*.mli_data* section) | 480 bytes | |
| 132 | +| Images (part of heap) | 14400 bytes | |
| 133 | + |
| 134 | +Application code size depends on target hardware configuration and compilation flags. MLI Library code is wrapped into mli_lib section. |
| 135 | + |
| 136 | +References |
| 137 | +---------------------------- |
| 138 | +> P. Viola and M. Jones. Rapid object detection using a boosted cascade of simple features. In CVPR, 2001 |
| 139 | +
|
| 140 | +> R. Vaillant, C. Monrocq, and Y. LeCun. Original approach for the localisation of objects in images. IEE Proc. on Vision, Image, and Signal Processing, 1994. |
0 commit comments