CTfLiteClass.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. unsigned char *modelfile = NULL;
  22. float* input;
  23. int input_i;
  24. int im_height, im_width, im_channel;
  25. long GetFileSize(std::string filename);
  26. bool ReadFileToModel(std::string _fn);
  27. void MakeStaticResolver();
  28. public:
  29. CTfLiteClass();
  30. ~CTfLiteClass();
  31. bool LoadModel(std::string _fn);
  32. bool MakeAllocate();
  33. void GetInputTensorSize();
  34. bool LoadInputImageBasis(CImageBasis *rs);
  35. void Invoke();
  36. bool LastInvokeSucceeded() const { return lastInvokeSucceeded; }
  37. int GetAnzOutPut(bool silent = true);
  38. int GetOutClassification(int _von = -1, int _bis = -1);
  39. int GetClassFromImageBasis(CImageBasis *rs);
  40. std::string GetStatusFlow();
  41. float GetOutputValue(int nr);
  42. void GetInputDimension(bool silent);
  43. int ReadInputDimenstion(int _dim);
  44. };
  45. #endif //CTFLITECLASS_H