tensorflowlite Interpreter 的构造函数

Interpreter::Interpreter(ErrorReporter* error_reporter)
    : error_reporter_(error_reporter ? error_reporter
                                     : DefaultErrorReporter()) {
  // TODO(b/128420794): Include the TFLite runtime version in the log.
  TFLITE_LOG_PROD_ONCE(TFLITE_LOG_INFO, "Initialized TensorFlow Lite runtime.");

  // There's always at least 1 subgraph which is the primary subgraph.
  AddSubgraphs(1);
  context_ = primary_subgraph().context();

  // Reserve some space for the tensors to avoid excessive resizing.
  for (int i = 0; i < kTfLiteMaxExternalContexts; ++i) {
    external_contexts_[i] = nullptr;
  }

  UseNNAPI(false);
}

上 源码;

##----解释AddSubgraphs----##
函数原型
void Interpreter::AddSubgraphs(int subgraphs_to_add,
                               int* first_new_subgraph_index) { //first_new_subgraph_index  == nullptr 默认参数
  const size_t base_index = subgraphs_.size();
  if (first_new_subgraph_index) *first_new_subgraph_index = base_index;//所以,这句话,也不会执行

  subgraphs_.reserve(base_index + subgraphs_to_add);//预留的容器的空间
  for (int i = 0; i < subgraphs_to_add; ++i) {//执行1次
    Subgraph* subgraph =
        new Subgraph(error_reporter_, external_contexts_, &subgraphs_);
    subgraphs_.emplace_back(subgraph);//所以呢,只是放入了一个对象Subgraph
  }
}
##

头文件 是这么写的:

 Subgraph& primary_subgraph() {
   return *subgraphs_.front();  // Safe as subgraphs_ always has 1 entry.
 }

 std::vector> subgraphs_;

所以,关键在于  理解这个 Subgraph 类里面的函数...怎么调用的...

kTfLiteMaxExternalContexts  这个是什么值? 

在 lite/c/c_api_internal.h

typedef enum {
  kTfLiteEigenContext = 0,       // include eigen_support.h to use.
  kTfLiteGemmLowpContext = 1,    // include gemm_support.h to use.
  kTfLiteEdgeTpuContext = 2,     // Placeholder for Edge TPU support.
  kTfLiteCpuBackendContext = 3,  // include cpu_backend_support.h to use.
  kTfLiteMaxExternalContexts = 4
} TfLiteExternalContextType;

for 循环也没具体做什么, 就是初始化了空指针...

UseNNAPI(false); //就是不使能 NNAPI ..事实上 还是调用了  Subgraph 类里边的 UseNNAPI

你可能感兴趣的:(tensorflowlite)