为 arm64-v8a 发布构建 libtensorflow_cc.so

Issue building libtensorflow_cc.so for arm64-v8a

我正在尝试使用 bazel

为 arm64-v8a 架构构建 libtensorflow_cc.so for android

要求

我正在尝试为 arm64-v8a 架构构建 'libtensorflow_cc.so' for android。 我需要它在运行时通过 C++ 在 Android NDK 中创建和训练模型文件。 在

生成的 'libtensorflow_cc.so' 的帮助下,我能够使用 C++ 在桌面上这样做

bazel build -c opt //tensorflow:libtensorflow_cc.so

,但现在想与 Android NDK 集成并在移动设备上进行训练。

我试过 'libtensorflow.so' ,但我得到以下错误

tensorflow_jni.cc:359 Non-OK-status: session->Create (graph_def) status: Invalid argument: No OpKernel was registered to support Op 'SparseSoftmaxCrossEntropyWithLogits' with these attrs. Registered devices: [CPU], Registered kernels: [[Node: SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT64](add, Cast)]]

我也试过 'libtensorflow_inference.so' 但我收到许多未定义的引用错误 如下图

In function tensorflow::TensorShapeRep::~TensorShapeRep()': /home/ashok/AndroidStudioProjects/Android-arm64-v8a-dnn/facerecognitionlibrary/jni-build/jni/include/include1/tensorflow/core/framework/tensor_shape.h:492: undefined reference totensorflow::TensorShapeRep::DestructorOutOfLine()' ./obj/local/arm64-v8a/objs-debug/tensorflow_cc1/tensorflowTrian_jni.o: In function std::pair::~pair()': /home/ashok/Ashok/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_pair.h:96: undefined reference totensorflow::Tensor::~Tensor()' ./obj/local/arm64-v8a/objs-debug/tensorflow_cc1/tensorflowTrian_jni.o: In function std::string* tensorflow::internal::MakeCheckOpString(long const&, int const&, char const*)': /home/ashok/AndroidStudioProjects/Android-arm64-v8a-dnn/facerecognitionlibrary/jni-build/jni/include/include1/tensorflow/core/platform/default/logging.h:184: undefined reference totensorflow::internal::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)'

因此使用以下代码为 arm64-v8a 构建 libtensorflow_cc.so

代码

bazel build -c opt //tensorflow:libtensorflow_cc.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=arm64-v8a

日志

WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:avgpooling_op.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:bounds_check.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:cwise_ops.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:cwise_ops_common.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:cwise_ops_gradients.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_activations.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_attention.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_backward_cuboid_convolutions.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_backward_spatial_convolutions.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_cuboid_convolution.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_pooling.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_softmax.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_spatial_convolutions.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_volume_patch.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:fifo_queue.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:maxpooling_op.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:ops_util.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:ops_util.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:padding_fifo_queue.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:pooling_ops_common.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:pooling_ops_common.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:queue_base.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:queue_op.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:typed_queue.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_entry.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_scorer.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_search.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_decoder.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_loss_util.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:naming.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:naming.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:tensor_bundle.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:tensor_bundle.h' directly. You should either move the file to this package or depend on an appropriate rule there ERROR: /home/ashok/Ashok/tensorflow/tensorflow/c/eager/BUILD:11:1: in deps attribute of cc_library rule //tensorflow/c/eager:c_api: target '//tensorflow/c/eager:c_api_internal' does not exist. Since this rule was created by the macro 'tf_cuda_library', the error might have been caused by the macro implementation in /home/ashok/Ashok/tensorflow/tensorflow/tensorflow.bzl:667:12 ERROR: Analysis of target '//tensorflow:libtensorflow_cc.so' failed; build aborted INFO: Elapsed time: 0.252s FAILED: Build did NOT complete successfully (0 packages loaded)

请帮忙解决问题

要修复最初的 "No OpKernel" 错误,您需要将您使用的操作添加到 tensorflow/core/kernels/BUILD 中的 android_extended_ops_group1 目标: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/BUILD#L4568

您可以在此处的 TF for Mobile 电子书中找到有关为什么需要这样做的更多详细信息: http://www.oreilly.com/data/free/building-mobile-applications-with-tensorflow.csp