Skip to content

Commit 94b165d

Browse files
authored
Merge pull request #121 from foss-for-synopsys-dwc-arc-processors/face_detect_exmpl
Face detect exmpl
2 parents c07931b + 2321115 commit 94b165d

File tree

15 files changed

+1905
-3
lines changed

15 files changed

+1905
-3
lines changed

build/rules.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ else
142142
AR = arc-elf32-ar
143143
AS = arc-elf32-as
144144
CFLAGS += $(addprefix -I, $(HEADER_DIRS))
145-
CFLAGS += -D_Interrupt=__attribute__((interrupt("ilink")))
145+
CFLAGS += -D_Interrupt=__attribute__\(\(interrupt\("ilink"\)\)\)
146146
CFLAGS += -D_lr=__builtin_arc_lr
147147
CFLAGS += -D_sr=__builtin_arc_sr
148148
CFLAGS += -D_seti=__builtin_arc_seti
@@ -152,8 +152,8 @@ else
152152
CFLAGS += -D__Xdmac
153153

154154
CFLAGS += -D_Uncached=volatile
155-
CFLAGS += -D_Usually(x)=__builtin_expect((x)!=0,1)
156-
CFLAGS += -D_Rarely(x)=__builtin_expect((x)!=0,0)
155+
CFLAGS += -D_Usually\(x\)=__builtin_expect\(\(x\)!=0,1\)
156+
CFLAGS += -D_Rarely\(x\)=__builtin_expect\(\(x\)!=0,0\)
157157
CFLAGS += -DIRQ_BUILD=0x00f3
158158
CFLAGS += -DRF_BUILD=0x006e
159159
CFLAGS += -DRF_BUILD=0x006e
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#
2+
# Copyright 2019, Synopsys, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-3-Clause license found in
6+
# the LICENSE file in the root directory of this source tree.
7+
#
8+
9+
# default toolchain
10+
TOOLCHAIN ?= mwdt
11+
12+
# default hardware config file
13+
TCF_FILE ?= ../../hw/em9d.tcf
14+
15+
# Directories and files
16+
EMBARC_MLI_DIR ?= ../..
17+
SRC_DIRS = . \
18+
$(EMBARC_MLI_DIR)/examples/auxiliary
19+
20+
INC_DIRS = . \
21+
$(EMBARC_MLI_DIR)/include \
22+
$(EMBARC_MLI_DIR)/examples/auxiliary
23+
24+
EXT_LIBS_DIR ?= $(EMBARC_MLI_DIR)/bin
25+
EXT_LIBS ?= $(EXT_LIBS_DIR)/libmli.a
26+
OUT_DIR ?= ./bin
27+
BUILD_DIR ?= ./obj
28+
OUT_NAME ?= example_face_trigger
29+
ifeq ($(TOOLCHAIN),mwdt)
30+
# MWDT specific options
31+
CFLAGS = -Hnocopyr -Hpurge -Hheap=20K -Hstack=4K -Hfxapi -e_start -Bgrouplib -Hldopt=-q -Hsdata0 -Xdsp_ctrl=postshift,guard,convergent -Hdense_prologue
32+
else
33+
PREBUILT_LIB ?= $(EMBARC_MLI_DIR)/examples/prebuilt/libmli.a
34+
35+
# GNU toolchain specific options - correct it according to your target platform settings (see build_configuration.txt for input)
36+
#Iot DevKit config
37+
CFLAGS = -mcpu=em4_fpuda -mlittle-endian -mcode-density -mdiv-rem -mswap -mnorm -mmpy-option=6 -mbarrel-shifter -mxy
38+
39+
# The embARC MLI Library specific options it according to your target platform settings
40+
#(EM5D or EM7D platform)
41+
#CFLAGS += -DV2DSP
42+
#(EM9D or EM11D platform)
43+
CFLAGS += -DV2DSP_XY
44+
#(HS45D or HS47D platform)
45+
#CFLAGS += -DV2DSP_WIDE
46+
47+
# GNU toolchain linker specific options
48+
LDFLAGS = --defsym=__DEFAULT_HEAP_SIZE=20k
49+
LDFLAGS += --defsym=__DEFAULT_STACK_SIZE=4k
50+
LDFLAGS += -Map $(OUT_DIR)/$(OUT_NAME).map
51+
52+
#specific options for run the example with the MetaWare Debuger on the nSim simulator.
53+
DBG_OPTS = -cmd="read mdb_com_gnu"
54+
endif
55+
56+
.PHONY: clean all lib cleanall app
57+
.DEFAULT_GOAL := all
58+
59+
all: lib app
60+
61+
$(EXT_LIBS): $(EXT_LIBS_DIR)
62+
@echo Copy prebuilt library $(PREBUILT_LIB) to $@
63+
@$(CP) $(call fix_platform_path,$(PREBUILT_LIB)) $(call fix_platform_path,$@)
64+
65+
$(EXT_LIBS_DIR):
66+
$(MKDIR) $(call fix_platform_path, $@ )
67+
68+
include $(EMBARC_MLI_DIR)/build/rules.mk
69+
70+
ifeq ($(TOOLCHAIN),mwdt)
71+
lib:
72+
@ $(MAKE) generic_lib -C $(EMBARC_MLI_DIR)$(PS)lib$(PS)make$(PS) TCF_FILE="$(TCF_FILE)"
73+
else
74+
lib: $(EXT_LIBS)
75+
endif
76+
77+
app: generic_app
78+
79+
run: generic_run
80+
81+
clean:
82+
@echo Cleaning application $(OUT_NAME)...
83+
-@$(RM) $(call fix_platform_path,$(OBJS))
84+
85+
cleanall: clean
86+
@echo Cleaning all files ..
87+
-@$(RM) $(call fix_platform_path,$(OUT_DIR)/$(OUT_NAME).elf)
88+
-@$(RM) $(call fix_platform_path,$(OUT_DIR)/$(OUT_NAME).map)
89+
+$(MAKE) clean -C $(EMBARC_MLI_DIR)$(PS)lib$(PS)make$(PS)
90+
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
MEMORY {
2+
# SYSTEM0 : ORIGIN = 0x00000000, LENGTH = 0x20000000
3+
ICCM0 : ORIGIN = 0x20000000, LENGTH = 0x00040000
4+
# CCMWRAP0: ORIGIN = 0x20040000, LENGTH = 0x0ffc0000
5+
# SYSTEM1 : ORIGIN = 0x30000000, LENGTH = 0x50000000
6+
DCCM : ORIGIN = 0x80000000, LENGTH = 0x00020000
7+
# CCMWRAP1: ORIGIN = 0x80020000, LENGTH = 0x0ffe0000
8+
# SYSTEM2 : ORIGIN = 0x90000000, LENGTH = 0x30000000
9+
XCCM : ORIGIN = 0xc0000000, LENGTH = 0x00008000
10+
# CCMWRAP2: ORIGIN = 0xc0008000, LENGTH = 0x0fff8000
11+
# SYSTEM3 : ORIGIN = 0xd0000000, LENGTH = 0x10000000
12+
YCCM : ORIGIN = 0xe0000000, LENGTH = 0x00008000
13+
# CCMWRAP3: ORIGIN = 0xe0008000, LENGTH = 0x0fff8000
14+
# SYSTEM4 : ORIGIN = 0xf0000000, LENGTH = 0x10000000
15+
}
16+
SECTIONS {
17+
GROUP: {
18+
.vectors (TEXT) SIZE(DEFINED _IVTSIZE?_IVTSIZE:684): {} = FILL(0xa5a5a5a5,4)
19+
.text? : { *('.text$crt*') }
20+
* (TEXT): {}
21+
* (LIT): {}
22+
} > ICCM0
23+
GROUP: {
24+
/* _SDA_BASE_ computed implicitly */
25+
.sdata?: {}
26+
.sbss?: {}
27+
* (DATA): {}
28+
* (BSS): {}
29+
.stack ALIGN(4) SIZE(DEFINED _STACKSIZE?_STACKSIZE:32768): {}
30+
.heap? ALIGN(4) SIZE(DEFINED _HEAPSIZE?_HEAPSIZE:0): {}
31+
} > DCCM
32+
GROUP: {
33+
.Xdata? : {}
34+
} > XCCM
35+
GROUP: {
36+
.Ydata? : {}
37+
} > YCCM
38+
39+
}

0 commit comments

Comments
 (0)