Skip to content

Commit ce9ea3f

Browse files
authored
Implement Sparse Face Detection Model (#212)
* Port Sparse Model * Incorporate Harsha's Comments * Add make clean argument
1 parent 92f9654 commit ce9ea3f

30 files changed

+747
-31
lines changed

.gitattributes

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Set the default behavior, in case people don't have core.autocrlf set.
22
* text=auto
3-
43
# Explicitly declare text files you want to always be normalized and converted
54
# to native line endings on checkout.
65
*.c text
@@ -11,17 +10,14 @@
1110
*.hh text
1211
*.mk text
1312
*.md text
14-
1513
# Declare files that will always have CRLF line endings on checkout.
1614
*.sln text eol=crlf
1715
*.vcxproj text eol=crlf
18-
1916
# Denote all files that are truly binary and should not be modified.
2017
*.png binary
2118
*.jpg binary
2219
*.pdf binary
2320
*.ipynb binary
24-
2521
c_reference/models/q_scut_head_b_face3_model/mbconv1.h filter=lfs diff=lfs merge=lfs -text
2622
c_reference/models/q_scut_head_b_face3_model/mbconv3.h filter=lfs diff=lfs merge=lfs -text
2723
c_reference/models/q_scut_head_b_face3_model/mbconv4.h filter=lfs diff=lfs merge=lfs -text
@@ -53,3 +49,14 @@ c_reference/models/q_scut_head_b_face2_model/mbconv13.h filter=lfs diff=lfs merg
5349
c_reference/models/q_scut_head_b_face2_model/mbconv1.h filter=lfs diff=lfs merge=lfs -text
5450
c_reference/models/q_scut_head_b_face2_model/detection2.h filter=lfs diff=lfs merge=lfs -text
5551
c_reference/models/q_scut_head_b_face2_model/mbconv12.h filter=lfs diff=lfs merge=lfs -text
52+
c_reference/models/q_scut_head_b_face4_model/detection1.h filter=lfs diff=lfs merge=lfs -text
53+
c_reference/models/q_scut_head_b_face4_model/detection3.h filter=lfs diff=lfs merge=lfs -text
54+
c_reference/models/q_scut_head_b_face4_model/detection4.h filter=lfs diff=lfs merge=lfs -text
55+
c_reference/models/q_scut_head_b_face4_model/mbconv3.h filter=lfs diff=lfs merge=lfs -text
56+
c_reference/models/q_scut_head_b_face4_model/rnn1.h filter=lfs diff=lfs merge=lfs -text
57+
c_reference/models/q_scut_head_b_face4_model/conv2D.h filter=lfs diff=lfs merge=lfs -text
58+
c_reference/models/q_scut_head_b_face4_model/mbconv1.h filter=lfs diff=lfs merge=lfs -text
59+
c_reference/models/q_scut_head_b_face4_model/mbconv2.h filter=lfs diff=lfs merge=lfs -text
60+
c_reference/models/q_scut_head_b_face4_model/mbconv4.h filter=lfs diff=lfs merge=lfs -text
61+
c_reference/models/q_scut_head_b_face4_model/rnn2.h filter=lfs diff=lfs merge=lfs -text
62+
c_reference/models/q_scut_head_b_face4_model/detection2.h filter=lfs diff=lfs merge=lfs -text

c_reference/include/quantized_fastgrnn.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@ int q15_fastgrnn_lr(Q15_T* const hiddenState, ITER_T hiddenDims,
159159

160160
/**
161161
* @brief Model paramters for FastGRNN
162+
* Note: Wids, Wvals, Uids, Uvals can be set to NULL for non-sparse mode operation
162163
* @var mean pointer to mean of input vector for normalization, size inputDims
163164
* @var stdDev pointer to standard dev of input for normalization, size inputDims * steps
164165
* @var W pointer to W matrix
166+
* @var Wids pointer to the matrix storing row-indices of non-zero elements of W
167+
* @var Wvals pointer to the matrix storing the non-zero elements of W
165168
* @var U pointer U matrix
169+
* @var Uids pointer to the matrix storing row-indices of non-zero elements of U
170+
* @var Uvals pointer to the matrix storing the non-zero elements of U
166171
* @var Bg pointer to bias for Sigmoid
167172
* @var Bh pointer to bias for TanH
168173
* @var sigmoid_zeta first weight parameter for update from input from next step
@@ -172,7 +177,11 @@ typedef struct Q15_FastGRNN_Params {
172177
const Q15_T* mean;
173178
const Q15_T* stdDev;
174179
const Q15_T* W;
180+
const ITER_T* Wids;
181+
const Q15_T* Wvals;
175182
const Q15_T* U;
183+
const ITER_T* Uids;
184+
const Q15_T* Uvals;
176185
const Q15_T* Bg;
177186
const Q15_T* Bh;
178187
Q15_T sigmoid_zeta;
@@ -183,7 +192,11 @@ typedef struct Q7xQ15_FastGRNN_Params {
183192
const Q7_T* mean;
184193
const Q7_T* stdDev;
185194
const Q15_T* W;
195+
const ITER_T* Wids;
196+
const Q15_T* Wvals;
186197
const Q15_T* U;
198+
const ITER_T* Uids;
199+
const Q15_T* Uvals;
187200
const Q15_T* Bg;
188201
const Q15_T* Bh;
189202
Q15_T sigmoid_zeta;

c_reference/include/quantized_utils.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,45 @@ void q15xq7_q15_m_mulvec(const Q15_T* mat, const Q7_T* const vec, ITER_T nrows,
304304
void q15_m_mulvec(const Q15_T* mat, const Q15_T* const vec, ITER_T nrows,
305305
ITER_T ncols, Q15_T* ret, SCALE_T scmat, SCALE_T scvec,
306306
SCALE_T H1, SCALE_T H2);
307+
/**
308+
* @brief Performs sparse matrix multiplication of a matrix and a vector.
309+
* row_indices and mat_values combined are a sparse representation; dim(vec) = [ncols].
310+
* mat_values[i] is the i^th non-zero value of the input matrix, and row_indices[i] encodes the (1-indexed) row location of mat_values[i].
311+
* If number of zeroes before row_indices[i] is l, then l is the column location of the (i-l)th matrix value.
312+
* @param[in] row_indices pointer to input matrix which stores the row indices of non-zero values of matrix A
313+
* @param[in] mat_values pointer to input matrix which stores the non-zero values of matrix A
314+
* @param[in] vec pointer to the input vector
315+
* @param[in] nrows number of rows of the input matrix
316+
* @param[in] ncols number of columns of the input matrix
317+
* @param[out] ret pointer to the output vector
318+
* @param[in] scmat scale factor of the input matrix
319+
* @param[in] scvec scale factor of the input vector
320+
* @param[in] H1 depth parameter for division-by-two used in TreeSum
321+
* @param[in] H2 depth parameter for direct sum used in TreeSum
322+
* @return none
323+
* @example mat = { {23, 32, 0},
324+
* {0, 0, 1},
325+
* {48, 0, 0}}
326+
* row_indices = {1, 3, 0, 1, 0, 2, 0}
327+
* mat_values = {23, 48, 32, 1}
328+
* vec = {1, 2, 3}
329+
* nrows = 3
330+
* ncols = 3
331+
* scmat = 1
332+
* scvec = 1
333+
* H1 = 1
334+
* H2 = 0
335+
* ret = {87, 3, 48}
336+
*/
337+
void q15xq7_q15_m_sparse_mulvec(const ITER_T* row_indices,
338+
const Q15_T* mat_values, const Q7_T* vec,
339+
ITER_T nrows, ITER_T ncols, Q15_T* ret,
340+
SCALE_T scmat, SCALE_T scvec, SCALE_T H1,
341+
SCALE_T H2);
342+
void q15_m_sparse_mulvec(const ITER_T* row_indices, const Q15_T* mat_values,
343+
const Q15_T* vec, ITER_T nrows, ITER_T ncols,
344+
Q15_T* ret, SCALE_T scmat, SCALE_T scvec, SCALE_T H1,
345+
SCALE_T H2);
307346

308347
/**
309348
* @brief Performs the element-wise addition of two input tensors.

c_reference/models/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ include ../config.mk
66
INCLUDE_DIR=../include
77
IFLAGS = -I $(INCLUDE_DIR)
88

9-
all: quantized_face_detection.o quantized_face_detection_fast.o
9+
all: quantized_face_detection.o quantized_face_detection_fast.o quantized_face_detection_sparse.o
1010

1111
quantized_face_detection.o: quantized_face_detection.c
1212
$(CC) -o $@ $(IFLAGS) $(CFLAGS) -c $^
1313

1414
quantized_face_detection_fast.o: quantized_face_detection_fast.c
1515
$(CC) -o $@ $(IFLAGS) $(CFLAGS) -c $^
1616

17+
quantized_face_detection_sparse.o: quantized_face_detection_sparse.c
18+
$(CC) -o $@ $(IFLAGS) $(CFLAGS) -c $^
19+
1720
.PHONY: clean cleanest
1821

1922
clean:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:e3386605f719f98078e9dd47e74353a08ab2d57d57a226b5e9663850a6d2bcb8
3-
size 5833
2+
oid sha256:455faca056eaec8069e17ed4829c5f6f4e513c972fd569e659c08e5a95b03d2e
3+
size 5908
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c26d12688e8264c0580b83b0c3043007a8872e855235d24d858926512ca4d890
3-
size 6997
2+
oid sha256:2132f05705188ae5008d6f43120c625c5995bb4133aff4327e4232edeb3baac1
3+
size 7073
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:40d453b1415418d36529cc645885ab3ce220de744826d32b5563464bf09a6570
3-
size 5853
2+
oid sha256:fbe2ceaa3e3cce2a7fc844311b0be170fd703f9ed0cb9ac4f41ecfc600bb0f53
3+
size 5928
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c3b5c16018b7dffcab15060f1f13e592b07487b77765213e64ebb31e366c2ef6
3-
size 6941
2+
oid sha256:ff0b4a711a06ed71e8bbf1682c4d9f7ee17d25cca7f291c9a4b3347daae52e6f
3+
size 7017
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:334038e066c40017acf7dee0d8ebcb1072968f1ac289e398908c70936d182f71
3+
size 2289
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:953b19e45354a3b3796db7f658915ea160a468de30830117c3998d0d10c17e35
3+
size 17457

0 commit comments

Comments
 (0)