TFLite: TfLiteCameraDemo bazel file

2024-06-03 15:08

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1027336

相关文章

BD错误集锦5——java.nio.file.FileSystemException 客户端没有所需的特权

问题:在运行storm本地模式程序时,java.nio.file.FileSystemException  客户端没有所需的特权   解决方式:以管理员身份运行IDEA即可。

BD错误集锦1——[Hive]ERROR StatusLogger No log4j2 configuration file found. Using default configuration:

错误描述:在使用IDEA进行jdbc方式连接到hive数据仓库时,出现以下错误:                ERROR StatusLogger No log4j2 configuration file found. 问题原因:缺少log4j2.xml文件   <?xml version="1.0" encoding="UTF-8"?><Configuration><Appender

iOS:编译时出现no such file or directory:xxx以及use twice...filenames are used to distinguish private dec

简    注册  登录   添加关注 作者  婉卿容若 2016.04.29 11:22 写了21870字,被16人关注,获得了14个喜欢 iOS:编译时出现"no such file or directory:xxx"以及"use twice...filenames are used to distinguish private

vue dist文件打开index.html报Failed to load resource: net::ERR_FILE_NOT_FOUND

本地正常。打包好的dist文件打开index.html报Failed to load resource: net::ERR_FILE_NOT_FOUND 解决办法: 在webpack.prod.conf.js 中output添加参数publicPath:’./’ 在webpack.base.conf.js里 publicPath: process.env.NODE_ENV === ‘pro

github 报错 git fatal: unable to write new index file

错误一:git fatal: unable to write new index file主要原因就是服务器磁盘空间不够导致的,增加服务器空间就OK了在百度上面搜索没得到什么有效信息,在gooogle上搜索得到很多有效信息 Finding large directories with something like the following helped clean up some log fi

STM32CubeIDE提示找不到头文件(No such file or directory)的解决办法

0 前言 最近在使用STM32CubeIDE时,发现为工程添加了头文件路径,但编译的时候还是报错,提示找不到头文件: 1 解决办法 1.1 为工程添加头文件路径 右键我们的工程,然后添加头文件路径(最好是相对路径): 1.2 为源文件夹添加头文件路径 右键我们包含了头文件的源文件夹,也将头文件路径添加进去(最好是相对路径): 最后编译就可以通过了: 2 更好的解决办法 这样

bazel build ‘...‘

Okay, let’s discuss the Bazel build command: bazel build ‘…’. Bazel Build Command: The bazel build command is used to build the targets (e.g., libraries, binaries, tests) specified in a Bazel-based p

springboot报错:A bean with that name has already been defined in file

springboot报错:A bean with that name has already been defined in file  Action : Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

libcudart.so.9.0: cannot open shared object file: No such file or directory

使用torch 或者 torchvision的时候,报错:libcudart.so.9.0: cannot open shared object file: No such file or directory 经过gg一下,发现这个错误是 没有正确安装 英伟达的 CUDA 9 工具包。 但我一想 不对!我是服务器上根本没有GPU 根本不需要安装cuda啊! 后来torch官网发现,必须专门指

SyntaxError- Non-ASCII character '-xe8' in file

python编译报错: SyntaxError: Non-ASCII character ‘\xe8’ in file xxx原因是不支持中文注释,如这种中英文混杂注释: # Subtract off the mean and divide by the variance of the pixels.#减去平均值并除以像素的方差 解决办法: 在文件第一行加上 #encoding:utf