我在Tensor flow Camera Demo中使用自定义模型进行分类.我生成了一个.bp文件,我可以显示它包含的巨大图表.要将此图转换为优化图,如[ https://www.oreilly.com/learning/tensorflow-on-android]中所述,可以使用以下过程:
$ bazel-bin/tensorflow/python/tools/optimize_for_inference \
--input=tf_files/retrained_graph.pb \
--output=tensorflow/examples/android/assets/retrained_graph.pb
--input_names=Mul \
--output_names=final_result
Run Code Online (Sandbox Code Playgroud)
这里是如何从图形显示中找到input_names和output_names.当我不使用专有名称时,我会遇到设备崩溃:
E/TensorFlowInferenceInterface(16821): Failed to run TensorFlow inference
with inputs:[AvgPool], outputs:[predictions]
E/AndroidRuntime(16821): FATAL EXCEPTION: inference
E/AndroidRuntime(16821): java.lang.IllegalArgumentException: Incompatible
shapes: [1,224,224,3] vs. [32,1,1,2048]
E/AndroidRuntime(16821): [[Node: dropout/dropout/mul = Mul[T=DT_FLOAT,
_device="/job:localhost/replica:0/task:0/cpu:0"](dropout/dropout/div,
dropout/dropout/Floor)]]
Run Code Online (Sandbox Code Playgroud)