问题
我开发了一个简单的 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