CTfLiteClass.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #ifndef CTFLITECLASS_H
  3. #define CTFLITECLASS_H
  4. #include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
  5. #include "tensorflow/lite/micro/micro_interpreter.h"
  6. #include "tensorflow/lite/schema/schema_generated.h"
  7. #include "esp_err.h"
  8. #include "esp_log.h"
  9. #include "CImageBasis.h"
  10. class CTfLiteClass
  11. {
  12. protected:
  13. tflite::MicroMutableOpResolver<10> resolver;
  14. const tflite::Model* model;
  15. tflite::MicroInterpreter* interpreter;
  16. TfLiteTensor* output = nullptr;
  17. int kTensorArenaSize;
  18. uint8_t *tensor_arena;
  19. bool ownsSharedMemoryLease;
  20. bool modelMemoryClaimed;
  21. bool lastInvokeSucceeded;
  22. unsigned char *modelfile = NULL;
  23. float* input;
  24. int input_i;
  25. int im_height, im_width, im_channel;
  26. long GetFileSize(std::string filename);
  27. bool ReadFileToModel(std::string _fn);
  28. void MakeStaticResolver();
  29. public:
  30. CTfLiteClass();
  31. ~CTfLiteClass();
  32. bool LoadModel(std::string _fn);
  33. bool MakeAllocate();
  34. void GetInputTensorSize();
  35. bool LoadInputImageBasis(CImageBasis *rs);
  36. void Invoke();
  37. bool LastInvokeSucceeded() const { return lastInvokeSucceeded; }
  38. int GetAnzOutPut(bool silent = true);
  39. int GetOutClassification(int _von = -1, int _bis = -1);
  40. int GetClassFromImageBasis(CImageBasis *rs);
  41. std::string GetStatusFlow();
  42. float GetOutputValue(int nr);
  43. void GetInputDimension(bool silent);
  44. int ReadInputDimenstion(int _dim);
  45. };
  46. #endif //CTFLITECLASS_H