将 Darkflow tensorflow 模型移植到 Tensorflow Android Camera Detection Demo

Porting Darkflow tensorflow model into Tensorflow Android Camera Detection Demo

我有一个定制的 YOLO 模型,形式为 cfg 和权重。我使用 darkflow (https://github.com/thtrieu/darkflow) as

将此模型转换为 .pb 和 .meta 文件
sudo ./flow --model cfg/license.cfg --load bin/yololp1_420000.weights --savepb --verbalise

分析结果.pb(/license.pb)是

>>> import tensorflow as tf
>>> gf = tf.GraphDef()
>>> gf.ParseFromString(open('/darkflow/built_graph/license.pb','rb').read())
202339124
>>> [n.name + '=>' +  n.op for n in gf.node if n.op in ( 'Softmax','Placeholder')]
[u'input=>Placeholder']
>>> [n.name + '=>' +  n.op for n in gf.node if n.op in ( 'Softmax','Mul')]
[u'mul=>Mul', u'mul_1=>Mul', u'mul_2=>Mul', u'mul_3=>Mul', u'mul_4=>Mul', u'mul_5=>Mul', u'mul_6=>Mul', ...]

它有 'input' 层但没有 'output' 层。 我尝试将模型移植到 tensorflow 相机演示检测中 (https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android)。 相机预览在一秒钟后停止。 android 异常如下:

04-27 15:06:32.727 21721 21737 D gralloc : gralloc_lock_ycbcr success. format : 11, usage: 3, ycbcr.y: 0xc07cf000, .cb: 0xc081a001, .cr: 0xc081a000, .ystride: 640 , .cstride: 640, .chroma_step: 2
04-27 15:06:32.735 21721 21736 E TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[input], outputs:[output]
04-27 15:06:32.736 21721 21736 E AndroidRuntime: FATAL EXCEPTION: inference
04-27 15:06:32.736 21721 21736 E AndroidRuntime: Process: org.tensorflow.demo, PID: 21721
04-27 15:06:32.736 21721 21736 E AndroidRuntime: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'ExtractImagePatches' with these attrs.  Registered devices: [CPU], Registered kernels:
04-27 15:06:32.736 21721 21736 E AndroidRuntime:   <no registered kernels>
04-27 15:06:32.736 21721 21736 E AndroidRuntime:     [[Node: ExtractImagePatches = ExtractImagePatches[T=DT_FLOAT, ksizes=[1, 2, 2, 1], padding="VALID", rates=[1, 1, 1, 1], strides=[1, 2, 2, 1]](47-leaky)]]

如何解决这个问题?我也尝试使用 "optimize_for_inference.py" 将 .pb 转换为移动优化的 .pb 但没有用。鉴于此,如何在转换后的 .pb 文件中正确定义输入和输出张量/层?或者如何在 TF 相机检测演示中正确移植生成的 .pb?

没有 Opkernel 意味着没有硬件的实现 运行 这个 .pb。 要解决此问题,请查看 ./net/ops/convolution.py 的 class 重组。它有两个方法 _forward 和 forward。当前的默认选项是使用 forward,它有 extract_image_patches - tensorflow 的内置方法。

交换两个方法的名称,您将使用我的手动实现,这在 Opkernel 实现中应该没有问题。

参考:https://github.com/thtrieu/darkflow/issues/56