forked from xuos/xiuos
refactor(knowing app): add common k210 yolov2 detection procedure
This commit is contained in:
parent
d368db9e76
commit
c07c918150
|
@ -5,9 +5,7 @@ menu "knowing app"
|
|||
|
||||
if APPLICATION_KNOWING
|
||||
source "$APP_DIR/Applications/knowing_app/mnist/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/face_detect/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/instrusion_detect/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/helmet_detect/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/k210_detect_entry/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/iris_ml_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/k210_fft_test/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/image_processing/Kconfig"
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
config FACE_DETECT
|
||||
bool "enable apps/face detect"
|
||||
depends on BOARD_K210_EVB
|
||||
depends on DRV_USING_OV2640
|
||||
depends on USING_KPU_PROCESSING
|
||||
depends on USING_YOLOV2
|
||||
depends on USING_YOLOV2_JSONPARSER
|
||||
select LIB_USING_CJSON
|
||||
default n
|
|
@ -1,9 +0,0 @@
|
|||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Applications', src, depend = ['FACE_DETECT'], LOCAL_CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
|
@ -1,8 +0,0 @@
|
|||
config HELMET_DETECT
|
||||
bool "enable apps/helmet detect"
|
||||
depends on BOARD_K210_EVB
|
||||
depends on DRV_USING_OV2640
|
||||
depends on USING_KPU_PROCESSING
|
||||
depends on USING_YOLOV2
|
||||
select LIB_USING_CJSON
|
||||
default n
|
|
@ -1,167 +0,0 @@
|
|||
# Helmet detection demo
|
||||
|
||||
### A helmet and head without helmet object detection task demo. Running MobileNet-yolo on K210-based edge devices.
|
||||
|
||||
---
|
||||
|
||||
## Training
|
||||
|
||||
### Enviroment preparation
|
||||
|
||||
Model generated by [aXeleRate](https://forgeplus.trustie.net/projects/yangtuo250/aXeleRate) and converted to kmodel by [nncase](https://github.com/kendryte/nncase/tree/v0.1.0-rc5).
|
||||
|
||||
```shell
|
||||
# master branch for MobileNetv1-yolov2 and unstable branch to test MobileNetv1(v2)-yolov2(v3)
|
||||
git clone https://git.trustie.net/yangtuo250/aXeleRate.git (-b unstable)
|
||||
cd aXeleRate
|
||||
pip install -r requirments.txt && pip install -e .
|
||||
```
|
||||
|
||||
### training config setting
|
||||
|
||||
Example [config](https://forgeplus.trustie.net/projects/yangtuo250/aXeleRate/tree/master/configs/detector.json), some hyper-parameters:
|
||||
|
||||
- architecture: backbone, MobileNet7_5 for default, MobileNet1_0(α = 1.0) and above cannot run on K210 because of OOM on feature map in master branch. For unstable branch MobileNetV2_1_0 is OK.
|
||||
|
||||
- input_size: fixed model input size, single integer for height equals to width, otherwise a list([height, width]).
|
||||
- anchors: yolov2 anchor(for master) or anchor scaled to 1.0(for unstable), can be generate by [darknet](https://github.com/AlexeyAB/darknet).
|
||||
- labels: labels of all classes.
|
||||
- train(valid)_image(annot)_folder: path of images and annoations for training and validation.
|
||||
- saved_folder: path for trainig result storage(models, checkpoints, logs ...).
|
||||
|
||||
Mine config for unstable:
|
||||
```json
|
||||
{
|
||||
"model": {
|
||||
"type": "Detector",
|
||||
"architecture": "MobileNetV2_1_0",
|
||||
"input_size": [
|
||||
224,
|
||||
320
|
||||
],
|
||||
"anchors": [
|
||||
[
|
||||
[
|
||||
0.1043,
|
||||
0.1560
|
||||
],
|
||||
[
|
||||
0.0839,
|
||||
0.3036
|
||||
],
|
||||
[
|
||||
0.1109,
|
||||
0.3923
|
||||
],
|
||||
[
|
||||
0.1378,
|
||||
0.5244
|
||||
],
|
||||
[
|
||||
0.2049,
|
||||
0.6673
|
||||
]
|
||||
]
|
||||
],
|
||||
"labels": [
|
||||
"human"
|
||||
],
|
||||
"obj_thresh": 0.5,
|
||||
"iou_thresh": 0.45,
|
||||
"coord_scale": 1.0,
|
||||
"class_scale": 0.0,
|
||||
"object_scale": 5.0,
|
||||
"no_object_scale": 3.0
|
||||
},
|
||||
"weights": {
|
||||
"full": "",
|
||||
"backend": ""
|
||||
},
|
||||
"train": {
|
||||
"actual_epoch": 2000,
|
||||
"train_image_folder": "mydata/human/Images/train",
|
||||
"train_annot_folder": "mydata/human/Annotations/train",
|
||||
"train_times": 2,
|
||||
"valid_image_folder": "mydata/human/Images/val",
|
||||
"valid_annot_folder": "mydata/human/Annotations/val",
|
||||
"valid_times": 1,
|
||||
"valid_metric": "precision",
|
||||
"batch_size": 32,
|
||||
"learning_rate": 2e-5,
|
||||
"saved_folder": "mydata/human/results",
|
||||
"first_trainable_layer": "",
|
||||
"augmentation": true,
|
||||
"is_only_detect": false,
|
||||
"validation_freq": 5,
|
||||
"quantize": false,
|
||||
"class_weights": [1.0]
|
||||
},
|
||||
"converter": {
|
||||
"type": [
|
||||
"k210"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
*(For more detailed config usage, please refer to original aXeleRate repo.)*
|
||||
|
||||
### data preparation
|
||||
|
||||
Please refer to [VOC format](https://towardsdatascience.com/coco-data-format-for-object-detection-a4c5eaf518c5), path as config above.
|
||||
|
||||
### train it!
|
||||
|
||||
```shell
|
||||
python -m aXeleRate.train -c PATH_TO_YOUR_CONFIG
|
||||
```
|
||||
|
||||
### model convert
|
||||
|
||||
Please refer to [nncase repo](https://github.com/kendryte/nncase/tree/v0.1.0-rc5).
|
||||
|
||||
---
|
||||
|
||||
## Deployment
|
||||
|
||||
### compile and burn
|
||||
|
||||
Use `(scons --)menuconfig` in bsp folder *(Ubiquitous/RT_Thread/bsp/k210)*, open:
|
||||
|
||||
- More Drivers --> ov2640 driver
|
||||
- Board Drivers Config --> Enable LCD on SPI0
|
||||
- Board Drivers Config --> Enable SDCARD (spi1(ss0))
|
||||
- Board Drivers Config --> Enable DVP(camera)
|
||||
- RT-Thread Components --> POSIX layer and C standard library --> Enable pthreads APIs
|
||||
- APP_Framework --> Framework --> support knowing framework --> kpu model postprocessing --> yolov2 region layer
|
||||
- APP_Framework --> Applications --> knowing app --> enable apps/helmet detect
|
||||
|
||||
`scons -j(n)` to compile and burn in by *kflash*.
|
||||
|
||||
### json config and kmodel
|
||||
|
||||
Copy json config for deployment o SD card */kmodel*. Example config file is *helmet.json* in this directory. Something to be modified:
|
||||
|
||||
- net_input_size: same as *input_size* in training config file, but array only.
|
||||
- net_output_shape: final feature map size, can be found in **nncase** output.
|
||||
- sensor_output_size: image height and width from camera.
|
||||
- kmodel_size: kmodel size shown in file system.
|
||||
- anchors: same as *anchor* in training config file(multi-dimention anchors flatten to 1 dim).
|
||||
- labels: same as *label* in training config file.
|
||||
- obj_thresh: array, object threshold of each label.
|
||||
- nms_thresh: NMS threshold of boxes.
|
||||
|
||||
Copy final kmodel to SD card */kmodel* either.
|
||||
|
||||
---
|
||||
|
||||
## Run
|
||||
|
||||
In serial terminal, `helmet_detect` to start a detection thread, `helmet_detect_delete` to stop it. Detection results can be found in output.
|
||||
|
||||
---
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] Fix LCD real-time result display.
|
||||
- [ ] Test more object detection backbone and algorithm(like yolox).
|
|
@ -1,9 +0,0 @@
|
|||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Applications', src, depend = ['HELMET_DETECT'], LOCAL_CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
|
@ -1,380 +0,0 @@
|
|||
#include <transform.h>
|
||||
#ifdef LIB_USING_CJSON
|
||||
#include <cJSON.h>
|
||||
#endif
|
||||
#include "region_layer.h"
|
||||
#define ANCHOR_NUM 5
|
||||
#define STACK_SIZE (128 * 1024)
|
||||
#define JSON_FILE_PATH "/kmodel/helmet.json"
|
||||
#define JSON_BUFFER_SIZE (4 * 1024)
|
||||
|
||||
// params from json
|
||||
static float anchor[ANCHOR_NUM * 2] = {};
|
||||
static int net_output_shape[3] = {};
|
||||
static int net_input_size[2] = {};
|
||||
static int sensor_output_size[2] = {};
|
||||
static char kmodel_path[127] = "";
|
||||
static int kmodel_size = 0;
|
||||
static float obj_thresh[20] = {};
|
||||
static float nms_thresh = 0.0;
|
||||
static char labels[20][32] = {};
|
||||
static int class_num = 0;
|
||||
|
||||
#define THREAD_PRIORITY_HELMET_D (11)
|
||||
static pthread_t helmettid = 0;
|
||||
static void *thread_helmet_detect_entry(void *parameter);
|
||||
static int g_fd = 0;
|
||||
static int kmodel_fd = 0;
|
||||
static int if_exit = 0;
|
||||
static unsigned char *showbuffer = NULL;
|
||||
static unsigned char *kpurgbbuffer = NULL;
|
||||
|
||||
static _ioctl_shoot_para shoot_para_t = {0};
|
||||
unsigned char *model_data = NULL; // kpu data load memory
|
||||
unsigned char *model_data_align = NULL;
|
||||
|
||||
kpu_model_context_t helmet_detect_task;
|
||||
static region_layer_t helmet_detect_rl;
|
||||
static obj_info_t helmet_detect_info;
|
||||
volatile uint32_t g_ai_done_flag;
|
||||
|
||||
static void ai_done(void *ctx) { g_ai_done_flag = 1; }
|
||||
|
||||
static void param_parse()
|
||||
{
|
||||
int fin;
|
||||
char buffer[JSON_BUFFER_SIZE] = "";
|
||||
// char *buffer;
|
||||
// if (NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
|
||||
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
|
||||
// } else {
|
||||
// printf("Json buffer malloc failed!");
|
||||
// exit(-1);
|
||||
// }
|
||||
int array_size;
|
||||
cJSON *json_obj;
|
||||
cJSON *json_item;
|
||||
cJSON *json_array_item;
|
||||
|
||||
fin = open(JSON_FILE_PATH, O_RDONLY);
|
||||
if (!fin) {
|
||||
printf("Error open file %s", JSON_FILE_PATH);
|
||||
exit(-1);
|
||||
}
|
||||
read(fin, buffer, sizeof(buffer));
|
||||
close(fin);
|
||||
|
||||
// read json string
|
||||
json_obj = cJSON_Parse(buffer);
|
||||
// free(buffer);
|
||||
char *json_print_str = cJSON_Print(json_obj);
|
||||
printf("Json file content: \n%s\n", json_print_str);
|
||||
cJSON_free(json_print_str);
|
||||
// get anchors
|
||||
json_item = cJSON_GetObjectItem(json_obj, "anchors");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (ANCHOR_NUM * 2 != array_size) {
|
||||
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d anchors from json file\n", ANCHOR_NUM);
|
||||
}
|
||||
for (int i = 0; i < ANCHOR_NUM * 2; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
anchor[i] = json_array_item->valuedouble;
|
||||
printf("%d: %f\n", i, anchor[i]);
|
||||
}
|
||||
// net_input_size
|
||||
json_item = cJSON_GetObjectItem(json_obj, "net_input_size");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (2 != array_size) {
|
||||
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d net_input_size from json file\n", 2);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
net_input_size[i] = json_array_item->valueint;
|
||||
printf("%d: %d\n", i, net_input_size[i]);
|
||||
}
|
||||
// net_output_shape
|
||||
json_item = cJSON_GetObjectItem(json_obj, "net_output_shape");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (3 != array_size) {
|
||||
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d net_output_shape from json file\n", 3);
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
net_output_shape[i] = json_array_item->valueint;
|
||||
printf("%d: %d\n", i, net_output_shape[i]);
|
||||
}
|
||||
// sensor_output_size
|
||||
json_item = cJSON_GetObjectItem(json_obj, "sensor_output_size");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (2 != array_size) {
|
||||
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d sensor_output_size from json file\n", 2);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
sensor_output_size[i] = json_array_item->valueint;
|
||||
printf("%d: %d\n", i, sensor_output_size[i]);
|
||||
}
|
||||
// kmodel_path
|
||||
json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
|
||||
memcpy(kmodel_path, json_item->valuestring, strlen(json_item->valuestring));
|
||||
printf("Got kmodel_path: %s\n", kmodel_path);
|
||||
// kmodel_size
|
||||
json_item = cJSON_GetObjectItem(json_obj, "kmodel_size");
|
||||
kmodel_size = json_item->valueint;
|
||||
printf("Got kmodel_size: %d\n", kmodel_size);
|
||||
// labels
|
||||
json_item = cJSON_GetObjectItem(json_obj, "labels");
|
||||
class_num = cJSON_GetArraySize(json_item);
|
||||
if (0 >= class_num) {
|
||||
printf("No labels!");
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d labels\n", class_num);
|
||||
}
|
||||
for (int i = 0; i < class_num; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
memcpy(labels[i], json_array_item->valuestring, strlen(json_array_item->valuestring));
|
||||
printf("%d: %s\n", i, labels[i]);
|
||||
}
|
||||
// obj_thresh
|
||||
json_item = cJSON_GetObjectItem(json_obj, "obj_thresh");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (class_num != array_size) {
|
||||
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", class_num, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d obj_thresh\n", array_size);
|
||||
}
|
||||
for (int i = 0; i < array_size; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
obj_thresh[i] = json_array_item->valuedouble;
|
||||
printf("%d: %f\n", i, obj_thresh[i]);
|
||||
}
|
||||
// nms_thresh
|
||||
json_item = cJSON_GetObjectItem(json_obj, "nms_thresh");
|
||||
nms_thresh = json_item->valuedouble;
|
||||
printf("Got nms_thresh: %f\n", nms_thresh);
|
||||
|
||||
cJSON_Delete(json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
void helmet_detect()
|
||||
{
|
||||
int ret = 0;
|
||||
int result = 0;
|
||||
int size = 0;
|
||||
param_parse();
|
||||
g_fd = open("/dev/ov2640", O_RDONLY);
|
||||
if (g_fd < 0) {
|
||||
printf("open ov2640 fail !!");
|
||||
return;
|
||||
}
|
||||
_ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]};
|
||||
ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso);
|
||||
showbuffer = (unsigned char *)malloc(sensor_output_size[0] * sensor_output_size[1] * 2);
|
||||
if (NULL == showbuffer) {
|
||||
close(g_fd);
|
||||
printf("showbuffer apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
kpurgbbuffer = (unsigned char *)malloc(net_input_size[0] * net_input_size[1] * 3);
|
||||
if (NULL == kpurgbbuffer) {
|
||||
close(g_fd);
|
||||
free(showbuffer);
|
||||
printf("kpurgbbuffer apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
||||
if (NULL == model_data) {
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
close(g_fd);
|
||||
printf("model_data apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
memset(model_data, 0, kmodel_size + 255);
|
||||
memset(showbuffer, 0, sensor_output_size[0] * sensor_output_size[1] * 2);
|
||||
memset(kpurgbbuffer, 127, net_input_size[0] * net_input_size[1] * 3);
|
||||
shoot_para_t.pdata = (unsigned int *)(showbuffer);
|
||||
shoot_para_t.length = (size_t)(sensor_output_size[0] * sensor_output_size[1] * 2);
|
||||
/*
|
||||
load memory
|
||||
*/
|
||||
kmodel_fd = open(kmodel_path, O_RDONLY);
|
||||
if (kmodel_fd < 0) {
|
||||
printf("open kmodel fail");
|
||||
close(g_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
return;
|
||||
} else {
|
||||
size = read(kmodel_fd, model_data, kmodel_size);
|
||||
if (size != kmodel_size) {
|
||||
printf("read kmodel error size %d\n", size);
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
return;
|
||||
|
||||
} else {
|
||||
printf("read kmodel success \n");
|
||||
}
|
||||
}
|
||||
unsigned char *model_data_align = (unsigned char *)(((unsigned int)model_data + 255) & (~255));
|
||||
dvp_set_ai_addr((uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0])),
|
||||
(uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0]) +
|
||||
net_input_size[0] * net_input_size[1]),
|
||||
(uint32_t)(kpurgbbuffer + net_input_size[0] * net_input_size[1] * 2 +
|
||||
net_input_size[1] * (net_input_size[0] - sensor_output_size[0])));
|
||||
if (kpu_load_kmodel(&helmet_detect_task, model_data_align) != 0) {
|
||||
printf("\nmodel init error\n");
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
return;
|
||||
}
|
||||
helmet_detect_rl.anchor_number = ANCHOR_NUM;
|
||||
helmet_detect_rl.anchor = anchor;
|
||||
helmet_detect_rl.threshold = malloc(class_num * sizeof(float));
|
||||
for (int idx = 0; idx < class_num; idx++) {
|
||||
helmet_detect_rl.threshold[idx] = obj_thresh[idx];
|
||||
}
|
||||
helmet_detect_rl.nms_value = nms_thresh;
|
||||
result = region_layer_init(&helmet_detect_rl, net_output_shape[0], net_output_shape[1], net_output_shape[2],
|
||||
net_input_size[1], net_input_size[0]);
|
||||
printf("region_layer_init result %d \n\r", result);
|
||||
size_t stack_size = STACK_SIZE;
|
||||
pthread_attr_t attr; /* 线程属性 */
|
||||
struct sched_param prio; /* 线程优先级 */
|
||||
prio.sched_priority = 8; /* 优先级设置为 8 */
|
||||
pthread_attr_init(&attr); /* 先使用默认值初始化属性 */
|
||||
pthread_attr_setschedparam(&attr, &prio); /* 修改属性对应的优先级 */
|
||||
pthread_attr_setstacksize(&attr, stack_size);
|
||||
|
||||
/* 创建线程 1, 属性为 attr,入口函数是 thread_entry,入口函数参数是 1 */
|
||||
result = pthread_create(&helmettid, &attr, thread_helmet_detect_entry, NULL);
|
||||
if (0 == result) {
|
||||
printf("thread_helmet_detect_entry successfully!\n");
|
||||
} else {
|
||||
printf("thread_helmet_detect_entry failed! error code is %d\n", result);
|
||||
close(g_fd);
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(helmet_detect, helmet detect task);
|
||||
#endif
|
||||
|
||||
static void *thread_helmet_detect_entry(void *parameter)
|
||||
{
|
||||
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
|
||||
printf("thread_helmet_detect_entry start!\n");
|
||||
int ret = 0;
|
||||
// sysctl_enable_irq();
|
||||
while (1) {
|
||||
// memset(showbuffer,0,320*240*2);
|
||||
g_ai_done_flag = 0;
|
||||
ret = ioctl(g_fd, IOCTRL_CAMERA_START_SHOT, &shoot_para_t);
|
||||
if (RT_ERROR == ret) {
|
||||
printf("ov2640 can't wait event flag");
|
||||
rt_free(showbuffer);
|
||||
close(g_fd);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
kpu_run_kmodel(&helmet_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
|
||||
while (!g_ai_done_flag)
|
||||
;
|
||||
float *output;
|
||||
size_t output_size;
|
||||
kpu_get_output(&helmet_detect_task, 0, (uint8_t **)&output, &output_size);
|
||||
helmet_detect_rl.input = output;
|
||||
region_layer_run(&helmet_detect_rl, &helmet_detect_info);
|
||||
/* display result */
|
||||
#ifdef BSP_USING_LCD
|
||||
for (int helmet_cnt = 0; helmet_cnt < helmet_detect_info.obj_number; helmet_cnt++) {
|
||||
// draw_edge((uint32_t *)showbuffer, &helmet_detect_info, helmet_cnt, 0xF800,
|
||||
// (uint16_t)sensor_output_size[1],
|
||||
// (uint16_t)sensor_output_size[0]);
|
||||
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", helmet_cnt, helmet_detect_info.obj[helmet_cnt].x1,
|
||||
helmet_detect_info.obj[helmet_cnt].y1, helmet_detect_info.obj[helmet_cnt].x2,
|
||||
helmet_detect_info.obj[helmet_cnt].y2, labels[helmet_detect_info.obj[helmet_cnt].class_id],
|
||||
helmet_detect_info.obj[helmet_cnt].prob);
|
||||
}
|
||||
if (0 != helmet_detect_info.obj_number) {
|
||||
printf("\n");
|
||||
}
|
||||
lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer);
|
||||
#endif
|
||||
usleep(1);
|
||||
if (1 == if_exit) {
|
||||
if_exit = 0;
|
||||
printf("thread_helmet_detect_entry exit");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void helmet_detect_delete()
|
||||
{
|
||||
if (showbuffer != NULL) {
|
||||
int ret = 0;
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
printf("helmet detect task cancel!!! ret %d ", ret);
|
||||
if_exit = 1;
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(helmet_detect_delete, helmet detect task delete);
|
||||
#endif
|
||||
|
||||
void kmodel_load(unsigned char *model_data)
|
||||
{
|
||||
int kmodel_fd = 0;
|
||||
int size = 0;
|
||||
kmodel_fd = open(kmodel_path, O_RDONLY);
|
||||
|
||||
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
||||
if (NULL == model_data) {
|
||||
printf("model_data apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
memset(model_data, 0, kmodel_size + 255);
|
||||
|
||||
if (kmodel_fd >= 0) {
|
||||
size = read(kmodel_fd, model_data, kmodel_size);
|
||||
if (size != kmodel_size) {
|
||||
printf("read kmodel error size %d\n", size);
|
||||
|
||||
} else {
|
||||
printf("read kmodel success");
|
||||
}
|
||||
} else {
|
||||
free(model_data);
|
||||
printf("open kmodel fail");
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(kmodel_load, kmodel load memory);
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
config INSTRUSION_DETECT
|
||||
bool "enable apps/instrusion detect"
|
||||
depends on BOARD_K210_EVB
|
||||
depends on DRV_USING_OV2640
|
||||
depends on USING_KPU_PROCESSING
|
||||
depends on USING_YOLOV2
|
||||
select LIB_USING_CJSON
|
||||
default n
|
|
@ -1,5 +0,0 @@
|
|||
# Instrusion detect demo
|
||||
|
||||
### A human object detection task demo. Running MobileNet-yolo on K210-based edge devices.
|
||||
|
||||
***Training, deployment and running, please see helmet_detect***
|
|
@ -1,390 +0,0 @@
|
|||
#include <transform.h>
|
||||
#include <unistd.h>
|
||||
#ifdef LIB_USING_CJSON
|
||||
#include <cJSON.h>
|
||||
#endif
|
||||
#include "region_layer.h"
|
||||
#define ANCHOR_NUM 5
|
||||
#define STACK_SIZE (128 * 1024)
|
||||
#define JSON_FILE_PATH "/kmodel/human.json"
|
||||
#define JSON_BUFFER_SIZE (4 * 1024)
|
||||
static dmac_channel_number_t dma_ch = DMAC_CHANNEL_MAX;
|
||||
|
||||
extern void lcd_show_image(int x, int y, int wide, int height,const rt_uint8_t *buf);
|
||||
// params from json
|
||||
static float anchor[ANCHOR_NUM * 2] = {};
|
||||
static int net_output_shape[3] = {};
|
||||
static int net_input_size[2] = {};
|
||||
static int sensor_output_size[2] = {};
|
||||
static char kmodel_path[127] = "";
|
||||
static int kmodel_size = 0;
|
||||
static float obj_thresh[20] = {};
|
||||
static float nms_thresh = 0.0;
|
||||
static char labels[20][32] = {};
|
||||
static int class_num = 0;
|
||||
|
||||
#define THREAD_PRIORITY_HUMAN_D (11)
|
||||
static pthread_t instrusiontid = 0;
|
||||
static void *thread_instrusion_detect_entry(void *parameter);
|
||||
static int g_fd = 0;
|
||||
static int kmodel_fd = 0;
|
||||
static int if_exit = 0;
|
||||
static unsigned char *showbuffer = NULL;
|
||||
static unsigned char *kpurgbbuffer = NULL;
|
||||
|
||||
static _ioctl_shoot_para shoot_para_t = {0};
|
||||
unsigned char *model_data = NULL; // kpu data load memory
|
||||
unsigned char *model_data_align = NULL;
|
||||
|
||||
kpu_model_context_t instrusion_detect_task;
|
||||
static region_layer_t instrusion_detect_rl;
|
||||
static obj_info_t instrusion_detect_info;
|
||||
volatile uint32_t g_ai_done_flag;
|
||||
|
||||
static void ai_done(void *ctx) { g_ai_done_flag = 1; }
|
||||
|
||||
static void param_parse()
|
||||
{
|
||||
int fin;
|
||||
char buffer[JSON_BUFFER_SIZE] = "";
|
||||
// char *buffer;
|
||||
// if (NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
|
||||
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
|
||||
// } else {
|
||||
// printf("Json buffer malloc failed!");
|
||||
// exit(-1);
|
||||
// }
|
||||
int array_size;
|
||||
cJSON *json_obj;
|
||||
cJSON *json_item;
|
||||
cJSON *json_array_item;
|
||||
|
||||
fin = open(JSON_FILE_PATH, O_RDONLY);
|
||||
if (!fin) {
|
||||
printf("Error open file %s", JSON_FILE_PATH);
|
||||
exit(-1);
|
||||
}
|
||||
read(fin, buffer, sizeof(buffer));
|
||||
close(fin);
|
||||
|
||||
// read json string
|
||||
json_obj = cJSON_Parse(buffer);
|
||||
// free(buffer);
|
||||
char *json_print_str = cJSON_Print(json_obj);
|
||||
printf("Json file content: \n%s\n", json_print_str);
|
||||
cJSON_free(json_print_str);
|
||||
// get anchors
|
||||
json_item = cJSON_GetObjectItem(json_obj, "anchors");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (ANCHOR_NUM * 2 != array_size) {
|
||||
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d anchors from json file\n", ANCHOR_NUM);
|
||||
}
|
||||
for (int i = 0; i < ANCHOR_NUM * 2; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
anchor[i] = json_array_item->valuedouble;
|
||||
printf("%d: %f\n", i, anchor[i]);
|
||||
}
|
||||
// net_input_size
|
||||
json_item = cJSON_GetObjectItem(json_obj, "net_input_size");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (2 != array_size) {
|
||||
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d net_input_size from json file\n", 2);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
net_input_size[i] = json_array_item->valueint;
|
||||
printf("%d: %d\n", i, net_input_size[i]);
|
||||
}
|
||||
// net_output_shape
|
||||
json_item = cJSON_GetObjectItem(json_obj, "net_output_shape");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (3 != array_size) {
|
||||
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d net_output_shape from json file\n", 3);
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
net_output_shape[i] = json_array_item->valueint;
|
||||
printf("%d: %d\n", i, net_output_shape[i]);
|
||||
}
|
||||
// sensor_output_size
|
||||
json_item = cJSON_GetObjectItem(json_obj, "sensor_output_size");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (2 != array_size) {
|
||||
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d sensor_output_size from json file\n", 2);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
sensor_output_size[i] = json_array_item->valueint;
|
||||
printf("%d: %d\n", i, sensor_output_size[i]);
|
||||
}
|
||||
// kmodel_path
|
||||
json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
|
||||
memcpy(kmodel_path, json_item->valuestring, strlen(json_item->valuestring));
|
||||
printf("Got kmodel_path: %s\n", kmodel_path);
|
||||
// kmodel_size
|
||||
json_item = cJSON_GetObjectItem(json_obj, "kmodel_size");
|
||||
kmodel_size = json_item->valueint;
|
||||
printf("Got kmodel_size: %d\n", kmodel_size);
|
||||
// labels
|
||||
json_item = cJSON_GetObjectItem(json_obj, "labels");
|
||||
class_num = cJSON_GetArraySize(json_item);
|
||||
if (0 >= class_num) {
|
||||
printf("No labels!");
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d labels\n", class_num);
|
||||
}
|
||||
for (int i = 0; i < class_num; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
memcpy(labels[i], json_array_item->valuestring, strlen(json_array_item->valuestring));
|
||||
printf("%d: %s\n", i, labels[i]);
|
||||
}
|
||||
// obj_thresh
|
||||
json_item = cJSON_GetObjectItem(json_obj, "obj_thresh");
|
||||
array_size = cJSON_GetArraySize(json_item);
|
||||
if (class_num != array_size) {
|
||||
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", class_num, array_size);
|
||||
exit(-1);
|
||||
} else {
|
||||
printf("Got %d obj_thresh\n", array_size);
|
||||
}
|
||||
for (int i = 0; i < array_size; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
obj_thresh[i] = json_array_item->valuedouble;
|
||||
printf("%d: %f\n", i, obj_thresh[i]);
|
||||
}
|
||||
// nms_thresh
|
||||
json_item = cJSON_GetObjectItem(json_obj, "nms_thresh");
|
||||
nms_thresh = json_item->valuedouble;
|
||||
printf("Got nms_thresh: %f\n", nms_thresh);
|
||||
|
||||
cJSON_Delete(json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
void instrusion_detect()
|
||||
{
|
||||
int ret = 0;
|
||||
int result = 0;
|
||||
int size = 0;
|
||||
param_parse();
|
||||
g_fd = open("/dev/ov2640", O_RDONLY);
|
||||
if (g_fd < 0) {
|
||||
printf("open ov2640 fail !!");
|
||||
return;
|
||||
}
|
||||
_ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]};
|
||||
ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso);
|
||||
showbuffer = (unsigned char *)rt_malloc_align(sensor_output_size[0] * sensor_output_size[1] * 2,64);
|
||||
if (NULL == showbuffer) {
|
||||
close(g_fd);
|
||||
printf("showbuffer apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
kpurgbbuffer = (unsigned char *)rt_malloc_align(net_input_size[0] * net_input_size[1] * 3,64);
|
||||
if (NULL == kpurgbbuffer) {
|
||||
close(g_fd);
|
||||
rt_free_align(showbuffer);
|
||||
printf("kpurgbbuffer apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
||||
if (NULL == model_data) {
|
||||
rt_free_align(showbuffer);
|
||||
rt_free_align(kpurgbbuffer);
|
||||
close(g_fd);
|
||||
printf("model_data apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
memset(model_data, 0, kmodel_size + 255);
|
||||
memset(showbuffer, 0, sensor_output_size[0] * sensor_output_size[1] * 2);
|
||||
memset(kpurgbbuffer, 127, net_input_size[0] * net_input_size[1] * 3);
|
||||
shoot_para_t.pdata = (unsigned int *)(showbuffer);
|
||||
shoot_para_t.length = (size_t)(sensor_output_size[0] * sensor_output_size[1] * 2);
|
||||
/*
|
||||
load memory
|
||||
*/
|
||||
kmodel_fd = open(kmodel_path, O_RDONLY);
|
||||
if (kmodel_fd < 0) {
|
||||
printf("open kmodel fail");
|
||||
close(g_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
return;
|
||||
} else {
|
||||
size = read(kmodel_fd, model_data, kmodel_size);
|
||||
if (size != kmodel_size) {
|
||||
printf("read kmodel error size %d\n", size);
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
return;
|
||||
|
||||
} else {
|
||||
printf("read kmodel success \n");
|
||||
}
|
||||
}
|
||||
unsigned char *model_data_align = (unsigned char *)(((unsigned int)model_data + 255) & (~255));
|
||||
dvp_set_ai_addr((uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0])),
|
||||
(uint32_t)(kpurgbbuffer + net_input_size[1] * (net_input_size[0] - sensor_output_size[0]) +
|
||||
net_input_size[0] * net_input_size[1]),
|
||||
(uint32_t)(kpurgbbuffer + net_input_size[0] * net_input_size[1] * 2 +
|
||||
net_input_size[1] * (net_input_size[0] - sensor_output_size[0])));
|
||||
if (kpu_load_kmodel(&instrusion_detect_task, model_data_align) != 0) {
|
||||
printf("\nmodel init error\n");
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
return;
|
||||
}
|
||||
instrusion_detect_rl.anchor_number = ANCHOR_NUM;
|
||||
instrusion_detect_rl.anchor = anchor;
|
||||
instrusion_detect_rl.threshold = malloc(class_num * sizeof(float));
|
||||
for (int idx = 0; idx < class_num; idx++) {
|
||||
instrusion_detect_rl.threshold[idx] = obj_thresh[idx];
|
||||
}
|
||||
instrusion_detect_rl.nms_value = nms_thresh;
|
||||
result = region_layer_init(&instrusion_detect_rl, net_output_shape[0], net_output_shape[1], net_output_shape[2],
|
||||
net_input_size[1], net_input_size[0]);
|
||||
printf("region_layer_init result %d \n\r", result);
|
||||
size_t stack_size = STACK_SIZE;
|
||||
pthread_attr_t attr; /* 线程属性 */
|
||||
struct sched_param prio; /* 线程优先级 */
|
||||
prio.sched_priority = 8; /* 优先级设置为 8 */
|
||||
pthread_attr_init(&attr); /* 先使用默认值初始化属性 */
|
||||
pthread_attr_setschedparam(&attr, &prio); /* 修改属性对应的优先级 */
|
||||
pthread_attr_setstacksize(&attr, stack_size);
|
||||
|
||||
/* 创建线程 1, 属性为 attr,入口函数是 thread_entry,入口函数参数是 1 */
|
||||
result = pthread_create(&instrusiontid, &attr, thread_instrusion_detect_entry, NULL);
|
||||
if (0 == result) {
|
||||
printf("thread_instrusion_detect_entry successfully!\n");
|
||||
} else {
|
||||
printf("thread_instrusion_detect_entry failed! error code is %d\n", result);
|
||||
close(g_fd);
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(instrusion_detect, instrusion detect task);
|
||||
#endif
|
||||
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
|
||||
extern void lcd_show_image(int x, int y, int wide, int height,const rt_uint8_t *buf);
|
||||
extern void lcd_draw_16_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
|
||||
|
||||
static void *thread_instrusion_detect_entry(void *parameter)
|
||||
{
|
||||
printf("thread_instrusion_detect_entry start!\n");
|
||||
int ret = 0;
|
||||
// sysctl_enable_irq();
|
||||
while (1) {
|
||||
// memset(showbuffer,0,320*240*2);
|
||||
g_ai_done_flag = 0;
|
||||
ret = ioctl(g_fd, IOCTRL_CAMERA_START_SHOT, &shoot_para_t);
|
||||
if (RT_ERROR == ret) {
|
||||
printf("ov2640 can't wait event flag");
|
||||
rt_free(showbuffer);
|
||||
close(g_fd);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
if (dmalock_sync_take(&dma_ch, 2000))
|
||||
{
|
||||
printf("Fail to take DMA channel");
|
||||
}
|
||||
kpu_run_kmodel(&instrusion_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
|
||||
while (!g_ai_done_flag)
|
||||
;
|
||||
dmalock_release(dma_ch);
|
||||
float *output;
|
||||
size_t output_size;
|
||||
kpu_get_output(&instrusion_detect_task, 0, (uint8_t **)&output, &output_size);
|
||||
instrusion_detect_rl.input = output;
|
||||
region_layer_run(&instrusion_detect_rl, &instrusion_detect_info);
|
||||
/* display result */
|
||||
for (int instrusion_cnt = 0; instrusion_cnt < instrusion_detect_info.obj_number; instrusion_cnt++)
|
||||
{
|
||||
draw_edge((uint32_t *)showbuffer, &instrusion_detect_info, instrusion_cnt, 0xF800,(uint16_t)sensor_output_size[1],(uint16_t)sensor_output_size[0]);
|
||||
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", instrusion_cnt, instrusion_detect_info.obj[instrusion_cnt].x1,
|
||||
instrusion_detect_info.obj[instrusion_cnt].y1, instrusion_detect_info.obj[instrusion_cnt].x2,
|
||||
instrusion_detect_info.obj[instrusion_cnt].y2, labels[instrusion_detect_info.obj[instrusion_cnt].class_id],
|
||||
instrusion_detect_info.obj[instrusion_cnt].prob);
|
||||
}
|
||||
#ifdef BSP_USING_LCD
|
||||
//lcd_show_image(0, 0,(uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0],(unsigned int *)showbuffer);
|
||||
lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (uint32_t *)showbuffer);
|
||||
#endif
|
||||
if (0 != instrusion_detect_info.obj_number) {
|
||||
printf("\n");
|
||||
}
|
||||
usleep(1);
|
||||
if (1 == if_exit) {
|
||||
if_exit = 0;
|
||||
printf("thread_instrusion_detect_entry exit");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void instrusion_detect_delete()
|
||||
{
|
||||
if (showbuffer != NULL) {
|
||||
int ret = 0;
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
printf("instrusion detect task cancel!!! ret %d ", ret);
|
||||
if_exit = 1;
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(instrusion_detect_delete, instrusion detect task delete);
|
||||
#endif
|
||||
|
||||
void kmodel_load(unsigned char *model_data)
|
||||
{
|
||||
int kmodel_fd = 0;
|
||||
int size = 0;
|
||||
kmodel_fd = open(kmodel_path, O_RDONLY);
|
||||
|
||||
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
||||
if (NULL == model_data) {
|
||||
printf("model_data apply memory fail !!");
|
||||
return;
|
||||
}
|
||||
memset(model_data, 0, kmodel_size + 255);
|
||||
|
||||
if (kmodel_fd >= 0) {
|
||||
size = read(kmodel_fd, model_data, kmodel_size);
|
||||
if (size != kmodel_size) {
|
||||
printf("read kmodel error size %d\n", size);
|
||||
|
||||
} else {
|
||||
printf("read kmodel success");
|
||||
}
|
||||
} else {
|
||||
free(model_data);
|
||||
printf("open kmodel fail");
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(kmodel_load, kmodel load memory);
|
||||
#endif
|
|
@ -0,0 +1,16 @@
|
|||
config K210_DETECT_ENTRY
|
||||
bool "enable apps/k210 detect entry"
|
||||
depends on BOARD_K210_EVB
|
||||
depends on DRV_USING_OV2640
|
||||
depends on USING_KPU_PROCESSING
|
||||
depends on USING_YOLOV2
|
||||
depends on USING_YOLOV2_JSONPARSER
|
||||
depends on USING_K210_DETECT
|
||||
select LIB_USING_CJSON
|
||||
default n
|
||||
|
||||
config K210_DETECT_CONFIGJSON
|
||||
string "k210 detect config path"
|
||||
default "/kmodel/face.json"
|
||||
---help---
|
||||
k210 detect task config json path
|
|
@ -4,6 +4,6 @@ cwd = GetCurrentDir()
|
|||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Applications', src, depend = ['INSTRUSION_DETECT'], LOCAL_CPPPATH = CPPPATH)
|
||||
group = DefineGroup('Applications', src, depend = ['USING_K210_DETECT'], LOCAL_CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
|
@ -24,7 +24,7 @@
|
|||
6.718375,
|
||||
9.01025
|
||||
],
|
||||
"kmodel_path": "/kmodel/detect.kmodel",
|
||||
"kmodel_path": "/kmodel/face.kmodel",
|
||||
"kmodel_size": 388776,
|
||||
"obj_thresh": [
|
||||
0.7
|
|
@ -24,7 +24,7 @@
|
|||
2.049,
|
||||
4.6711
|
||||
],
|
||||
"kmodel_path": "/kmodel/human.kmodel",
|
||||
"kmodel_path": "/kmodel/instrusion.kmodel",
|
||||
"kmodel_size": 2713236,
|
||||
"obj_thresh": [
|
||||
0.7
|
|
@ -0,0 +1,9 @@
|
|||
#ifdef USING_K210_DETECT
|
||||
#include "k210_detect.h"
|
||||
#endif
|
||||
#include <transform.h>
|
||||
|
||||
static void detect_app() { k210_detect(K210_DETECT_CONFIGJSON); }
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(detect_app, detect app);
|
||||
#endif
|
|
@ -4,4 +4,5 @@ menuconfig USING_KPU_PROCESSING
|
|||
if USING_KPU_PROCESSING
|
||||
source "$APP_DIR/Framework/knowing/kpu/yolov2/Kconfig"
|
||||
source "$APP_DIR/Framework/knowing/kpu/yolov2_json/Kconfig"
|
||||
source "$APP_DIR/Framework/knowing/kpu/k210_detect_procedure/Kconfig"
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
menuconfig USING_K210_DETECT
|
||||
bool "k210 yolov2 detect procedure"
|
||||
depends on USING_KPU_PROCESSING
|
||||
default n
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
src = Glob('*.c')
|
||||
|
||||
group = DefineGroup('k210_detect_procedure', src, depend = ['USING_YOLOV2', 'USING_YOLOV2_JSONPARSER', 'USING_KPU_PROCESSING'], CPPPATH = [cwd])
|
||||
|
||||
Return('group')
|
|
@ -1,4 +1,4 @@
|
|||
#include <transform.h>
|
||||
#include "k210_detect.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#ifdef USING_YOLOV2_JSONPARSER
|
||||
|
@ -6,13 +6,12 @@
|
|||
#endif
|
||||
#include "region_layer.h"
|
||||
#define STACK_SIZE (128 * 1024)
|
||||
#define JSON_FILE_PATH "/kmodel/detect.json"
|
||||
|
||||
static dmac_channel_number_t dma_ch = DMAC_CHANNEL_MAX;
|
||||
|
||||
#define THREAD_PRIORITY_FACE_D (11)
|
||||
static pthread_t facetid = 0;
|
||||
static void *thread_face_detcet_entry(void *parameter);
|
||||
#define THREAD_PRIORITY_D (11)
|
||||
static pthread_t tid = 0;
|
||||
static void *thread_detect_entry(void *parameter);
|
||||
static int g_fd = 0;
|
||||
static int kmodel_fd = 0;
|
||||
static int if_exit = 0;
|
||||
|
@ -23,19 +22,19 @@ static _ioctl_shoot_para shoot_para_t = {0};
|
|||
unsigned char *model_data = NULL; // kpu data load memory
|
||||
unsigned char *model_data_align = NULL;
|
||||
|
||||
kpu_model_context_t face_detect_task;
|
||||
static region_layer_t face_detect_rl;
|
||||
static obj_info_t face_detect_info;
|
||||
kpu_model_context_t detect_task;
|
||||
static region_layer_t detect_rl;
|
||||
static obj_info_t detect_info;
|
||||
volatile uint32_t g_ai_done_flag;
|
||||
|
||||
static void ai_done(void *ctx) { g_ai_done_flag = 1; }
|
||||
|
||||
void face_detect()
|
||||
void k210_detect(char *json_file_path)
|
||||
{
|
||||
int ret = 0;
|
||||
int result = 0;
|
||||
int size = 0;
|
||||
yolov2_params_t detect_params = param_parse(JSON_FILE_PATH);
|
||||
yolov2_params_t detect_params = param_parse(json_file_path);
|
||||
g_fd = open("/dev/ov2640", O_RDONLY);
|
||||
if (g_fd < 0) {
|
||||
printf("open ov2640 fail !!");
|
||||
|
@ -73,6 +72,7 @@ void face_detect()
|
|||
/*
|
||||
load memory
|
||||
*/
|
||||
printf("%s\n", detect_params.kmodel_path);
|
||||
kmodel_fd = open(detect_params.kmodel_path, O_RDONLY);
|
||||
if (kmodel_fd < 0) {
|
||||
printf("open kmodel fail");
|
||||
|
@ -100,7 +100,7 @@ void face_detect()
|
|||
dvp_set_ai_addr((uint32_t)kpurgbbuffer,
|
||||
(uint32_t)(kpurgbbuffer + detect_params.net_input_size[0] * detect_params.net_input_size[1]),
|
||||
(uint32_t)(kpurgbbuffer + detect_params.net_input_size[0] * detect_params.net_input_size[1] * 2));
|
||||
if (kpu_load_kmodel(&face_detect_task, model_data_align) != 0) {
|
||||
if (kpu_load_kmodel(&detect_task, model_data_align) != 0) {
|
||||
printf("\nmodel init error\n");
|
||||
close(g_fd);
|
||||
close(kmodel_fd);
|
||||
|
@ -109,15 +109,15 @@ void face_detect()
|
|||
free(model_data);
|
||||
return;
|
||||
}
|
||||
face_detect_rl.anchor_number = ANCHOR_NUM;
|
||||
face_detect_rl.anchor = detect_params.anchor;
|
||||
face_detect_rl.threshold = malloc(detect_params.class_num * sizeof(float));
|
||||
detect_rl.anchor_number = ANCHOR_NUM;
|
||||
detect_rl.anchor = detect_params.anchor;
|
||||
detect_rl.threshold = malloc(detect_params.class_num * sizeof(float));
|
||||
for (int idx = 0; idx < detect_params.class_num; idx++) {
|
||||
face_detect_rl.threshold[idx] = detect_params.obj_thresh[idx];
|
||||
detect_rl.threshold[idx] = detect_params.obj_thresh[idx];
|
||||
}
|
||||
face_detect_rl.nms_value = detect_params.nms_thresh;
|
||||
detect_rl.nms_value = detect_params.nms_thresh;
|
||||
result =
|
||||
region_layer_init(&face_detect_rl, detect_params.net_output_shape[0], detect_params.net_output_shape[1],
|
||||
region_layer_init(&detect_rl, detect_params.net_output_shape[0], detect_params.net_output_shape[1],
|
||||
detect_params.net_output_shape[2], detect_params.net_input_size[1], detect_params.net_input_size[0]);
|
||||
printf("region_layer_init result %d \n\r", result);
|
||||
size_t stack_size = STACK_SIZE;
|
||||
|
@ -129,23 +129,23 @@ void face_detect()
|
|||
pthread_attr_setstacksize(&attr, stack_size);
|
||||
|
||||
/* 创建线程 1, 属性为 attr,入口函数是 thread_entry,入口函数参数是 1 */
|
||||
result = pthread_create(&facetid, &attr, thread_face_detcet_entry, &detect_params);
|
||||
result = pthread_create(&tid, &attr, thread_detect_entry, &detect_params);
|
||||
if (0 == result) {
|
||||
printf("thread_face_detcet_entry successfully!\n");
|
||||
printf("thread_detect_entry successfully!\n");
|
||||
} else {
|
||||
printf("thread_face_detcet_entry failed! error code is %d\n", result);
|
||||
printf("thread_detect_entry failed! error code is %d\n", result);
|
||||
close(g_fd);
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(face_detect, face detect task);
|
||||
#endif
|
||||
// #ifdef __RT_THREAD_H__
|
||||
// MSH_CMD_EXPORT(detect, detect task);
|
||||
// #endif
|
||||
|
||||
static void *thread_face_detcet_entry(void *parameter)
|
||||
static void *thread_detect_entry(void *parameter)
|
||||
{
|
||||
yolov2_params_t detect_params = *(yolov2_params_t *)parameter;
|
||||
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr);
|
||||
printf("thread_face_detcet_entry start!\n");
|
||||
printf("thread_detect_entry start!\n");
|
||||
int ret = 0;
|
||||
// sysctl_enable_irq();
|
||||
while (1) {
|
||||
|
@ -162,24 +162,23 @@ static void *thread_face_detcet_entry(void *parameter)
|
|||
if (dmalock_sync_take(&dma_ch, 2000)) {
|
||||
printf("Fail to take DMA channel");
|
||||
}
|
||||
kpu_run_kmodel(&face_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
|
||||
kpu_run_kmodel(&detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
|
||||
while (!g_ai_done_flag)
|
||||
;
|
||||
dmalock_release(dma_ch);
|
||||
float *output;
|
||||
size_t output_size;
|
||||
kpu_get_output(&face_detect_task, 0, (uint8_t **)&output, &output_size);
|
||||
face_detect_rl.input = output;
|
||||
region_layer_run(&face_detect_rl, &face_detect_info);
|
||||
kpu_get_output(&detect_task, 0, (uint8_t **)&output, &output_size);
|
||||
detect_rl.input = output;
|
||||
region_layer_run(&detect_rl, &detect_info);
|
||||
/* display result */
|
||||
|
||||
for (int face_cnt = 0; face_cnt < face_detect_info.obj_number; face_cnt++) {
|
||||
draw_edge((uint32_t *)showbuffer, &face_detect_info, face_cnt, 0xF800,
|
||||
(uint16_t)detect_params.sensor_output_size[1], (uint16_t)detect_params.sensor_output_size[0]);
|
||||
// printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", face_cnt, face_detect_info.obj[face_cnt].x1,
|
||||
// face_detect_info.obj[face_cnt].y1, face_detect_info.obj[face_cnt].x2,
|
||||
// face_detect_info.obj[face_cnt].y2, detect_params.labels[face_detect_info.obj[face_cnt].class_id],
|
||||
// face_detect_info.obj[face_cnt].prob);
|
||||
for (int cnt = 0; cnt < detect_info.obj_number; cnt++) {
|
||||
draw_edge((uint32_t *)showbuffer, &detect_info, cnt, 0xF800, (uint16_t)detect_params.sensor_output_size[1],
|
||||
(uint16_t)detect_params.sensor_output_size[0]);
|
||||
printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", cnt, detect_info.obj[cnt].x1, detect_info.obj[cnt].y1,
|
||||
detect_info.obj[cnt].x2, detect_info.obj[cnt].y2, detect_params.labels[detect_info.obj[cnt].class_id],
|
||||
detect_info.obj[cnt].prob);
|
||||
}
|
||||
#ifdef BSP_USING_LCD
|
||||
lcd_draw_picture(0, 0, (uint16_t)detect_params.sensor_output_size[1], (uint16_t)detect_params.sensor_output_size[0],
|
||||
|
@ -190,13 +189,13 @@ static void *thread_face_detcet_entry(void *parameter)
|
|||
usleep(500);
|
||||
if (1 == if_exit) {
|
||||
if_exit = 0;
|
||||
printf("thread_face_detcet_entry exit");
|
||||
printf("thread_detect_entry exit");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void face_detect_delete()
|
||||
void detect_delete()
|
||||
{
|
||||
if (showbuffer != NULL) {
|
||||
int ret = 0;
|
||||
|
@ -205,13 +204,13 @@ void face_detect_delete()
|
|||
free(showbuffer);
|
||||
free(kpurgbbuffer);
|
||||
free(model_data);
|
||||
printf("face detect task cancel!!! ret %d ", ret);
|
||||
printf("detect task cancel!!! ret %d ", ret);
|
||||
if_exit = 1;
|
||||
}
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(face_detect_delete, face detect task delete);
|
||||
#endif
|
||||
// #ifdef __RT_THREAD_H__
|
||||
// MSH_CMD_EXPORT(detect_delete, detect task delete);
|
||||
// #endif
|
||||
|
||||
// void kmodel_load(unsigned char *model_data)
|
||||
// {
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _K210_DETECT_H_
|
||||
#define _K210_DETECT_H_
|
||||
|
||||
#include <transform.h>
|
||||
|
||||
void k210_detect(char *json_file_path);
|
||||
|
||||
#endif
|
|
@ -5,6 +5,6 @@ cwd = GetCurrentDir()
|
|||
|
||||
src = Glob('*.c')
|
||||
|
||||
group = DefineGroup('yolov2_json', src, depend = ['USING_YOLOV2_JSONPARSER', 'LIB_USING_CJSON'], CPPPATH = [cwd])
|
||||
group = DefineGroup('yolov2_json', src, depend = ['LIB_USING_CJSON'], CPPPATH = [cwd])
|
||||
|
||||
Return('group')
|
||||
|
|
|
@ -93,6 +93,7 @@ yolov2_params_t param_parse(char *json_file_path)
|
|||
}
|
||||
// kmodel_path
|
||||
json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
|
||||
memset(params_return.kmodel_path, 0, 127);
|
||||
memcpy(params_return.kmodel_path, json_item->valuestring, strlen(json_item->valuestring));
|
||||
printf("Got kmodel_path: %s\n", params_return.kmodel_path);
|
||||
// kmodel_size
|
||||
|
@ -110,6 +111,7 @@ yolov2_params_t param_parse(char *json_file_path)
|
|||
}
|
||||
for (int i = 0; i < params_return.class_num; i++) {
|
||||
json_array_item = cJSON_GetArrayItem(json_item, i);
|
||||
memset(params_return.labels[i], 0, 127);
|
||||
memcpy(params_return.labels[i], json_array_item->valuestring, strlen(json_array_item->valuestring));
|
||||
printf("%d: %s\n", i, params_return.labels[i]);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ CONFIG_BOARD_K210_EVB=y
|
|||
# RT-Thread Kernel
|
||||
#
|
||||
CONFIG_RT_NAME_MAX=8
|
||||
# CONFIG_RT_USING_BIG_ENDIAN is not set
|
||||
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
|
||||
CONFIG_RT_USING_SMP=y
|
||||
CONFIG_RT_CPUS_NR=2
|
||||
|
@ -26,6 +27,7 @@ CONFIG_RT_USING_HOOK=y
|
|||
CONFIG_RT_USING_IDLE_HOOK=y
|
||||
CONFIG_RT_IDLE_HOOK_LIST_SIZE=4
|
||||
CONFIG_IDLE_THREAD_STACK_SIZE=4096
|
||||
CONFIG_SYSTEM_THREAD_STACK_SIZE=4096
|
||||
# CONFIG_RT_USING_TIMER_SOFT is not set
|
||||
|
||||
#
|
||||
|
@ -33,6 +35,7 @@ CONFIG_IDLE_THREAD_STACK_SIZE=4096
|
|||
#
|
||||
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
|
||||
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
|
||||
# CONFIG_RT_USING_ASM_MEMCPY is not set
|
||||
CONFIG_RT_DEBUG=y
|
||||
CONFIG_RT_DEBUG_COLOR=y
|
||||
CONFIG_RT_DEBUG_INIT_CONFIG=y
|
||||
|
@ -79,6 +82,7 @@ CONFIG_RT_USING_DEVICE=y
|
|||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=128
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uarths"
|
||||
# CONFIG_RT_PRINTF_LONGLONG is not set
|
||||
CONFIG_RT_VER_NUM=0x40004
|
||||
CONFIG_ARCH_CPU_64BIT=y
|
||||
# CONFIG_RT_USING_CPU_FFS is not set
|
||||
|
@ -100,24 +104,25 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10
|
|||
# C++ features
|
||||
#
|
||||
CONFIG_RT_USING_CPLUSPLUS=y
|
||||
# CONFIG_RT_USING_CPLUSPLUS11 is not set
|
||||
|
||||
#
|
||||
# Command shell
|
||||
#
|
||||
CONFIG_RT_USING_FINSH=y
|
||||
CONFIG_RT_USING_MSH=y
|
||||
CONFIG_FINSH_USING_MSH=y
|
||||
CONFIG_FINSH_THREAD_NAME="tshell"
|
||||
CONFIG_FINSH_THREAD_PRIORITY=20
|
||||
CONFIG_FINSH_THREAD_STACK_SIZE=16384
|
||||
CONFIG_FINSH_USING_HISTORY=y
|
||||
CONFIG_FINSH_HISTORY_LINES=5
|
||||
CONFIG_FINSH_USING_SYMTAB=y
|
||||
CONFIG_FINSH_CMD_SIZE=80
|
||||
CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
|
||||
CONFIG_FINSH_USING_DESCRIPTION=y
|
||||
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
|
||||
CONFIG_FINSH_THREAD_PRIORITY=20
|
||||
CONFIG_FINSH_THREAD_STACK_SIZE=16384
|
||||
CONFIG_FINSH_CMD_SIZE=80
|
||||
# CONFIG_FINSH_USING_AUTH is not set
|
||||
CONFIG_FINSH_USING_MSH=y
|
||||
CONFIG_FINSH_USING_MSH_DEFAULT=y
|
||||
# CONFIG_FINSH_USING_MSH_ONLY is not set
|
||||
CONFIG_FINSH_ARG_MAX=10
|
||||
|
||||
#
|
||||
|
@ -151,6 +156,7 @@ CONFIG_RT_DFS_ELM_DRIVES=2
|
|||
CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=4096
|
||||
# CONFIG_RT_DFS_ELM_USE_ERASE is not set
|
||||
CONFIG_RT_DFS_ELM_REENTRANT=y
|
||||
CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000
|
||||
CONFIG_RT_USING_DFS_DEVFS=y
|
||||
# CONFIG_RT_USING_DFS_ROMFS is not set
|
||||
# CONFIG_RT_USING_DFS_RAMFS is not set
|
||||
|
@ -165,6 +171,8 @@ CONFIG_RT_USING_SYSTEM_WORKQUEUE=y
|
|||
CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048
|
||||
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
|
||||
CONFIG_RT_USING_SERIAL=y
|
||||
CONFIG_RT_USING_SERIAL_V1=y
|
||||
# CONFIG_RT_USING_SERIAL_V2 is not set
|
||||
CONFIG_RT_SERIAL_USING_DMA=y
|
||||
CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||
# CONFIG_RT_USING_CAN is not set
|
||||
|
@ -246,8 +254,9 @@ CONFIG_RT_USING_POSIX=y
|
|||
# CONFIG_RT_USING_POSIX_TERMIOS is not set
|
||||
# CONFIG_RT_USING_POSIX_GETLINE is not set
|
||||
# CONFIG_RT_USING_POSIX_AIO is not set
|
||||
CONFIG_RT_LIBC_USING_TIME=y
|
||||
# CONFIG_RT_USING_MODULE is not set
|
||||
CONFIG_RT_LIBC_FIXED_TIMEZONE=8
|
||||
CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
|
||||
#
|
||||
# Network
|
||||
|
@ -284,6 +293,7 @@ CONFIG_NETDEV_IPV6=0
|
|||
CONFIG_RT_USING_LWIP=y
|
||||
# CONFIG_RT_USING_LWIP141 is not set
|
||||
CONFIG_RT_USING_LWIP202=y
|
||||
# CONFIG_RT_USING_LWIP203 is not set
|
||||
# CONFIG_RT_USING_LWIP212 is not set
|
||||
# CONFIG_RT_USING_LWIP_IPV6 is not set
|
||||
CONFIG_RT_LWIP_MEM_ALIGNMENT=8
|
||||
|
@ -353,6 +363,7 @@ CONFIG_RT_LWIP_USING_PING=y
|
|||
# CONFIG_RT_USING_RYM is not set
|
||||
# CONFIG_RT_USING_ULOG is not set
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
|
||||
#
|
||||
|
@ -415,9 +426,6 @@ CONFIG_BSP_DVP_CMOS_PWDN_PIN=44
|
|||
CONFIG_BSP_DVP_CMOS_XCLK_PIN=46
|
||||
CONFIG_BSP_DVP_CMOS_PCLK_PIN=47
|
||||
CONFIG_BSP_DVP_CMOS_HREF_PIN=45
|
||||
CONFIG_RW007_SPIDEV_NAME="spi11"
|
||||
CONFIG_RW007_INT_BUSY_PIN=7
|
||||
CONFIG_RW007_RST_PIN=6
|
||||
|
||||
#
|
||||
# Kendryte SDK Config
|
||||
|
@ -427,10 +435,7 @@ CONFIG_PKG_KENDRYTE_SDK_VERNUM=0x0055
|
|||
#
|
||||
# More Drivers
|
||||
#
|
||||
CONFIG_PKG_USING_RW007=y
|
||||
CONFIG_RW007_NOT_USE_EXAMPLE_DRIVERS=y
|
||||
# CONFIG_RW007_USING_STM32_DRIVERS is not set
|
||||
CONFIG_RW007_SPI_MAX_HZ=20000000
|
||||
# CONFIG_PKG_USING_RW007 is not set
|
||||
CONFIG_DRV_USING_OV2640=y
|
||||
|
||||
#
|
||||
|
@ -446,6 +451,11 @@ CONFIG_DRV_USING_OV2640=y
|
|||
#
|
||||
CONFIG_MAIN_KTASK_STACK_SIZE=1024
|
||||
|
||||
#
|
||||
# ota app
|
||||
#
|
||||
# CONFIG_APPLICATION_OTA is not set
|
||||
|
||||
#
|
||||
# test app
|
||||
#
|
||||
|
@ -464,10 +474,9 @@ CONFIG_MAIN_KTASK_STACK_SIZE=1024
|
|||
# knowing app
|
||||
#
|
||||
CONFIG_APPLICATION_KNOWING=y
|
||||
CONFIG_APP_MNIST=y
|
||||
CONFIG_FACE_DETECT=y
|
||||
# CONFIG_INSTRUSION_DETECT is not set
|
||||
# CONFIG_HELMET_DETECT is not set
|
||||
# CONFIG_APP_MNIST is not set
|
||||
CONFIG_K210_DETECT_ENTRY=y
|
||||
CONFIG_K210_DETECT_CONFIGJSON="/kmodel/face.json"
|
||||
# CONFIG_IRIS_ML_DEMO is not set
|
||||
# CONFIG_K210_FFT_TEST is not set
|
||||
# CONFIG_USING_IMAGE_PROCESSING_APP is not set
|
||||
|
@ -507,12 +516,14 @@ CONFIG_USING_TENSORFLOWLITEMICRO=y
|
|||
CONFIG_USING_TENSORFLOWLITEMICRO_NORMAL=y
|
||||
# CONFIG_USING_TENSORFLOWLITEMICRO_CMSISNN is not set
|
||||
# CONFIG_USING_TENSORFLOWLITEMICRO_DEMOAPP is not set
|
||||
CONFIG_USING_KPU_PROCESSING=y
|
||||
CONFIG_USING_YOLOV2=y
|
||||
CONFIG_USING_YOLOV2_JSONPARSER=y
|
||||
# CONFIG_USING_KNOWING_FILTER is not set
|
||||
# CONFIG_USING_OTA_MODEL is not set
|
||||
# CONFIG_USING_IMAGE_PROCESSING is not set
|
||||
# CONFIG_USING_CMSIS_5 is not set
|
||||
CONFIG_USING_KPU_PROCESSING=y
|
||||
CONFIG_USING_YOLOV2=y
|
||||
CONFIG_USING_YOLOV2_JSONPARSER=y
|
||||
CONFIG_USING_K210_DETECT=y
|
||||
# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set
|
||||
|
||||
#
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define RT_USING_IDLE_HOOK
|
||||
#define RT_IDLE_HOOK_LIST_SIZE 4
|
||||
#define IDLE_THREAD_STACK_SIZE 4096
|
||||
#define SYSTEM_THREAD_STACK_SIZE 4096
|
||||
|
||||
/* kservice optimization */
|
||||
|
||||
|
@ -75,16 +76,17 @@
|
|||
/* Command shell */
|
||||
|
||||
#define RT_USING_FINSH
|
||||
#define RT_USING_MSH
|
||||
#define FINSH_USING_MSH
|
||||
#define FINSH_THREAD_NAME "tshell"
|
||||
#define FINSH_THREAD_PRIORITY 20
|
||||
#define FINSH_THREAD_STACK_SIZE 16384
|
||||
#define FINSH_USING_HISTORY
|
||||
#define FINSH_HISTORY_LINES 5
|
||||
#define FINSH_USING_SYMTAB
|
||||
#define FINSH_USING_DESCRIPTION
|
||||
#define FINSH_THREAD_PRIORITY 20
|
||||
#define FINSH_THREAD_STACK_SIZE 16384
|
||||
#define FINSH_CMD_SIZE 80
|
||||
#define FINSH_USING_MSH
|
||||
#define FINSH_USING_MSH_DEFAULT
|
||||
#define MSH_USING_BUILT_IN_COMMANDS
|
||||
#define FINSH_USING_DESCRIPTION
|
||||
#define FINSH_ARG_MAX 10
|
||||
|
||||
/* Device virtual file system */
|
||||
|
@ -108,6 +110,7 @@
|
|||
#define RT_DFS_ELM_DRIVES 2
|
||||
#define RT_DFS_ELM_MAX_SECTOR_SIZE 4096
|
||||
#define RT_DFS_ELM_REENTRANT
|
||||
#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
|
||||
#define RT_USING_DFS_DEVFS
|
||||
|
||||
/* Device Drivers */
|
||||
|
@ -118,6 +121,7 @@
|
|||
#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
|
||||
#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
|
||||
#define RT_USING_SERIAL
|
||||
#define RT_USING_SERIAL_V1
|
||||
#define RT_SERIAL_USING_DMA
|
||||
#define RT_SERIAL_RB_BUFSZ 64
|
||||
#define RT_USING_PIN
|
||||
|
@ -164,7 +168,8 @@
|
|||
#define RT_USING_PTHREADS
|
||||
#define PTHREAD_NUM_MAX 8
|
||||
#define RT_USING_POSIX
|
||||
#define RT_LIBC_FIXED_TIMEZONE 8
|
||||
#define RT_LIBC_USING_TIME
|
||||
#define RT_LIBC_DEFAULT_TIMEZONE 8
|
||||
|
||||
/* Network */
|
||||
|
||||
|
@ -286,9 +291,6 @@
|
|||
#define BSP_DVP_CMOS_XCLK_PIN 46
|
||||
#define BSP_DVP_CMOS_PCLK_PIN 47
|
||||
#define BSP_DVP_CMOS_HREF_PIN 45
|
||||
#define RW007_SPIDEV_NAME "spi11"
|
||||
#define RW007_INT_BUSY_PIN 7
|
||||
#define RW007_RST_PIN 6
|
||||
|
||||
/* Kendryte SDK Config */
|
||||
|
||||
|
@ -296,9 +298,6 @@
|
|||
|
||||
/* More Drivers */
|
||||
|
||||
#define PKG_USING_RW007
|
||||
#define RW007_NOT_USE_EXAMPLE_DRIVERS
|
||||
#define RW007_SPI_MAX_HZ 20000000
|
||||
#define DRV_USING_OV2640
|
||||
|
||||
/* APP_Framework */
|
||||
|
@ -309,6 +308,9 @@
|
|||
|
||||
#define MAIN_KTASK_STACK_SIZE 1024
|
||||
|
||||
/* ota app */
|
||||
|
||||
|
||||
/* test app */
|
||||
|
||||
|
||||
|
@ -320,8 +322,8 @@
|
|||
/* knowing app */
|
||||
|
||||
#define APPLICATION_KNOWING
|
||||
#define APP_MNIST
|
||||
#define FACE_DETECT
|
||||
#define K210_DETECT_ENTRY
|
||||
#define K210_DETECT_CONFIGJSON "/kmodel/face.json"
|
||||
|
||||
/* sensor app */
|
||||
|
||||
|
@ -345,6 +347,7 @@
|
|||
#define USING_KPU_PROCESSING
|
||||
#define USING_YOLOV2
|
||||
#define USING_YOLOV2_JSONPARSER
|
||||
#define USING_K210_DETECT
|
||||
|
||||
/* Security */
|
||||
|
||||
|
|
Loading…
Reference in New Issue