tflite-support icon indicating copy to clipboard operation
tflite-support copied to clipboard

How to link the task library to a bazel project?

Open LuisTbx opened this issue 2 years ago • 3 comments

I would like to use the CC task/vision library on my own project. How can i add it to my current workspace?

i tried by adding the http_archive, but this lead to missing dependencies:

http_archive( name = "org_tensorflow_lite_support", urls = [ "https://github.com/tensorflow/tflite-support/archive/822939c02daf36ef99d3d0e4a0633bd18c62e85e.tar.gz", ], strip_prefix = "tflite-support-822939c02daf36ef99d3d0e4a0633bd18c62e85e", )

Is there a way to create a 'bazel/tflite_support_deps.bzl' file that could handle all the dependencies so they can be loaded on any other bazel project?

Something like; load("@org_tensorflow_lite_support//bazel:tflite_support_deps.bzl", "tflite_support_deps") tflite_support_deps()

Or should i add all the dependencies on my workspace file?

Perhaps there is an eassier way to add the library but i dont know it. Thanks in advance for your help.

Best,

LuisTbx avatar Aug 03 '22 11:08 LuisTbx

Your http_archive target looks good to me. What kind of error message did you run into? Can you please provide an example of your bazel target?

Or should i add all the dependencies on my workspace file? You need to add depends for whatever linked in your bazel target, for example, absl, protobuf, etc

lu-wang-g avatar Aug 08 '22 21:08 lu-wang-g

Thanks for your answer @lu-wang-g .

I have added to my target the following dependencies:

deps = [ "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/flags:parse", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/port:statusor", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/core:external_file_handler", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/core/proto:external_file_proto_inc", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/vision:object_detector", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/vision/proto:bounding_box_proto_inc", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/vision/proto:class_proto_inc", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/vision/proto:detections_proto_inc", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/vision/proto:object_detector_options_proto_inc", "@org_tensorflow_lite_support//tensorflow_lite_support/cc/task/vision/utils:frame_buffer_common_utils" ]

the error i get: Unable to find package for @org_tensorflow//tensorflow/lite/core/shims:cc_library_with_tflite.bzl: The repository '@org_tensorflow' could not be resolved: Repository '@org_tensorflow' is not defined.

I will manually add the missing dependencies to my workspace file, but it could be nice to have a bazel folder on tflite-support repo that contains the directives to load these dependencies.

LuisTbx avatar Aug 10 '22 07:08 LuisTbx

You don't need to use cc_library_with_tflite (a target we created for internal usage). Regular cc_library should just work. Therefore you don't need to depend on @org_tensorflow specifically.

Note that you don't need to load transitive deps (i.e. deps used in tflite_support, but not directly in your project) in your workspace. You need @org_tensorflow here because you defined the target using cc_library_with_tflite.

lu-wang-g avatar Aug 16 '22 17:08 lu-wang-g