forked from xuos/xiuos
fix(knowing framework/yolov2 region layer): free region layer thresholds
This commit is contained in:
parent
c782dd26c4
commit
62df72af5b
|
@ -19,7 +19,8 @@ void simple_CSV_read()
|
||||||
fin = open(CSV_PATH, O_RDONLY);
|
fin = open(CSV_PATH, O_RDONLY);
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
printf("Error open file %s", CSV_PATH);
|
printf("Error open file %s", CSV_PATH);
|
||||||
exit(-1);
|
// exit(-1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
read(fin, buffer, sizeof(buffer));
|
read(fin, buffer, sizeof(buffer));
|
||||||
close(fin);
|
close(fin);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
"kmodel_size": 2714044,
|
"kmodel_size": 2714044,
|
||||||
"obj_thresh": [
|
"obj_thresh": [
|
||||||
0.7,
|
0.7,
|
||||||
0.9
|
0.99
|
||||||
],
|
],
|
||||||
"labels": [
|
"labels": [
|
||||||
"head",
|
"head",
|
||||||
|
|
|
@ -7,10 +7,9 @@ static void detect_app(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (2 != argc) {
|
if (2 != argc) {
|
||||||
printf("Usage: detect_app <ABSOLUTE_CONFIG_JSON_PATH>");
|
printf("Usage: detect_app <ABSOLUTE_CONFIG_JSON_PATH>");
|
||||||
exit(-1);
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
k210_detect(argv[1]);
|
k210_detect(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ void k210_detect(char *json_file_path)
|
||||||
char kmodel_path[127] = {};
|
char kmodel_path[127] = {};
|
||||||
|
|
||||||
yolov2_params_t detect_params = param_parse(json_file_path);
|
yolov2_params_t detect_params = param_parse(json_file_path);
|
||||||
|
if (!detect_params.is_valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_fd = open("/dev/ov2640", O_RDONLY);
|
g_fd = open("/dev/ov2640", O_RDONLY);
|
||||||
if (g_fd < 0) {
|
if (g_fd < 0) {
|
||||||
printf("open ov2640 fail !!");
|
printf("open ov2640 fail !!");
|
||||||
|
@ -128,17 +132,19 @@ void k210_detect(char *json_file_path)
|
||||||
free(model_data);
|
free(model_data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
detect_rl.anchor_number = ANCHOR_NUM;
|
detect_rl.anchor_number = ANCHOR_NUM;
|
||||||
detect_rl.anchor = detect_params.anchor;
|
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++) {
|
|
||||||
detect_rl.threshold[idx] = detect_params.obj_thresh[idx];
|
|
||||||
}
|
|
||||||
detect_rl.nms_value = detect_params.nms_thresh;
|
detect_rl.nms_value = detect_params.nms_thresh;
|
||||||
|
detect_rl.classes = detect_params.class_num;
|
||||||
result =
|
result =
|
||||||
region_layer_init(&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]);
|
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);
|
printf("region_layer_init result %d \n\r", result);
|
||||||
|
for (int idx = 0; idx < detect_params.class_num; idx++) {
|
||||||
|
detect_rl.threshold[idx] = detect_params.obj_thresh[idx];
|
||||||
|
}
|
||||||
|
|
||||||
size_t stack_size = STACK_SIZE;
|
size_t stack_size = STACK_SIZE;
|
||||||
pthread_attr_t attr; /* 线程属性 */
|
pthread_attr_t attr; /* 线程属性 */
|
||||||
struct sched_param prio; /* 线程优先级 */
|
struct sched_param prio; /* 线程优先级 */
|
||||||
|
@ -200,8 +206,8 @@ static void *thread_detect_entry(void *parameter)
|
||||||
detect_info.obj[cnt].prob);
|
detect_info.obj[cnt].prob);
|
||||||
}
|
}
|
||||||
#ifdef BSP_USING_LCD
|
#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],
|
lcd_draw_picture(0, 0, (uint16_t)detect_params.sensor_output_size[1] - 1,
|
||||||
(uint32_t *)showbuffer);
|
(uint16_t)detect_params.sensor_output_size[0] - 1, (uint32_t *)showbuffer);
|
||||||
// lcd_show_image(0, 0, (uint16_t)detect_params.sensor_output_size[1], (uint16_t)detect_params.sensor_output_size[0],
|
// lcd_show_image(0, 0, (uint16_t)detect_params.sensor_output_size[1], (uint16_t)detect_params.sensor_output_size[0],
|
||||||
// (unsigned int *)showbuffer);
|
// (unsigned int *)showbuffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,12 +58,14 @@ int region_layer_init(region_layer_t *rl, int width, int height, int channels, i
|
||||||
goto malloc_error;
|
goto malloc_error;
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < rl->boxes_number; i++) rl->probs[i] = &(rl->probs_buf[i * (rl->classes + 1)]);
|
for (uint32_t i = 0; i < rl->boxes_number; i++) rl->probs[i] = &(rl->probs_buf[i * (rl->classes + 1)]);
|
||||||
|
rl->threshold = malloc(rl->classes * sizeof(float));
|
||||||
return 0;
|
return 0;
|
||||||
malloc_error:
|
malloc_error:
|
||||||
free(rl->output);
|
free(rl->output);
|
||||||
free(rl->boxes);
|
free(rl->boxes);
|
||||||
free(rl->probs_buf);
|
free(rl->probs_buf);
|
||||||
free(rl->probs);
|
free(rl->probs);
|
||||||
|
free(rl->threshold);
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +75,7 @@ void region_layer_deinit(region_layer_t *rl)
|
||||||
free(rl->boxes);
|
free(rl->boxes);
|
||||||
free(rl->probs_buf);
|
free(rl->probs_buf);
|
||||||
free(rl->probs);
|
free(rl->probs);
|
||||||
|
free(rl->threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float sigmoid(float x) { return 1.f / (1.f + expf(-x)); }
|
static inline float sigmoid(float x) { return 1.f / (1.f + expf(-x)); }
|
||||||
|
|
|
@ -7,14 +7,16 @@
|
||||||
yolov2_params_t param_parse(char *json_file_path)
|
yolov2_params_t param_parse(char *json_file_path)
|
||||||
{
|
{
|
||||||
yolov2_params_t params_return;
|
yolov2_params_t params_return;
|
||||||
|
params_return.is_valid = 1;
|
||||||
int fin;
|
int fin;
|
||||||
char buffer[JSON_BUFFER_SIZE] = "";
|
char buffer[JSON_BUFFER_SIZE] = "";
|
||||||
// char *buffer;
|
// char *buffer;
|
||||||
// if (NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
|
// if ((yolov2_params_t *)NULL != (buffer = (char*)malloc(JSON_BUFFER_SIZE * sizeof(char)))) {
|
||||||
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
|
// memset(buffer, 0, JSON_BUFFER_SIZE * sizeof(char));
|
||||||
// } else {
|
// } else {
|
||||||
// printf("Json buffer malloc failed!");
|
// printf("Json buffer malloc failed!");
|
||||||
// exit(-1);
|
// params_return.is_valid = 0;
|
||||||
|
// return params_return;
|
||||||
// }
|
// }
|
||||||
int array_size;
|
int array_size;
|
||||||
cJSON *json_obj;
|
cJSON *json_obj;
|
||||||
|
@ -24,8 +26,9 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
fin = open(json_file_path, O_RDONLY);
|
fin = open(json_file_path, O_RDONLY);
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
printf("Error open file %s\n", json_file_path);
|
printf("Error open file %s\n", json_file_path);
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
} else{
|
return params_return;
|
||||||
|
} else {
|
||||||
printf("Reading config from: %s\n", json_file_path);
|
printf("Reading config from: %s\n", json_file_path);
|
||||||
}
|
}
|
||||||
read(fin, buffer, sizeof(buffer));
|
read(fin, buffer, sizeof(buffer));
|
||||||
|
@ -42,7 +45,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
array_size = cJSON_GetArraySize(json_item);
|
array_size = cJSON_GetArraySize(json_item);
|
||||||
if (ANCHOR_NUM * 2 != array_size) {
|
if (ANCHOR_NUM * 2 != array_size) {
|
||||||
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
|
printf("Expect anchor size: %d, got %d in json file", ANCHOR_NUM * 2, array_size);
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
} else {
|
} else {
|
||||||
printf("Got %d anchors from json file\n", ANCHOR_NUM);
|
printf("Got %d anchors from json file\n", ANCHOR_NUM);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +60,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
array_size = cJSON_GetArraySize(json_item);
|
array_size = cJSON_GetArraySize(json_item);
|
||||||
if (2 != array_size) {
|
if (2 != array_size) {
|
||||||
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
|
printf("Expect net_input_size: %d, got %d in json file", 2, array_size);
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
} else {
|
} else {
|
||||||
printf("Got %d net_input_size from json file\n", 2);
|
printf("Got %d net_input_size from json file\n", 2);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +75,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
array_size = cJSON_GetArraySize(json_item);
|
array_size = cJSON_GetArraySize(json_item);
|
||||||
if (3 != array_size) {
|
if (3 != array_size) {
|
||||||
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
|
printf("Expect net_output_shape: %d, got %d in json file", 3, array_size);
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
} else {
|
} else {
|
||||||
printf("Got %d net_output_shape from json file\n", 3);
|
printf("Got %d net_output_shape from json file\n", 3);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +90,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
array_size = cJSON_GetArraySize(json_item);
|
array_size = cJSON_GetArraySize(json_item);
|
||||||
if (2 != array_size) {
|
if (2 != array_size) {
|
||||||
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
|
printf("Expect sensor_output_size: %d, got %d in json file", 2, array_size);
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
} else {
|
} else {
|
||||||
printf("Got %d sensor_output_size from json file\n", 2);
|
printf("Got %d sensor_output_size from json file\n", 2);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +103,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
// check sensor output width and net input width
|
// check sensor output width and net input width
|
||||||
if (params_return.sensor_output_size[1] != params_return.net_input_size[1]) {
|
if (params_return.sensor_output_size[1] != params_return.net_input_size[1]) {
|
||||||
printf("Net input width must match sensor output width!\n");
|
printf("Net input width must match sensor output width!\n");
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
}
|
}
|
||||||
// // kmodel_path
|
// // kmodel_path
|
||||||
// json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
|
// json_item = cJSON_GetObjectItem(json_obj, "kmodel_path");
|
||||||
|
@ -112,7 +120,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
params_return.class_num = cJSON_GetArraySize(json_item);
|
params_return.class_num = cJSON_GetArraySize(json_item);
|
||||||
if (0 >= params_return.class_num) {
|
if (0 >= params_return.class_num) {
|
||||||
printf("No labels!");
|
printf("No labels!");
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
} else {
|
} else {
|
||||||
printf("Got %d labels\n", params_return.class_num);
|
printf("Got %d labels\n", params_return.class_num);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +137,8 @@ yolov2_params_t param_parse(char *json_file_path)
|
||||||
if (params_return.class_num != array_size) {
|
if (params_return.class_num != array_size) {
|
||||||
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", params_return.class_num,
|
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", params_return.class_num,
|
||||||
array_size);
|
array_size);
|
||||||
exit(-1);
|
params_return.is_valid = 0;
|
||||||
|
return params_return;
|
||||||
} else {
|
} else {
|
||||||
printf("Got %d obj_thresh\n", array_size);
|
printf("Got %d obj_thresh\n", array_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ typedef struct {
|
||||||
float nms_thresh;
|
float nms_thresh;
|
||||||
char labels[20][32];
|
char labels[20][32];
|
||||||
int class_num;
|
int class_num;
|
||||||
|
int is_valid;
|
||||||
} yolov2_params_t;
|
} yolov2_params_t;
|
||||||
|
|
||||||
yolov2_params_t param_parse(char *json_file_path);
|
yolov2_params_t param_parse(char *json_file_path);
|
||||||
|
|
Loading…
Reference in New Issue