8#include <tensorflow/lite/core/c/common.h>
9#include <tensorflow/lite/micro/micro_interpreter.h>
21 ESP_LOGE(TAG,
"Refusing to allocate a zero-length model");
28 if (new_allocation ==
nullptr) {
29 ESP_LOGE(TAG,
"Failed to reallocate %zu bytes",
size);
32 this->
data_ = new_allocation;
40 if (this->
data_ ==
nullptr) {
41 ESP_LOGE(TAG,
"Failed to allocate %zu bytes",
size);
51 if (this->
data_ !=
nullptr) {
53 this->
data_ =
nullptr;
69 ESP_LOGE(TAG,
"Model data is null or too small");
74 if (memcmp(this->
data_ + 4,
"TFL3", 4) != 0) {
75 ESP_LOGE(TAG,
"Invalid TFLite model magic number");
82 memcpy(&root_offset, this->
data_,
sizeof(root_offset));
83 if (root_offset >= this->
size_) {
84 ESP_LOGE(TAG,
"TFLite model root offset is out of bounds");
88 const tflite::Model *model = tflite::GetModel(this->
data_);
89 if (model->version() != TFLITE_SCHEMA_VERSION) {
90 ESP_LOGE(TAG,
"TFLite model version mismatch (expected %d, got %" PRIu32
")", TFLITE_SCHEMA_VERSION,
T * reallocate(T *p, size_t n)
void deallocate(T *p, size_t n)
const uint8_t * get_model_pointer() const
bool allocate(size_t size)
uint8_t * get_write_pointer()
RAMAllocator< uint8_t > allocator_
bool validate_and_mark_ready()
ESPHOME_LOG_TAG(TAG, "micro_wake_word")