本文主要是介绍TFLite: TfLiteCameraDemo bazel file,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
编译源码使用的命令
bazel build --cxxopt='--std=c++11' //tensorflow/lite/java:TfLiteCameraDemo \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=arm64-v8a
bazel file组成元素
workspace: 路径下包含文件WORKSPACE(可以是空文件,但必须有)
package:路径下包含文件BUILD
target:BUILD文件中的某个ruler
BUILD file
load("@build_bazel_rules_android//android:rules.bzl", "android_binary")
package(default_visibility = ["//visibility:private"])
licenses(["notice"]) # Apache 2.0
android_binary(
name = "TfLiteCameraDemo",
srcs = glob(["java/**/*.java"]),
aapt_version = "aapt",
assets = [
"//tensorflow/contrib/lite/java/demo/app/src/main/assets:labels_mobilenet_quant_v1_224.txt",
"@tflite_mobilenet//:mobilenet_quant_v1_224.tflite",
],
assets_dir = "",
custom_package = "com.example.android.tflitecamerademo",
manifest = "AndroidManifest.xml",
nocompress_extensions = [
".tflite",
],
resource_files = glob(["res/**"]),
# In some platforms we don't have an Android SDK/NDK and this target
# can't be built. We need to prevent the build system from trying to
# use the target in that case.
tags = ["manual"],
deps = [
"//tensorflow/contrib/lite/java:tensorflowlite",
"//tensorflow/contrib/lite/java/src/testhelper/java/org/tensorflow/lite:testhelper",
"@androidsdk//com.android.support:support-v13-25.2.0",
"@androidsdk//com.android.support:support-v4-25.2.0",
],
)
分析第一句 load("@build_bazel_rules_android//android:rules.bzl", "android_binary")
load是一个扩展bazel功能的函数
build_bazel_rules_android是一个ruler的name,表示从某个 URL 下载到的文件,android是包含文件rules.bzl的文件夹
android_binary和该BULD文件的android_binary对应
build_bazel_rules_android定义在文件中tensorflow/tensorflow/workspace.bzl文件中
tf_http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_android/archive/v0.1.1.zip",
"https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip",
],
)
tf_http_archive(
name = "tflite_mobilenet",
build_file = clean_dep("//third_party:tflite_mobilenet.BUILD"),
sha256 = "23f814d1c076bdf03715dfb6cab3713aa4fbdf040fd5448c43196bd2e97a4c1b",
urls = [
"https://mirror.bazel.build/storage.googleapis.com/..models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip",
"https://storage.googleapis.com/../models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip",
],
)
另外androidsdk定义在文件:tensorflow/WORKSPACE
android_sdk_repository (
name = "androidsdk",
api_level = 23,
build_tools_version = "26.0.1",
path = "/home/mi/Android/Sdk/",
)
glob函数
glob(include, exclude=[], exclude_directories=1)
Glob is a helper function that can be used anywhere a list of filenames is expected.
srcs = glob(["*.java"]) + [":gen_java_srcs"],
data = glob(
["testdata/*.txt"],
exclude = ["testdata/experimental.txt"],
srcs = glob(
["**/*.java"],
exclude = ["**/testing/**"],
),
android ruler
android_binary: Produces Android application package files (.apk).
name: required
deps: The list of other libraries to be linked in to the binary target.
srcs: The list of source files that are processed to create the target.
aapt_version: Select the version of aapt for this rule. aapt/aapt2/auto
assets: The list of assets to be packaged
assets_dir: The string giving the path to the files in assets.
custom_package: Java package for which java sources will be generated.
manifest: The name of the Android manifest file, normally AndroidManifest.xml.
resource_files: The list of resources to be packaged.
nocompress_extensions: A list of file extension to leave uncompressed in apk.
android_libray
This rule compiles and archives its sources into a .jar file.
java接口的组成
native层的代码主要由framework和builtin_ops组成 ;
framework
其中的 *.d 文件表示改文件的依赖如 .c/ .h文件的改变将引起重新编译
│ ├── framework
│ │ ├── allocation.o
│ │ ├── graph_info.o
│ │ ├── interpreter.o
│ │ ├── mmap_allocation.o
│ │ ├── model.d
│ │ ├── model.o
│ │ ├── mutable_op_resolver.o
│ │ ├── nnapi_delegate.o
│ │ ├── optional_debug_tools.o
│ │ └── stderr_reporter.o
builtin_ops
只用一个regitster ops的register.cc文件
│ ├── builtin_ops
│ │ ├── register.d
│ │ └── register.o
注册的ops在builtin_op_kernels中
│ ├── builtin_op_kernels
│ │ ├── activations.d
│ │ ├── activations.o
│ │ ├── add.d
│ │ ├── add.o
这篇关于TFLite: TfLiteCameraDemo bazel file的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!