Skip to content

Commit 956d3a0

Browse files
committed
modified: arc_design_contest/2019/HUST_electrical_load_identification/main.c
modified: arc_design_contest/2019/HUST_electrical_load_identification/makefile modified: arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_coefficients.c modified: arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_constants.h modified: arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_model.c modified: arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_model.h modified: arc_design_contest/2019/HUST_electrical_load_identification/oled_display.c modified: arc_design_contest/2019/HUST_electrical_load_identification/process.c
1 parent a56eafa commit 956d3a0

File tree

8 files changed

+226
-3532
lines changed

8 files changed

+226
-3532
lines changed

arc_design_contest/2019/HUST_electrical_load_identification/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,29 @@ int main(void)
6060
display_welcome(&u8g);
6161
board_delay_ms(2000, 1);
6262

63-
EMBARC_PRINTF("Load Identification\r\n");
63+
EMBARC_PRINTF("*************Load Identification****************\r\n");
6464
/* configuring GPIO to handle the "data ready" interrupt */
6565
while (1) {
6666
board_delay_ms(1, 1);
67-
EMBARC_PRINTF("Hello ARC\r\n");
67+
// EMBARC_PRINTF("Hello ARC\r\n");
6868
if(proc_flag == 0){
6969
if(one_frame_finish_flag == 0){
7070
ad7991_adc_read(ad7991_sensor, ad_data);
7171
input_buffer_push_data(ad_data);
7272
}
7373
else{
7474
my_result = Cnn_Net_Classify();
75+
u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_2x_i2c, U8G_COM_SSD_I2C);
76+
u8g_Begin(&u8g); /* reset display and put it into default state */
7577
display_result(&u8g, my_result);
7678
one_frame_finish_flag = 0;
79+
EMBARC_PRINTF("Result:%d\r\n",my_result);
7780
proc_flag = 1;
7881
}
7982
}
8083
else{
8184
proc_flag = 0;
82-
board_delay_ms(100, 1);
85+
board_delay_ms(500, 1);
8386
}
8487
}
8588
return E_SYS;

arc_design_contest/2019/HUST_electrical_load_identification/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ OLEVEL = O0
1717
#
1818
# root dir of embARC
1919
#
20-
EMBARC_ROOT = ../../../..
20+
EMBARC_ROOT = ../../
2121

2222
# use -Hpurge option to optimize the code size
2323
ifeq ($(TOOLCHAIN), gnu)

arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_coefficients.c

Lines changed: 163 additions & 3348 deletions
Large diffs are not rendered by default.

arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_constants.h

Lines changed: 29 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,16 @@ extern const w_type _W L1_conv_bias_buf[];
4949
extern const w_type _W L2_conv_wt_buf[];
5050
extern const w_type _W L2_conv_bias_buf[];
5151

52-
extern const w_type _W2 L3_conv_wt_buf[];
53-
extern const w_type _W2 L3_conv_bias_buf[];
5452

55-
extern const w_type _W2 L4_fc_wt_buf[];
56-
extern const w_type _W2 L4_fc_bias_buf[];
53+
extern const w_type _W2 L3_fc_wt_buf[];
54+
extern const w_type _W2 L3_fc_bias_buf[];
5755

58-
#if defined(MODEL_BIG)
59-
extern const w_type _W2 L5_fc_wt_buf[];
60-
extern const w_type _W2 L5_fc_bias_buf[];
61-
#endif
6256

6357
//======================================================
6458
//
6559
// Tensor's Integer bits per layer definitions
6660
//
6761
//======================================================
68-
#if !defined(MODEL_BIG) // Small Model
6962
#if (MODEL_BIT_DEPTH == MODEL_FX_16)
7063

7164
#define CONV1_W_INT (-1)
@@ -76,13 +69,10 @@ extern const w_type _W2 L5_fc_bias_buf[];
7669
#define CONV2_B_INT (-1)
7770
#define CONV2_OUT_INT (5)
7871

79-
#define CONV3_W_INT (-1)
80-
#define CONV3_B_INT (-2)
81-
#define CONV3_OUT_INT (6)
8272

83-
#define FC4_W_INT (-1)
84-
#define FC4_B_INT (-2)
85-
#define FC4_OUT_INT (5)
73+
#define FC3_W_INT (-1)
74+
#define FC3_B_INT (-2)
75+
#define FC3_OUT_INT (5)
8676

8777
#else //(MODEL_BIT_DEPTH == MODEL_FX_8 or MODEL_FX_8W16D)
8878

@@ -94,65 +84,13 @@ extern const w_type _W2 L5_fc_bias_buf[];
9484
#define CONV2_B_INT (-1)
9585
#define CONV2_OUT_INT (5)
9686

97-
#define CONV3_W_INT (-1)
98-
#define CONV3_B_INT (-2)
99-
#define CONV3_OUT_INT (5)
10087

101-
#define FC4_W_INT (-1)
102-
#define FC4_B_INT (-2)
103-
#define FC4_OUT_INT (5)
88+
#define FC3_W_INT (-1)
89+
#define FC3_B_INT (-2)
90+
#define FC3_OUT_INT (5)
10491

10592
#endif
10693

107-
#else // Big Model
108-
#if (MODEL_BIT_DEPTH == MODEL_FX_16)
109-
110-
#define CONV1_W_INT (0)
111-
#define CONV1_B_INT (0)
112-
#define CONV1_OUT_INT (5)
113-
114-
#define CONV2_W_INT (-1)
115-
#define CONV2_B_INT (-1)
116-
#define CONV2_OUT_INT (6)
117-
118-
#define CONV3_W_INT (-2)
119-
#define CONV3_B_INT (-2)
120-
#define CONV3_OUT_INT (5)
121-
122-
#define FC4_W_INT (-1)
123-
#define FC4_B_INT (-3)
124-
#define FC4_OUT_INT (3)
125-
126-
#define FC5_W_INT (0)
127-
#define FC5_B_INT (-2)
128-
#define FC5_OUT_INT (5)
129-
130-
131-
#else //(MODEL_BIT_DEPTH == MODEL_FX_8 or MODEL_FX_8W16D)
132-
133-
#define CONV1_W_INT (0)
134-
#define CONV1_B_INT (0)
135-
#define CONV1_OUT_INT (4)
136-
137-
#define CONV2_W_INT (-1)
138-
#define CONV2_B_INT (-1)
139-
#define CONV2_OUT_INT (5)
140-
141-
#define CONV3_W_INT (-2)
142-
#define CONV3_B_INT (-2)
143-
#define CONV3_OUT_INT (4)
144-
145-
#define FC4_W_INT (-2)
146-
#define FC4_B_INT (-3)
147-
#define FC4_OUT_INT (3)
148-
149-
#define FC5_W_INT (0)
150-
#define FC5_B_INT (-2)
151-
#define FC5_OUT_INT (5)
152-
153-
#endif
154-
#endif
155-
15694
//======================================================
15795
//
15896
// Shape and Fractional bits per layer definitions
@@ -161,15 +99,15 @@ extern const w_type _W2 L5_fc_bias_buf[];
16199

162100
// CONV1
163101
//================================================
164-
#define CONV1_W_SHAPE {32,3,5,5}
165-
#define CONV1_W_ELEMENTS (32*3*5*5)
102+
#define CONV1_W_SHAPE {4,1,5,5}
103+
#define CONV1_W_ELEMENTS (4*1*5*5)
166104
#define CONV1_W_RANK (4)
167105

168106
#define CONV1_W_FRAQ (FRQ_BITS(CONV1_W_INT, w_type))
169107
#define L1_WQ(val) QMN(w_type, CONV1_W_FRAQ, val)
170108

171-
#define CONV1_B_ELEMENTS (32)
172-
#define CONV1_B_SHAPE {32}
109+
#define CONV1_B_ELEMENTS (4)
110+
#define CONV1_B_SHAPE {4}
173111
#define CONV1_B_RANK (1)
174112

175113
#define CONV1_B_FRAQ (FRQ_BITS(CONV1_B_INT, w_type))
@@ -179,17 +117,10 @@ extern const w_type _W2 L5_fc_bias_buf[];
179117

180118
// CONV2
181119
//================================================
182-
#if defined(MODEL_BIG)
183-
#define CONV2_W_SHAPE {32,32,5,5}
184-
#define CONV2_W_ELEMENTS (32*32*5*5)
185-
#define CONV2_B_SHAPE {32}
186-
#define CONV2_B_ELEMENTS (32)
187-
#else // Small Model
188-
#define CONV2_W_SHAPE {16,32,5,5}
189-
#define CONV2_W_ELEMENTS (16*32*5*5)
190-
#define CONV2_B_SHAPE {16}
191-
#define CONV2_B_ELEMENTS (16)
192-
#endif
120+
#define CONV2_W_SHAPE {2,4,5,5}
121+
#define CONV2_W_ELEMENTS (2*4*5*5)
122+
#define CONV2_B_SHAPE {2}
123+
#define CONV2_B_ELEMENTS (2)
193124

194125
#define CONV2_W_RANK (4)
195126
#define CONV2_B_RANK (1)
@@ -200,51 +131,21 @@ extern const w_type _W2 L5_fc_bias_buf[];
200131
#define L2_BQ(val) QMN(w_type, CONV2_B_FRAQ, val)
201132
#define CONV2_OUT_FRAQ (FRQ_BITS(CONV2_OUT_INT, d_type))
202133

203-
// CONV3
204-
//================================================
205-
#if defined(MODEL_BIG)
206-
#define CONV3_W_SHAPE {64,32,5,5}
207-
#define CONV3_W_ELEMENTS (64*32*5*5)
208-
#define CONV3_B_SHAPE {64}
209-
#define CONV3_B_ELEMENTS (64)
210-
#else // Small Model
211-
#define CONV3_W_SHAPE {32,16,5,5}
212-
#define CONV3_W_ELEMENTS (32*16*5*5)
213-
#define CONV3_B_SHAPE {32}
214-
#define CONV3_B_ELEMENTS (32)
215-
#endif
216-
#define CONV3_W_RANK (4)
217-
#define CONV3_B_RANK (1)
218-
219-
#define CONV3_W_FRAQ (FRQ_BITS(CONV2_W_INT, w_type))
220-
#define L3_WQ(val) QMN(w_type, CONV2_W_FRAQ, val)
221-
#define CONV3_B_FRAQ (FRQ_BITS(CONV2_B_INT, w_type))
222-
#define L3_BQ(val) QMN(w_type, CONV2_B_FRAQ, val)
223-
#define CONV3_OUT_FRAQ (FRQ_BITS(CONV2_OUT_INT, d_type))
224134

225-
// FC4
135+
// FC3
226136
//================================================
227-
#if defined(MODEL_BIG)
228-
#define FC4_W_SHAPE {64,(64*16)}
229-
#define FC4_W_ELEMENTS (64*(64*16))
230-
#define FC4_B_SHAPE {64}
231-
#define FC4_B_ELEMENTS (64)
232-
#else // Small Model
233-
#define FC4_W_SHAPE {10,(32*16)}
234-
#define FC4_W_ELEMENTS (10*(32*16))
235-
#define FC4_B_SHAPE {10}
236-
#define FC4_B_ELEMENTS (10)
237-
#endif
238-
#define FC4_W_RANK (2)
239-
#define FC4_B_RANK (1)
240-
241-
#define FC4_W_FRAQ (FRQ_BITS(FC4_W_INT, w_type))
242-
#define L4_WQ(val) QMN(w_type, FC4_W_FRAQ, val)
243-
#define FC4_B_FRAQ (FRQ_BITS(FC4_B_INT, w_type))
244-
#define L4_BQ(val) QMN(w_type, FC4_B_FRAQ, val)
245-
#define FC4_OUT_FRAQ (FRQ_BITS(FC4_OUT_INT, d_type))
246-
247-
137+
#define FC3_W_SHAPE {6,(7*7*4)}
138+
#define FC3_W_ELEMENTS (6*(7*7*4))
139+
#define FC3_B_SHAPE {6}
140+
#define FC3_B_ELEMENTS (6)
141+
#define FC3_W_RANK (2)
142+
#define FC3_B_RANK (1)
143+
144+
#define FC3_W_FRAQ (FRQ_BITS(FC3_W_INT, w_type))
145+
#define L3_WQ(val) QMN(w_type, FC3_W_FRAQ, val)
146+
#define FC3_B_FRAQ (FRQ_BITS(FC3_B_INT, w_type))
147+
#define L3_BQ(val) QMN(w_type, FC3_B_FRAQ, val)
148+
#define FC3_OUT_FRAQ (FRQ_BITS(FC3_OUT_INT, d_type))
248149

249150

250151

arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_model.c

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@
4141

4242
// Intermediate data buffers (enough size for max intermediate results)
4343
//==============================
44-
#define IR_BUF_SZ_MOST (32*32*32) //32768
45-
#define IR_BUF_SZ_NEXT (32*16*16)
44+
#define IR_BUF_SZ_MOST (28*28*28) //32768
45+
#define IR_BUF_SZ_NEXT (28*14*14)
4646
static d_type _Z x_mem_buf[IR_BUF_SZ_MOST];
4747
static d_type _Y y_mem_buf[IR_BUF_SZ_NEXT];
4848

4949
// Module Input/Output tensors and their's external interface
5050
//============================================================
5151
static mli_tensor input = {
5252
.data = (void *)x_mem_buf,
53-
.capacity = sizeof(d_type) * (28 * 28 * 1),
54-
.shape = IN_POINTS,
53+
.capacity = sizeof(d_type) * IN_POINTS,
54+
.shape = {28, 28, 1},
5555
.rank = 3,
5656
.el_type = D_EL_TYPE,
5757
.el_params.fx.frac_bits = 7,
5858
};
5959

6060
static mli_tensor output = {
6161
.data = (void *)y_mem_buf,
62-
.capacity = sizeof(d_type) * (10),
62+
.capacity = sizeof(d_type) * OUT_POINTS,
6363
.shape = OUT_POINTS,
64-
.rank = 1,
64+
.rank = {6},
6565
.el_type = D_EL_TYPE,
6666
.el_params.fx.frac_bits = 0,
6767
};
@@ -142,45 +142,26 @@ static mli_tensor L2_conv_bias = {
142142
};
143143

144144

145-
// Conv 3 Layer related data
146-
//===================================
147-
static mli_tensor L3_conv_wt = {
148-
.data = (void *)L3_conv_wt_buf,
149-
.capacity = CONV3_W_ELEMENTS * sizeof(w_type),
150-
.shape = CONV3_W_SHAPE,
151-
.rank = CONV3_W_RANK,
152-
.el_type = W_EL_TYPE,
153-
.el_params.fx.frac_bits = CONV3_W_FRAQ,
154-
};
155-
156-
static mli_tensor L3_conv_bias = {
157-
.data = (void *)L3_conv_bias_buf,
158-
.capacity = CONV3_B_ELEMENTS * sizeof(w_type),
159-
.shape = CONV3_B_SHAPE,
160-
.rank = CONV3_B_RANK,
161-
.el_type = W_EL_TYPE,
162-
.el_params.fx.frac_bits = CONV3_B_FRAQ,
163-
};
164145

165146

166-
// FC4 Layer related data
147+
// FC3 Layer related data
167148
//===================================
168-
static mli_tensor L4_fc_wt = {
169-
.data = (void *)L4_fc_wt_buf,
170-
.capacity = FC4_W_ELEMENTS * sizeof(w_type),
171-
.shape = FC4_W_SHAPE,
172-
.rank = FC4_W_RANK,
149+
static mli_tensor L3_fc_wt = {
150+
.data = (void *)L3_fc_wt_buf,
151+
.capacity = FC3_W_ELEMENTS * sizeof(w_type),
152+
.shape = FC3_W_SHAPE,
153+
.rank = FC3_W_RANK,
173154
.el_type = W_EL_TYPE,
174-
.el_params.fx.frac_bits = FC4_W_FRAQ,
155+
.el_params.fx.frac_bits = FC3_W_FRAQ,
175156
};
176157

177-
static mli_tensor L4_fc_bias = {
178-
.data = (void *)L4_fc_bias_buf,
179-
.capacity = FC4_B_ELEMENTS * sizeof(w_type),
180-
.shape = FC4_B_SHAPE,
181-
.rank = FC4_B_RANK,
158+
static mli_tensor L3_fc_bias = {
159+
.data = (void *)L3_fc_bias_buf,
160+
.capacity = FC3_B_ELEMENTS * sizeof(w_type),
161+
.shape = FC3_B_SHAPE,
162+
.rank = FC3_B_RANK,
182163
.el_type = W_EL_TYPE,
183-
.el_params.fx.frac_bits = FC4_B_FRAQ,
164+
.el_params.fx.frac_bits = FC3_B_FRAQ,
184165
};
185166

186167

@@ -255,19 +236,12 @@ void load_identification_net(void) {
255236
//=======================================
256237
ir_tensor_X.el_params.fx.frac_bits = CONV2_OUT_FRAQ;
257238
conv2d_chw(&ir_tensor_Y, &L2_conv_wt, &L2_conv_bias, &shared_conv_cfg, &ir_tensor_X);
258-
avepool_chw(&ir_tensor_X, &shared_pool_cfg, &ir_tensor_Y);
239+
maxpool_chw(&ir_tensor_X, &shared_pool_cfg, &ir_tensor_Y);
259240

260241
// LAYER 3
261242
//=======================================
262-
ir_tensor_X.el_params.fx.frac_bits = CONV3_OUT_FRAQ;
263-
conv2d_chw(&ir_tensor_Y, &L3_conv_wt, &L3_conv_bias, &shared_conv_cfg, &ir_tensor_X);
264-
avepool_chw(&ir_tensor_X, &shared_pool_cfg, &ir_tensor_Y);
265-
266-
// LAYER 4
267-
//=======================================
268-
ir_tensor_X.el_params.fx.frac_bits = FC4_OUT_FRAQ;
269-
fully_connected(&ir_tensor_Y, &L4_fc_wt, &L4_fc_bias, &ir_tensor_X);
270-
243+
ir_tensor_X.el_params.fx.frac_bits = FC3_OUT_FRAQ;
244+
fully_connected(&ir_tensor_Y, &L3_fc_wt, &L3_fc_bias, &ir_tensor_X);
271245

272246
softmax(&ir_tensor_X, &output);
273247

arc_design_contest/2019/HUST_electrical_load_identification/model/load_identification_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
extern mli_tensor * const load_identification_net_input;
2626
#define IN_POINTS (28 * 28 * 1)
2727
extern mli_tensor * const load_identification_net_output;
28-
#define OUT_POINTS (10)
28+
#define OUT_POINTS (6)
2929

3030
extern void load_identification_net(void);
3131

0 commit comments

Comments
 (0)