Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOT FOR MERGING] Core ML Delegate Tests on iOS Device #857

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c9a7767
Updated files
priankakariat May 19, 2022
dc5c057
Updated files
priankakariat May 26, 2022
95522de
Updated files
priankakariat Jun 2, 2022
5468a42
Added files
priankakariat Jun 3, 2022
cf615ba
Reverted vision podspec
priankakariat Jun 3, 2022
7b30cb2
Reverted build file
priankakariat Jun 3, 2022
0e19c84
Reverted to version in master
priankakariat Jun 3, 2022
9344bb1
Reverted to version in master
priankakariat Jun 3, 2022
ae671c7
Reverted to version in master
priankakariat Jun 3, 2022
54f509a
Updated formatting
priankakariat Jun 3, 2022
135f369
Added vision framework as vendored framework of cocoapods
priankakariat Jun 8, 2022
5c7401a
Fixed typos
priankakariat Jun 8, 2022
8decd90
Updated bundle name
priankakariat Jun 16, 2022
77e85c3
Updated build version
priankakariat Jun 16, 2022
405454b
Updated coremldelegate tests
priankakariat Jun 22, 2022
8fd27eb
Updated tests
priankakariat Jun 22, 2022
5753ce9
Updated build file
priankakariat Jun 22, 2022
485949c
Updated .bzl
priankakariat Jun 22, 2022
00d8993
Updated files
priankakariat Jun 22, 2022
cfd3dba
Merge branch 'ios-image-embedder-cocoapods' into ios-gpu-delegate-test
priankakariat Jun 22, 2022
c940ef6
Updated files
priankakariat Jun 23, 2022
613238c
Removed comments
priankakariat Jul 14, 2022
bd0891e
Merge remote-tracking branch 'origin/ios-cocoapods' into ios-gpu-dele…
priankakariat Jul 14, 2022
937c753
Updated files
priankakariat Jul 14, 2022
eb8d04e
Added back missing target
priankakariat Jul 14, 2022
0e16c33
Deleted podspec
priankakariat Jul 14, 2022
5578f2c
Removed unnecessary files
priankakariat Jul 14, 2022
ceab44c
Added back missing files
priankakariat Jul 14, 2022
af96597
Removed image embedder files
priankakariat Jul 14, 2022
90bc689
Added back coreml plugin
priankakariat Jul 14, 2022
c427184
Updated vision podspec
priankakariat Jul 14, 2022
c0518c9
Updated podspec
priankakariat Jul 25, 2022
b5d8216
Removed log
priankakariat Jul 28, 2022
bed5efe
Added manual triggering of registration
priankakariat Aug 12, 2022
c3c867e
Reverted build command
priankakariat Aug 12, 2022
9f2e68e
Reverted changes
priankakariat Aug 12, 2022
d7ee00e
Reverted changes in shell script
priankakariat Aug 12, 2022
7985c8f
Revert "Reverted changes in shell script"
priankakariat Aug 12, 2022
e9c1635
Added space
priankakariat Aug 12, 2022
038c044
Updated formatting
priankakariat Aug 12, 2022
50ac237
Updated formatting
priankakariat Aug 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tensorflow_lite_support/c/task/vision/image_classifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ StatusOr<ImageClassifierOptionsCpp> CreateImageClassifierCppOptionsFromCOptions(
cpp_options.set_score_threshold(
c_options->classification_options.score_threshold);

cpp_options.mutable_base_options()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding core ml delegate settings here since these changes are only for testing on a device.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once issues are fixed these can be implemented in the iOS framework.

->mutable_compute_settings()
->mutable_tflite_settings()
->set_delegate(tflite::proto::Delegate::CORE_ML);

cpp_options.mutable_base_options()
->mutable_compute_settings()
->mutable_tflite_settings()
->mutable_coreml_settings()
->set_enabled_devices(tflite::proto::CoreMLSettings::DEVICES_ALL);

return cpp_options;
}
} // namespace
Expand Down
10 changes: 8 additions & 2 deletions tensorflow_lite_support/ios/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(
load(
"//tensorflow_lite_support/ios:ios.bzl",
"TFL_TASK_MINIMUM_OS_VERSION",
"TFL_TASK_COREML_MINIMUM_OS_VERSION",
"strip_api_include_path_prefix",
)

Expand Down Expand Up @@ -142,6 +143,12 @@ objc_library(
],
)

# Xcode 12 does not support ios fat libraries. Frameworks built for multiple
# architectures should be compiled into a .xcframework inside. Bazel currently
# does not support building .xcframework. You have to build the framework
# for the architecture you decide to test on.
# Use the below command to build for arm64 which lets you test the library on
# iOS devices.
# bazel build -c opt --config=ios_arm64 //tensorflow_lite_support/ios:TensorFlowLiteTaskVision_framework
ios_static_framework(
name = "TensorFlowLiteTaskVision_framework",
Expand All @@ -159,7 +166,7 @@ ios_static_framework(
":GMLImage.h",
],
bundle_name = "TensorFlowLiteTaskVision",
minimum_os_version = TFL_TASK_MINIMUM_OS_VERSION,
minimum_os_version = TFL_TASK_COREML_MINIMUM_OS_VERSION,
deps = [
"//tensorflow_lite_support/ios/task/vision:TFLImageClassifier",
"//tensorflow_lite_support/ios/task/vision:TFLObjectDetector",
Expand All @@ -182,4 +189,3 @@ ios_static_framework(
"//tensorflow_lite_support/ios/task/text/qa:TFLBertQuestionAnswerer",
],
)

12 changes: 6 additions & 6 deletions tensorflow_lite_support/ios/ios.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""TensorFlow Lite Support Library Helper Rules for iOS"""

TFL_TASK_MINIMUM_OS_VERSION = "10.0"
TFL_TASK_COREML_MINIMUM_OS_VERSION = "11.0"

# When the static framework is built with bazel, the all header files are moved
# to the "Headers" directory with no header path prefixes. This auxiliary rule
# is used for stripping the path prefix to the C/iOS API header files included by
# other C/iOS API header files.
# In case of C header files includes start with a keyword of "#include'.
# Imports in iOS header files start with a keyword of '#import'.

TFL_TASK_MINIMUM_OS_VERSION = "10.0"

def strip_api_include_path_prefix(name, hdr_labels, prefix = ""):
"""Create modified header files with the import path stripped out.

Expand All @@ -20,8 +20,9 @@ def strip_api_include_path_prefix(name, hdr_labels, prefix = ""):
"""
for hdr_label in hdr_labels:
hdr_filename = hdr_label.split(":")[-1]
# The last path component of iOS header files can be sources/some_file.h
# or Sources/some_file.h. Hence it wiill contain a '/'. So the string

# The last path component of iOS header files can be sources/some_file.h
# or Sources/some_file.h. Hence it wiill contain a '/'. So the string
# can be split at '/' to get the header file name.
if "/" in hdr_filename:
hdr_filename = hdr_filename.split("/")[-1]
Expand All @@ -37,4 +38,3 @@ def strip_api_include_path_prefix(name, hdr_labels, prefix = ""):
> "$@"
""".format(prefix, hdr_label),
)

1 change: 1 addition & 0 deletions tensorflow_lite_support/ios/task/vision/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ objc_library(
"//tensorflow_lite_support/ios/task/processor:TFLClassificationResultHelpers",
"//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils",
"//tensorflow_lite_support/odml/ios/image:MLImage",
"@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have linked in the cormel_plugin target here. I am still getting the following error:
"Could not create CoreML plugin. Have you linked in the CoreML_plugin target?"

],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ objc_library(
"//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils",
"@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin",
],
copts = ["-std=c++14"],
)

ios_unit_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
==============================================================================*/
#import <XCTest/XCTest.h>

#import "third_party/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h"
#import "tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h"

#include "third_party/tensorflow_lite_support/c/task/vision/utils/frame_buffer_cpp_c_utils.h"
#include "third_party/tensorflow_lite_support/cc/task/vision/image_classifier.h"
#include "tensorflow_lite_support/c/task/vision/utils/frame_buffer_cpp_c_utils.h"
#include "tensorflow_lite_support/cc/task/vision/image_classifier.h"

using ImageClassifier = ::tflite::task::vision::ImageClassifier;
using ImageClassifierOptions = ::tflite::task::vision::ImageClassifierOptions;
Expand Down Expand Up @@ -47,12 +47,12 @@ - (void)testCoreMLDelegateCreationFailsWithNeuralEngine {
options.mutable_base_options()
->mutable_compute_settings()
->mutable_tflite_settings()
->set_delegate(::acceleration::Delegate::CORE_ML);
->set_delegate(tflite::proto::Delegate::CORE_ML);
options.mutable_base_options()
->mutable_compute_settings()
->mutable_tflite_settings()
->mutable_coreml_settings()
->set_enabled_devices(::acceleration::CoreMLDelegateSettings::DEVICES_ALL);
->set_enabled_devices(tflite::proto::CoreMLSettings::DEVICES_ALL);

// Creates the classifier.
tflite::support::StatusOr<std::unique_ptr<ImageClassifier>> image_classifier_status =
Expand Down