ansjer_ai_cfg.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "ansjer_ai_cfg.h"
  2. #include <iostream>
  3. #include <string.h>
  4. char* load_file(char const* path)
  5. {
  6. char* buffer = 0;
  7. long length;
  8. FILE * f = fopen (path, "rb"); //was "rb"
  9. if (f)
  10. {
  11. fseek (f, 0, SEEK_END);
  12. length = ftell (f);
  13. fseek (f, 0, SEEK_SET);
  14. buffer = (char*)malloc ((length+1)*sizeof(char));
  15. if (buffer)
  16. {
  17. fread (buffer, sizeof(char), length, f);
  18. }
  19. fclose (f);
  20. }
  21. buffer[length] = '\0';
  22. // for (int i = 0; i < length; i++) {
  23. // printf("buffer[%d] == %c\n", i, buffer[i]);
  24. // }
  25. //printf("buffer = %s\n", buffer);
  26. return buffer;
  27. }
  28. int read_Asj_Ai_Json (void *hdl, char *filename){
  29. char *json_file_str = load_file(filename);
  30. printf("%s",json_file_str);
  31. Asj_Ai_Cfg_t *ai_config = (Asj_Ai_Cfg_t *)hdl;
  32. json_t mem[64];
  33. json_t const* json = json_create(json_file_str, mem, sizeof mem / sizeof *mem );
  34. json_t const* property = json_getProperty(json, "property");
  35. json_t const* model_type = json_getProperty(property, "model_type");
  36. ai_config->property.model_type = json_getValue(model_type);
  37. json_t const* ezb_model_path = json_getProperty(property, "ezb_model_path");
  38. strcpy(ai_config->property.ezbStr, json_getValue(ezb_model_path ));
  39. json_t const* ezb_bin_path = json_getProperty(property, "ezb_bin_path");
  40. strcpy(ai_config->property.binStr, json_getValue(ezb_bin_path ));
  41. json_t const* yolo_anchor = json_getProperty(property, "yolo_anchor");
  42. int index = 0;
  43. for(json_t const* i = json_getChild(yolo_anchor); i != 0; i = json_getSibling(i)) {
  44. ai_config->property.anchors[index] = json_getInteger(i);
  45. index++;
  46. }
  47. index = 0;
  48. json_t const* label = json_getProperty(property, "label" );
  49. for(json_t const* i = json_getChild(label); i != 0; i = json_getSibling(i)) {
  50. ai_config->property.label.push_back(json_getValue(i));
  51. index++;
  52. }
  53. index = 0;
  54. json_t const* output_blob_names = json_getProperty(property, "output_blob_names");
  55. for(json_t const* i = json_getChild(output_blob_names); i != 0; i = json_getSibling(i)) {
  56. ai_config->property.yolo_outputs_name.push_back( json_getValue(i));
  57. index++;
  58. }
  59. json_t const* need_nu_freq = json_getProperty(property, "need_nu_freq" );
  60. ai_config->property.need_nu_freq = json_getBoolean(json_getProperty(property, "need_nu_freq"));
  61. ai_config->property.freq_nu = json_getInteger(json_getProperty(property,"freq_nu"));
  62. ai_config->property.need_vu_freq = json_getBoolean(json_getProperty(property,"need_vu_freq"));
  63. ai_config->property.freq_vu = json_getInteger(json_getProperty(property,"freq_vu"));
  64. json_t const* class_attrs_all = json_getProperty( json, "class_attrs_all");
  65. ai_config->class_attrs_all.conf_thresh = json_getReal(json_getProperty(class_attrs_all,"pre_cluster_threshold"));
  66. ai_config->class_attrs_all.iou_thresh = json_getReal(json_getProperty(class_attrs_all,"nms_iou_threshold"));
  67. return 1;
  68. }