Tensorflow lite 微神经网络层构建

Tensorflow lite micro neural network layers building

我尝试在我的 ESP32 上 运行 一些 ML,我想使用 Tensorflow lite micro。但我真的不明白,他们是如何建立这些层的。下面是如何训练人员检测模型的示例: Person detection model training

很清楚,但最后他们说:

MobileNet v1 is a stack of 14 of these depthwise separable convolution layers with an average pool, then a fully-connected layer followed by a softmax at the end.

如果我查看示例代码,他们在其中构建了 tf lite 微型模型,它只有 3 行:

 static tflite::MicroMutableOpResolver<3> micro_op_resolver;
  micro_op_resolver.AddAveragePool2D();
  micro_op_resolver.AddConv2D();
  micro_op_resolver.AddDepthwiseConv2D();

有Average pool和depthwise layer,但是Conv2D layer是从哪里来的呢?并且只展示了 1 个 depthwise 层,但是在文档中,模型中有 14 个 depthwise 层。

所以问题是,训练模型和我应该在 tensoflow lite micro 中构建的模型之间有什么关系吗?如果有,我如何确定如何建立。这就是问题,如果没有关系,我需要以什么方式建立模型。

他们没有明确地构建模型,他们依赖于包含架构的模型文件 (source):

  model = tflite::GetModel(g_person_detect_model_data);

其中 g_person_detect_model_data.cc 是使用以下命令从 tflite 模型(包含体系结构)生成的(请参阅自述文件中的 Converting into a c source file):

# Install xxd if it is not available
!apt-get -qq install xxd
# Save the file as a C source file
!xxd -i vww_96_grayscale_quantized.tflite > person_detect_model_data.cc

所以您共享的代码没有构建模型。您看到的是,出于性能原因,他们明确添加了模型所需的操作,而不是依赖更复杂的操作 tflite::AllOpsResolver。 表示为 comment above the code you shared :

  // Pull in only the operation implementations we need.
  // This relies on a complete list of all the ops needed by this graph.
  // An easier approach is to just use the AllOpsResolver, but this will
  // incur some penalty in code space for op implementations that are not
  // needed by this graph.
  //
  // tflite::AllOpsResolver resolver;
  // NOLINTNEXTLINE(runtime-global-variables)
  static tflite::MicroMutableOpResolver<5> micro_op_resolver;
  micro_op_resolver.AddAveragePool2D();
  micro_op_resolver.AddConv2D();
  micro_op_resolver.AddDepthwiseConv2D();
  micro_op_resolver.AddReshape();
  micro_op_resolver.AddSoftmax();