简体   繁体   English

没有OpKernel Tensorflow Mobile Android。 如何调试?

[英]No OpKernel Tensorflow Mobile Android. How to debug?

I know this is a very common error to see in Android Studio. 我知道这是在Android Studio中常见的错误。 I used to see this for 'GatherNd' until I checked my tf_op_files.txt against the one in master and saw that 'gather_nd_op' had been added recently. 我以前在'GatherNd'上看到过这个,直到我tf_op_files.txt中的那个检查了tf_op_files.txt并看到最近已经添加了'gather_nd_op'。 After building with bazel (though it seems jcenter/'none' still yields 'GatherNd' not found), I don't see this anymore. 在使用bazel构建之后(尽管jcenter /'none'仍然会生成'GatherNd'),我再也看不到它了。 However, I do see this now with 'StridedSlice'. 但是,我现在确实通过“ StridedSlice”看到了这一点。

java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'StridedSlice' with these attrs.  Registered devices: [CPU], Registered kernels:
                                                                       device='CPU'; T in [DT_BFLOAT16]
                                                                       device='CPU'; T in [DT_BOOL]
                                                                       device='CPU'; T in [DT_FLOAT]
                                                                       device='CPU'; T in [DT_INT32]

                                                                         [[Node: roi_align_classifier/strided_slice = StridedSlice[Index=DT_INT32, T=DT_INT64, begin_mask=1, ellipsis_mask=0, end_mask=1, new_axis_mask=0, shrink_axis_mask=2](roi_align_classifier/Where, roi_align_classifier/strided_slice/stack, roi_align_classifier/strided_slice/stack_1, roi_align_classifier/strided_slice/stack_2)]]
                                                                         at org.tensorflow.Session.run(Native Method)
                                                                         at org.tensorflow.Session.access$100(Session.java:48)
                                                                         at org.tensorflow.Session$Runner.runHelper(Session.java:298)
                                                                         at org.tensorflow.Session$Runner.run(Session.java:248)
                                                                         at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:218)

I see that this op exists in tf_op_files.txt and that the error can occur from using the wrong parameters. 我看到该操作存在于tf_op_files.txt并且使用错误的参数可能会发生错误。 I have tried changing the input and output types from float[] to int[] but no luck. 我尝试将输入和输出类型从float []更改为int [],但是没有运气。

I see the type signature and info about strided_slice in array_ops.cc and https://www.tensorflow.org/api_docs/python/tf/strided_slice . 我在array_ops.cc和https://www.tensorflow.org/api_docs/python/tf/strided_slice中看到类型签名和有关strided_slice的信息。 However, these don't provide great insight as to whether I'm merely supplying the wrong params or the StridedSlice I am using actually doesn't exist! 但是,对于我只是提供错误的参数还是我所使用的StridedSlice实际上不存在,这些都无法提供深刻的见解!

My question is: how do I debug this in a more deterministic way than random guessing? 我的问题是:与随机猜测相比,我如何以更具确定性的方式调试它?

Edit Checking http://www.oreilly.com/data/free/files/building-mobile-applications-with-tensorflow.pdf , it seems this implementation is correct and that it is not supported for mobile currently? 编辑检查http://www.oreilly.com/data/free/files/building-mobile-applications-with-tensorflow.pdf ,看来此实现是正确的,并且当前不支持移动设备吗? ie. 即。 this error message is not dependent on the input and output passed. 此错误消息不取决于传递的输入和输出。 Is this right? 这是正确的吗? I think adding the op would be rather straightforward. 我认为添加操作非常简单。 I just need to know if that's what the problem is and what the type is supposed to be. 我只需要知道这是否是问题所在,以及类型应该是什么。

I've also found https://medium.com/joytunes/deploying-a-tensorflow-model-to-android-69d04d1b0cba . 我还找到了https://medium.com/joytunes/deploying-a-tensorflow-model-to-android-69d04d1b0cba That said, any debugging information on the android/type side would be great. 就是说,任何在android / type端的调试信息都会很棒。 ie. 即。 what is the type being passed to the op and what is it expecting? 传递给操作的类型是什么,期望什么? It seems I have to use outside resources to determine this 看来我必须使用外部资源来确定

Edit 2 编辑2

After finding all the ops, quantizing, getting the inputs of input nodes and outputs of output nodes, I tried adding the strided_slice_op.cc to the android_extended_ops_group2 only to see it already existed when building. 找到所有操作后,进行量化,获取输入节点的输入和输出节点的输出,我尝试将strided_slice_op.cc添加到android_extended_ops_group2中,只是在构建时看到它已经存在。 I think I have to add another implementation. 我想我必须添加另一个实现。 Does anyone know how to get the full type signature of the nodes and does this seem like I'm on the right path? 有谁知道如何获取节点的完整类型签名,这看起来像我在正确的道路上吗? In tensorboard and in the error, the op is strided_slice[0-9] while the build is like so: 在张量板和错误中,操作是strided_slice [0-9],而构建是这样的:

`tf_kernel_library(
    name = "strided_slice_op",
    srcs = [
        "strided_slice_op.cc",
        "strided_slice_op_inst_0.cc",
        "strided_slice_op_inst_1.cc",
        "strided_slice_op_inst_2.cc",
        "strided_slice_op_inst_3.cc",
        "strided_slice_op_inst_4.cc",
        "strided_slice_op_inst_5.cc",
        "strided_slice_op_inst_6.cc",
        "strided_slice_op_inst_7.cc",
    ],
    hdrs = [
        "slice_op.h",
        "strided_slice_op.h",
        "strided_slice_op_impl.h",
    ],
    gpu_srcs = [
        "slice_op.h",
        "strided_slice_op.h",
        "strided_slice_op_impl.h",
        "strided_slice_op_gpu.cu.cc",
    ],
    deps = [
        ":bounds_check",
        ":dense_update_functor",
        ":ops_util",
        ":variable_ops",
        "//tensorflow/core:framework",
        "//tensorflow/core:lib",
        "//third_party/eigen3",
    ],
)`

The problem was staring me in the face the whole time. 问题一直困扰着我。 T=DT_INT64 is not one of the registered kernels for strided_slice. T = DT_INT64不是strided_slice的注册内核之一。 Editing the model to cast before slicing solved the issue for me. 在切片之前编辑要投射的模型为我解决了这个问题。

Ref: https://github.com/tensorflow/tensorflow/issues/13772 参考: https : //github.com/tensorflow/tensorflow/issues/13772

On to registering a custom op! 开始注册自定义操作!

Edit 编辑

Just needed to change the order of operations! 只需更改操作顺序即可!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM