bazelbuild / bazelbuild/rules_apple
[iOS] Linking issue with resources or data (*.tflite files) for ios_static_framework.
- Dominant language
- Starlark
- Stars
- 593
- Forks
- 334
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 9
Description
### Description of the bug:
System information:
MediaPipe v0.8.7.1 :
Bazel version: 5.2.0
XCode 14.0.1
iOS 16 (iPhone 7)
Describe the problem:
I have faced with the problem of building static framework with Mediapipe.
The working solution for dynamic version:
```
apple_binary(
name = "face_landmarks_detector_ios",
deps = [
":face_landmarks_detector_ios_lib",
"@opencv_framework_ios16//:OpencvFramework"
],
data = [
"//mediapipe/modules/face_detection:face_detection_short_range.tflite",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
],
platform_type = "ios",
binary_type = "dylib"
)
```
Not working solution for static framework:
```
ios_static_framework(
name = "face_landmarks_detector_ios_static",
minimum_os_version = "16.0",
platform_type = "ios",
families = ["iphone"],
deps = [
":face_landmarks_detector_ios_lib",
"@opencv_framework_ios16//:OpencvFramework",
],
resources = [
"//mediapipe/modules/face_detection:face_detection_short_range.tflite",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
],
)
```
And here is this lib to see that is inside 'face_landmarks_detector_ios_lib':
```
cc_library(
name = "face_landmarks_detector_ios_lib",
srcs = [
"face_landmarks_detector.cc",
],
hdrs = [
"export.h",
"face_landmarks_detector.h"
],
copts = ["-std=c++17"],
deps = [
"//mediapipe/framework:calculator_framework",
"//mediapipe/framework/port:parse_text_proto",
"//mediapipe/graphs/face_mesh/subgraphs:face_renderer_gpu",
"//mediapipe/calculators/core:flow_limiter_calculator",
":face_landmarks_detector_front_gpu",
"//mediapipe/calculators/core:constant_side_packet_calculator",
":desktop_live_calculators",
] + select({
"//mediapipe:ios_i386": [],
"//mediapipe:ios_x86_64": [],
"//conditions:default": [
":mobile_calculators",
"//mediapipe/framework/formats:landmark_cc_proto",
],
}),
data = [
"//mediapipe/modules/face_detection:face_detection_short_range.tflite",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
],
defines = ["COMPILING_FACE_DETECTOR_API"],
alwayslink = 1,
)
```
Problem:
After linking it to the iOS app with XCode I will get issues related to tensor flow models. Especially for:
```
"//mediapipe/modules/face_detection:face_detection_short_range.tflite",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
```
Somehow ios_static_framework is ignoring this files, rather than dynamic build working good without any issues.
Environment and setting of the project is the same for dynamic and static lib.
Here is text from issue when app is running on the device (iPhone 7 iOS 16):
2023-01-08 13:28:55.216549+0200 app-api[13255:7401738] Error NOT_FOUND: ValidatedGraphConfig Initialization failed.
No registered object with name: FaceLandmarksDetectorFrontCpu; Unable to find Calculator "FaceLandmarksDetectorFrontCpu"
No registered object with name: FaceRendererCpu; Unable to find Calculator "FaceRendererCpu"
Questing is: How to link this tflite files to ios_static_framework?
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
_No response_
### Which operating system are you running Bazel on?
macOS 12.6.1
### What is the output of `bazel info release`?
release 5.3.2-homebrew
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
```text
https://github.com/google/mediapipe
add5600d0d4e9f0213ebf58088301dc7e743194a
63e679d99ca45b30514a9d84c9351a2d77bb9ba0
```
### Have you found anything relevant by searching the web?
Nothing related to static frameworks and resources.
### Any other information, logs, or outputs that you want to share?
To build solution I use this command:
```
bazel build -c opt
--config=ios_arm64
--action_env PYTHON_BIN_PATH=/usr/bin/python3
--apple_platform_type=ios
--sandbox_debug
--experimental_enable_objc_cc_deps
--features=-swift.no_generated_header
--apple_bitcode=embedded
--copt=-fembed-bitcode
--verbose_failures
mediapipe/face_landmarks_detector:face_landmarks_detector_ios_static
```
Where 'mediapipe/face_landmarks_detector:face_landmarks_detector_ios_static' is also described in the problem (let me know if you need more details for this component, because this is standard things what I found on official tutorials).
Inside Xcode project I was include generated static framework and also made bounds for tensor models:
I have copied "//mediapipe/modules/face_detection:face_detection_short_range.tflite" and //mediapipe/modules/face_landmark:face_landmark.tflite" as Wrapper for project (perfectly works for dynamic lib) by destination subgraph "mediapipe/modules/face_detection/".
Contributor guide
Research direction
Start with the ios_static_framework target face_landmarks_detector_ios_static and compare its resources handling with the working apple_binary configuration. Reproduce the Bazel build using the supplied command, then inspect the generated static framework and its integration in Xcode, focusing on the two named .tflite resources and the missing FaceLandmarksDetectorFrontCpu and FaceRendererCpu calculators. Done means the static framework runs without these NOT_FOUND errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, tensorflow
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100