3

问题

我开发了一个简单的 NodeJS 应用程序,用于使用@tensorflow/tfjs-node. 在我的开发 PC (Windows 10 Pro) 上一切正常,但尝试在我的 Raspberry Pi 2B (Raspbian 10) 上执行时,出现以下错误:

Overriding the gradient for 'Max'
Overriding the gradient for 'OneHot'
Overriding the gradient for 'PadV2'
Overriding the gradient for 'SpaceToBatchND'
Overriding the gradient for 'SplitV'
2020-07-31 11:25:12.068892: I tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: ./assets/saved_model
2020-07-31 11:25:12.643852: I tensorflow/cc/saved_model/reader.cc:54] Reading meta graph with tags { serve }
2020-07-31 11:25:13.206821: I tensorflow/cc/saved_model/loader.cc:311] SavedModel load for tags { serve }; Status: fail. Took 1137915 microseconds.
Error: Failed to load SavedModel: Op type not registered 'NonMaxSuppressionV5' in binary running on raspberrypi. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.
    at NodeJSKernelBackend.loadSavedModelMetaGraph (/home/pi/storage/tensorflow-test-node/node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.js:1588:29)
    at Object.<anonymous> (/home/pi/storage/tensorflow-test-node/node_modules/@tensorflow/tfjs-node/dist/saved_model.js:429:45)
    at step (/home/pi/storage/tensorflow-test-node/node_modules/@tensorflow/tfjs-node/dist/saved_model.js:48:23)
    at Object.next (/home/pi/storage/tensorflow-test-node/node_modules/@tensorflow/tfjs-node/dist/saved_model.js:29:53)
    at fulfilled (/home/pi/storage/tensorflow-test-node/node_modules/@tensorflow/tfjs-node/dist/saved_model.js:20:58)

我可以用以下几行重现它:

const tf = require('@tensorflow/tfjs-node');

// Native SavedModel: ./assets/saved_model/saved_model.pb
const objectDetectionModel = await tf.node.loadSavedModel('./assets/saved_model'); // Error

// ...

我认为该错误与 SavedModel 版本有关,但我不知道如何将其转换为在 Rapsberry Pi 中使用,或者如果我在 Windows 或 Raspbian 中执行 NodeJS 应用程序需要不同的 SavedModel。

细节

环境

  • 发展
    • 操作系统:Windows 10 专业版
    • 节点JS:v12.16.2
    • 新PM:6.11.3
  • 目标(树莓派):
    • 操作系统:Raspbian 10
    • 节点JS:v12.18.3
    • 新PM:6.14.6

NodeJS 应用程序

@tensorflow/tfjs-node@2.0.1是在package.json.

训练

该模型是按照本指南在 Python 上训练的(使用的 TensorFlow 版本是1.15.2)。

保存模型

SavedModel 的详细信息(执行的命令saved_model_cli show --dir saved_model --tag_set serve --signature_def serving_default):

The given SavedModel SignatureDef contains the following input(s):
  inputs['inputs'] tensor_info:
      dtype: DT_INT32
      shape: (-1, -1, -1, 3)
      name: image_tensor:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['detection_boxes'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 300, 4)
      name: detection_boxes:0
  outputs['detection_classes'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 300)
      name: detection_classes:0
  outputs['detection_multiclass_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 300, 37)
      name: detection_multiclass_scores:0
  outputs['detection_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 300)
      name: detection_scores:0
  outputs['num_detections'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1)
      name: num_detections:0
  outputs['raw_detection_boxes'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 300, 4)
      name: raw_detection_boxes:0
  outputs['raw_detection_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 300, 37)
      name: raw_detection_scores:0
Method name is: tensorflow/serving/predict
4

1 回答 1

2

您需要将模型转换为 Tensorflow Lite(减少操作)。收到的错误是由于在加载桌面编译模型时树莓派上缺少可用的操作(有更高的操作可用)。在此处阅读有关操作的更多信息:https ://www.tensorflow.org/lite/guide/ops_select

已经有一个将模型导出到 TF Lite 的构建脚本,类似于您正在使用的那个(官方示例 repo 中的相同文件夹)。功能相同,但输入格式略有不同。看看:https ://www.github.com/tensorflow/models/tree/master/research%2Fobject_detection%2Fexport_tflite_ssd_graph.py

于 2020-08-09T03:04:29.020 回答