From c9a7767956c0d1725e9971d489a02994f4b96109 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 19 May 2022 16:03:57 +0530 Subject: [PATCH 01/39] Updated files --- tensorflow_lite_support/ios/BUILD | 53 +++++++++++++++++++ tensorflow_lite_support/ios/task/vision/BUILD | 44 +++++++++++++++ .../allowlist_TensorFlowLiteTaskText.txt | 0 .../vision/sources/TFLImageClassifierTest.h | 29 ++++++++++ .../vision/sources/TFLImageClassifierTest.mm | 49 +++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt create mode 100644 tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h create mode 100644 tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 6e3264804..fec044c85 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -92,6 +92,59 @@ tflite_ios_framework( ], ) +tflite_ios_framework( + name = "TensorFlowLiteTaskVisionTestC_framework", + hdrs = [ + ":base_options.h", + ":bounding_box.h", + ":category.h", + ":classification_options.h", + ":classification_result.h", + ":common.h", + ":frame_buffer.h", + ":image_classifier.h", + ], + allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", + bundle_name = "TensorFlowLiteTaskVisionC", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/c/task/vision:image_classifier", + "//tensorflow_lite_support/cc/task/vision:image_classifier", + ], +) + +objc_library( + name = "TFLCommon", + hdrs = [ + "sources/TFLCommon.h", + ], + module_name = "TFLCommon", + visibility = [ + "//tensorflow_lite_support:__subpackages__", + ], +) + +tflite_ios_framework( + name = "TensorFlowLiteTaskVisionTestC_framework", + hdrs = [ + ":base_options.h", + ":bounding_box.h", + ":category.h", + ":classification_options.h", + ":classification_result.h", + ":common.h", + ":frame_buffer.h", + ":image_classifier.h", + ], + allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", + bundle_name = "TensorFlowLiteTaskVisionC", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/c/task/vision:image_classifier", + "//tensorflow_lite_support/cc/task/vision:image_classifier", + ], +) + objc_library( name = "TFLCommon", hdrs = [ diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 0a756dc56..3698685b9 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -3,6 +3,21 @@ package( licenses = ["notice"], # Apache 2.0 ) +load( + "@org_tensorflow//tensorflow/lite/ios:ios.bzl", + "TFL_MINIMUM_OS_VERSION", + "tflite_ios_framework", +) +load( + "//tensorflow_lite_support/ios:ios.bzl", + "strip_c_api_include_path_prefix", +) + +# strip_c_api_include_path_prefix( +# name = "strip_c_api_include_path", +# hdr_labels = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest.h"], +# ) + objc_library( name = "TFLImageClassifier", srcs = [ @@ -72,3 +87,32 @@ objc_library( "//tensorflow_lite_support/odml/ios/image:MLImage", ], ) + +objc_library( + name = "TFLImageClassifierTest", + srcs = [ + "sources/TFLImageClassifierTest.mm", + ], + hdrs = [ + "sources/TFLImageClassifierTest.h", + ], + features = ["-layering_check"], + module_name = "TFLImageClassifierTest", + deps = [ + "//tensorflow_lite_support/cc/task/vision:image_classifier", + ], + copts = ["-ObjC++","-std=c++14"], +) + +tflite_ios_framework( + name = "TensorFlowLiteTaskImageClassifierTest_framework", + hdrs = [ + "sources/TFLImageClassifierTest.h", + ], + allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", + bundle_name = "TensorFlowLiteTaskImageClassifierTest", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest", + ], +) diff --git a/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt b/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h new file mode 100644 index 000000000..1dc7b80b3 --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h @@ -0,0 +1,29 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ==============================================================================*/ +#import + + +NS_ASSUME_NONNULL_BEGIN + +/** + * A TensorFlow Lite Task Image Classifiier. + */ +NS_SWIFT_NAME(ImageClassifierTest) +@interface TFLImageClassifierTest : NSObject + +-(BOOL)testClassifier; +@end + +NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm new file mode 100644 index 000000000..bac0fcdeb --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm @@ -0,0 +1,49 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ==============================================================================*/ + +#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h" +#include "tensorflow_lite_support/cc/task/vision/image_classifier.h" + +namespace { +using ImageClassifierCpp = ::tflite::task::vision::ImageClassifier; +using ImageClassifierOptionsCpp = + ::tflite::task::vision::ImageClassifierOptions; +using ::tflite::support::StatusOr; + + +} // namespace + +@interface TFLImageClassifierTest () +/** ImageClassifier backed by C API */ +// @property(nonatomic) TfLiteImageClassifier *imageClassifier; +@end + +@implementation TFLImageClassifierTest + +-(BOOL)testClassifier { + +ImageClassifierOptionsCpp cc_options; + + cc_options.mutable_base_options()->mutable_model_file()->set_file_name( + ""); + + StatusOr> classifier_status = + ImageClassifierCpp::CreateFromOptions(cc_options); + + return classifier_status.ok(); + +} + +@end From dc5c057fb426a9c77096f443d1eb71cce96c2a1b Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 26 May 2022 08:42:44 +0530 Subject: [PATCH 02/39] Updated files --- tensorflow_lite_support/ios/BUILD | 53 ---- .../TensorFlowLiteTaskVision.podspec.template | 6 +- tensorflow_lite_support/ios/task/vision/BUILD | 10 + .../ios/task/vision/apis/TFLTaskVision.h | 2 + .../TFLTaskVisionImageClassifierCPPTest.h | 17 ++ .../task/vision/apis/framework_cpp.modulemap | 4 + .../builds/build_ios_cpp_framework.sh | 238 ++++++++++++++++++ 7 files changed, 275 insertions(+), 55 deletions(-) create mode 100644 tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h create mode 100644 tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap create mode 100755 tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index fec044c85..6e3264804 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -92,59 +92,6 @@ tflite_ios_framework( ], ) -tflite_ios_framework( - name = "TensorFlowLiteTaskVisionTestC_framework", - hdrs = [ - ":base_options.h", - ":bounding_box.h", - ":category.h", - ":classification_options.h", - ":classification_result.h", - ":common.h", - ":frame_buffer.h", - ":image_classifier.h", - ], - allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", - bundle_name = "TensorFlowLiteTaskVisionC", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - "//tensorflow_lite_support/c/task/vision:image_classifier", - "//tensorflow_lite_support/cc/task/vision:image_classifier", - ], -) - -objc_library( - name = "TFLCommon", - hdrs = [ - "sources/TFLCommon.h", - ], - module_name = "TFLCommon", - visibility = [ - "//tensorflow_lite_support:__subpackages__", - ], -) - -tflite_ios_framework( - name = "TensorFlowLiteTaskVisionTestC_framework", - hdrs = [ - ":base_options.h", - ":bounding_box.h", - ":category.h", - ":classification_options.h", - ":classification_result.h", - ":common.h", - ":frame_buffer.h", - ":image_classifier.h", - ], - allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", - bundle_name = "TensorFlowLiteTaskVisionC", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - "//tensorflow_lite_support/c/task/vision:image_classifier", - "//tensorflow_lite_support/cc/task/vision:image_classifier", - ], -) - objc_library( name = "TFLCommon", hdrs = [ diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index 137d891e9..fc0bf03fa 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -26,7 +26,8 @@ Pod::Spec.new do |s| objc_dir + 'sources/TFLCommon.h', objc_core_dir + 'sources/TFLBaseOptions.h', objc_processor_dir + 'sources/{TFLClassificationOptions,TFLCategory,TFLClassificationResult,TFLDetectionResult,TFLSegmentationResult}.h', - objc_vision_dir + 'sources/*.h' + objc_vision_dir + 'sources/*.h', + "Frameworks/TensorFlowLiteTaskImageClassifierTest.framework/Headers/*.h" ] c_dir = root_dir_name + '/c/' @@ -48,6 +49,7 @@ Pod::Spec.new do |s| objc_vision_dir + 'sources/*', gml_image_dir + 'apis/*.h', gml_image_dir + 'sources/*' + "Frameworks/TensorFlowLiteTaskImageClassifierTest.framework/Headers/*.h" ] s.module_map = objc_vision_dir + 'apis/framework.modulemap' @@ -58,5 +60,5 @@ Pod::Spec.new do |s| } s.library = 'c++' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionC.framework' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionC.framework', 'Frameworks/TensorFlowLiteTaskImageClassifierTest.framework' end diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 3698685b9..5e21c4470 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -70,6 +70,7 @@ objc_library( name = "TFLImageSegmenter", srcs = [ "sources/TFLImageSegmenter.m", + ], hdrs = [ "sources/TFLImageSegmenter.h", @@ -108,11 +109,20 @@ tflite_ios_framework( name = "TensorFlowLiteTaskImageClassifierTest_framework", hdrs = [ "sources/TFLImageClassifierTest.h", + # "sources/TFLObjectDetector.h", + # "sources/TFLImageSegmenter.h", + # "sources/TFLImageClassifier.h", + # "sources/TFLImageClassifier.h", + # "//tensorflow_lite_support/ios/task/processor/sources/TFLCategory.h" + ], allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", bundle_name = "TensorFlowLiteTaskImageClassifierTest", minimum_os_version = TFL_MINIMUM_OS_VERSION, deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest", + # "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", + # "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", + # "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", ], ) diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h index 3eb4f4964..e5de4ed82 100644 --- a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h +++ b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h @@ -23,3 +23,5 @@ #import "TFLImageSegmenter.h" #import "TFLObjectDetector.h" #import "TFLSegmentationResult.h" +#import "TFLImageClassifierTest.h" + diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h new file mode 100644 index 000000000..7ed6d9083 --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h @@ -0,0 +1,17 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#import "TFLImageClassifierTest.h" + diff --git a/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap b/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap new file mode 100644 index 000000000..dd117ac09 --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap @@ -0,0 +1,4 @@ +framework module TensorFlowLiteTaskVision { + umbrella header "Frameworks/TensorFlowLiteTaskImageClassifierTest.framework/Headers/TensorFlowLiteTaskImageClassifierTests.h" + export * +} diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh new file mode 100755 index 000000000..c79ee8f2d --- /dev/null +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh @@ -0,0 +1,238 @@ +#!/usr/bin/env bash +# Copyright 2021 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +# Set the following variables as appropriate. +# * BAZEL: path to bazel. defaults to the first one available in PATH +# * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the +# * accepted values are TensorFlowLiteTaskVision, TensorFlowLiteTaskText. +# * TFLS_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev +# * IS_RELEASE_BUILD: set as true if this build should be a release build +# * ARCHIVE_FRAMEWORK: set as true if the framework should be archived +# * DEST_DIR: destination directory to which the framework will be copied + +set -ex + +if [[ "$(uname)" != "Darwin" ]]; then + echo "This build script only works on macOS." + exit 1 +fi + +BAZEL="${BAZEL:-$(which bazel)}" +TFLS_BUILD_VERSION=${TFLS_BUILD_VERSION:-0.0.1-dev} +TFLS_ROOT_DIR=$(git rev-parse --show-toplevel) + +if [[ ! -x "${BAZEL}" ]]; then + echo "bazel executable is not found." + exit 1 +fi + +if [ -z ${FRAMEWORK_NAME+x} ]; then + echo "Name of the iOS framework, which is to be built, must be set." + exit 1 +fi + +case $FRAMEWORK_NAME in + "TensorFlowLiteTaskVision"|"TensorFlowLiteTaskText") + ;; + *) + echo "Wrong framework name" + exit 1 + ;; +esac + +if [[ -z "${DEST_DIR+x}" || "${DEST_DIR}" == ${TFLS_ROOT_DIR}* ]]; then + echo "DEST_DIR variable must be set and not be under the repository root." + exit 1 +fi + + +# Builds the C API framework for the specified framework for iOS. +function build_c_api_framework { + "${BAZEL}" build -c opt --config=ios_fat \ + //tensorflow_lite_support/ios:$1C_framework +} + +function build_ios_api_framework { + "${BAZEL}" build -c opt --config=ios_fat \ + //tensorflow_lite_support/ios/task/vision:TensorFlowLiteTaskImageClassifierTest_framework + + # "${BAZEL}" build -c opt --config=ios_fat //tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest +} + +function create_framework_archive { + TARGET_FRAMEWORK_NAME="$1" + C_API_FRAMEWORK_NAME="$1C" + + TFLS_IOS_DIR=tensorflow_lite_support/ios + BAZEL_IOS_OUTDIR="bazel-bin/${TFLS_IOS_DIR}" + + # Change to the Bazel iOS output directory. + pushd "${BAZEL_IOS_OUTDIR}" + + # Create the temporary directory for the given framework. + ARCHIVE_NAME="${TARGET_FRAMEWORK_NAME}-${TFLS_BUILD_VERSION}" + TFLS_TMPDIR="$(mktemp -d)" + + # Unzip the framework into the appropriate directory structure for CocoaPods. + # The final archive should contain the C API framework as a vendored framework + # as well as all the Obj-C source code and the header files. + # + # The directory structure will be like: + # + # ${TFLS_TMPDIR}/ + # |-- tensorflow_lite_support/ + # | |-- c/ + # | | +-- + # | +-- ios/ + # | +-- + # +-- Frameworks/ + # +-- TensorFlowLiteTaskTextC.framework + # + + # ----- (1) Copy source files ----- + pushd "${TFLS_ROOT_DIR}" + + # Set Source files and iOS header files which are to be stripped off header + # prefixes, to be archived along with the static framework. + case $FRAMEWORK_NAME in + "TensorFlowLiteTaskVision") + # # SRC_PATTERNS=" + # # */c/common.h + # # */c/task/core/base_options.h + # # */c/task/processor/category.h + # # */c/task/processor/bounding_box.h + # # */c/task/processor/classification_options.h + # # */c/task/processor/classification_result.h + # # */c/task/processor/detection_result.h + # # */c/task/processor/segmentation_result.h + # # */c/task/vision/image_classifier.h + # # */c/task/vision/object_detector.h + # # */c/task/vision/image_segmenter.h + # # */c/task/vision/core/*.h + # # */ios/sources/* + # # */ios/task/core/sources/* + # # */ios/task/processor/sources/* + # # */ios/task/vision/sources/* + # # */ios/task/vision/apis/* + # # */ios/task/vision/*/sources/* + # # */odml/ios/image/apis/*.h + # # */odml/ios/image/sources/*.m + # # " + + # # IOS_HEADER_PATTERNS=" + # # */ios/task/vision/apis/*.h + # # */ios/task/vision/sources/TFLImageClassifierTest.h + # # " + # IOS_HEADER_PATTERNS=" + # */ios/task/vision/sources/TFLImageClassifierTest.h + # " + ;; + "TensorFlowLiteTaskText") + SRC_PATTERNS=" + */c/task/text/*.h + */ios/task/text/*/Sources/* + */ios/task/text/apis/* + " + + IOS_HEADER_PATTERNS=" + */ios/task/text/*/Sources/*.h + " + ;; + *) + echo "FRAMEWORK_NAME provided is not in the list of buildable frameworks. + The accepted values are TensorFlowLiteTaskVision, + TensorFlowLiteTaskText" + exit 1 + ;; + esac + + # # List of individual files obtained from the patterns above. + # SRC_FILES=$(xargs -n1 find * -wholename <<< "${SRC_PATTERNS}" | sort | uniq) + + # # Copy source files with the intermediate directories preserved. + # xargs -n1 -I{} rsync -R {} "${TFLS_TMPDIR}" <<< "${SRC_FILES}" + + # Copy the license file to TFLS_TMPDIR + cp "${TFLS_ROOT_DIR}/LICENSE" ${TFLS_TMPDIR} + + popd + + pushd "${TFLS_ROOT_DIR}" + + # List of individual files obtained from the patterns above. +# IOS_HEADER_FILES=$(xargs -n1 find * -wholename <<< "${IOS_HEADER_PATTERNS}" | sort | uniq) +# popd + +# # The iOS headers should be stripped off the path prefixes in the #imports. +# # This is required for the cocoapods to build fine since the header files in +# # an iOS framework cannot be organised in multilevel directories. +# for filename in ${IOS_HEADER_FILES} +# do +# LAST_PATH_COMPONENT=$(basename ${filename}) +# FULL_SOURCE_PATH="$TFLS_ROOT_DIR/$filename" +# FULL_DEST_PATH="$TFLS_TMPDIR/$filename" +# sed -E 's|#import ".+\/([^/]+.h)"|#import "\1"|' $FULL_SOURCE_PATH > $FULL_DEST_PATH +# done + + # ----- (2) Unzip the prebuilt C API framework ----- + # unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks + unzip "bazel-bin/tensorflow_lite_support/ios/task/vision/TensorFlowLiteTaskImageClassifierTest_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks + + cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap" ${TFLS_TMPDIR} + # cp "${TFLS_ROOT_DIR}/bazel-bin/tensorflow_lite_support/ios/task/vision/libTFLImageClassifierTest.a" ${TFLS_TMPDIR} + # cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/libTFLImageClassifierTest.a" ${TFLS_TMPDIR} + + + # unzip "task/vision/libTFLImageClassifierTest.a" -d "${TFLS_TMPDIR}"/Frameworks + + # ----- (3) Move the framework to the destination ----- + if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then + TARGET_DIR="$(realpath "${TARGET_FRAMEWORK_NAME}")" + + # Create the framework archive directory. + if [[ "${IS_RELEASE_BUILD}" == true ]]; then + # Get the first 16 bytes of the sha256 checksum of the root directory. + SHA256_CHECKSUM=$(find "${TFLS_TMPDIR}" -type f -print0 | xargs -0 shasum -a 256 | sort | shasum -a 256 | cut -c1-16) + FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}/${SHA256_CHECKSUM}" + else + FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}" + fi + mkdir -p "${FRAMEWORK_ARCHIVE_DIR}" + + # Zip up the framework and move to the archive directory. + pushd "${TFLS_TMPDIR}" + TFLS_ARCHIVE_FILE="${ARCHIVE_NAME}.tar.gz" + tar -cvzf "${TFLS_ARCHIVE_FILE}" . + mv "${TFLS_ARCHIVE_FILE}" "${FRAMEWORK_ARCHIVE_DIR}" + popd + + # Move the target directory to the Kokoro artifacts directory. + mv "${TARGET_DIR}" "$(realpath "${DEST_DIR}")"/ + else + rsync -r "${TFLS_TMPDIR}/" "$(realpath "${DEST_DIR}")/" + fi + + # Clean up the temporary directory for the framework. + rm -rf "${TFLS_TMPDIR}" + + # Pop back to the TFLS root directory. + popd +} + +cd "${TFLS_ROOT_DIR}" +build_ios_api_framework +# build_c_api_framework $FRAMEWORK_NAME +create_framework_archive $FRAMEWORK_NAME From 95522de755b361ac52738bc56cdabaf43f2bf6c2 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 2 Jun 2022 14:03:18 +0530 Subject: [PATCH 03/39] Updated files --- tensorflow_lite_support/ios/ios.bzl | 30 ++++ tensorflow_lite_support/ios/task/vision/BUILD | 56 ++++++- .../allowlist_TensorFlowLiteTaskText.txt | 1 + .../vision/sources/TFLImageClassifierTest.mm | 8 +- .../test/task/vision/image_classifier/BUILD | 20 +++ .../TFLImageClassifierCPPTests.m | 140 ++++++++++++++++++ tensorflow_lite_support/odml/ios/image/BUILD | 2 +- .../builds/build_ios_cpp_framework.sh | 6 +- 8 files changed, 250 insertions(+), 13 deletions(-) create mode 100644 tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m diff --git a/tensorflow_lite_support/ios/ios.bzl b/tensorflow_lite_support/ios/ios.bzl index cb8c92ac2..ab87777ff 100644 --- a/tensorflow_lite_support/ios/ios.bzl +++ b/tensorflow_lite_support/ios/ios.bzl @@ -28,3 +28,33 @@ def strip_c_api_include_path_prefix(name, hdr_labels, prefix = ""): > "$@" """.format(prefix, hdr_label), ) + +def strip_ios_api_include_path_prefix(name, hdr_labels, prefix = ""): + """Create modified header files with the common.h include path stripped out. + + Args: + name: The name to be used as a prefix to the generated genrules. + hdr_labels: List of header labels to strip out the include path. Each + label must end with a colon followed by the header file name. + prefix: Optional prefix path to prepend to the header inclusion path. + """ + + for hdr_label in hdr_labels: + hdr_filename = hdr_label.split(":")[-1] + if hdr_filename.startswith("sources/"): + hdr_filename = hdr_filename[len("sources/"):] + if hdr_filename.startswith("apis/"): + hdr_filename = hdr_filename[len("apis/"):] + + hdr_basename = hdr_filename.split(".")[0] + native.genrule( + name = "{}_{}".format(name, hdr_basename), + srcs = [hdr_label], + outs = [hdr_filename], + cmd = """ + sed 's|#import ".*/\\([^/]\\{{1,\\}}\\.h\\)"|#import "{}\\1"|'\ + "$(location {})"\ + > "$@" + """.format(prefix, hdr_label), + ) + diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 5e21c4470..7f1582944 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -11,12 +11,37 @@ load( load( "//tensorflow_lite_support/ios:ios.bzl", "strip_c_api_include_path_prefix", + "strip_ios_api_include_path_prefix" ) +load( + "@build_bazel_rules_apple//apple:ios.bzl", + "ios_static_framework", + "ios_unit_test", +) + +# exports_files([ +# "sources/TFLImageClassifier.h", +# ]) + + # strip_c_api_include_path_prefix( # name = "strip_c_api_include_path", # hdr_labels = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest.h"], # ) +strip_ios_api_include_path_prefix( + name = "strip_ios_api_include_path", + hdr_labels = [ + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageClassifier.h", + "//tensorflow_lite_support/ios/task/core:sources/TFLBaseOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLCategory.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationResult.h", + "//tensorflow_lite_support/ios:sources/TFLCommon.h", + "//tensorflow_lite_support/odml/ios/image:apis/GMLImage.h" + + ], +) objc_library( name = "TFLImageClassifier", @@ -26,7 +51,7 @@ objc_library( hdrs = [ "sources/TFLImageClassifier.h", ], - features = ["-layering_check"], + # features = ["-layering_check"], module_name = "TFLImageClassifier", deps = [ "//tensorflow_lite_support/c/task/vision:image_classifier", @@ -105,8 +130,8 @@ objc_library( copts = ["-ObjC++","-std=c++14"], ) -tflite_ios_framework( - name = "TensorFlowLiteTaskImageClassifierTest_framework", +ios_static_framework( + name = "TensorFlowLiteCPPTest_framework", hdrs = [ "sources/TFLImageClassifierTest.h", # "sources/TFLObjectDetector.h", @@ -116,8 +141,8 @@ tflite_ios_framework( # "//tensorflow_lite_support/ios/task/processor/sources/TFLCategory.h" ], - allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", - bundle_name = "TensorFlowLiteTaskImageClassifierTest", + # allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", + bundle_name = "TensorFlowLiteCPP", minimum_os_version = TFL_MINIMUM_OS_VERSION, deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest", @@ -126,3 +151,24 @@ tflite_ios_framework( # "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", ], ) + +ios_static_framework( + name = "TensorFlowLiteTaskImageClassifier_framework", + hdrs = [ + ":TFLImageClassifier.h", + ":TFLBaseOptions.h", + ":TFLClassificationOptions.h", + ":TFLClassificationResult.h", + ":TFLCategory.h", + ":TFLCommon.h", + ":GMLImage.h", + ], + #allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", + bundle_name = "TensorFlowLiteTaskImageClassifierObjC", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", + "//tensorflow_lite_support/ios/task/processor:TFLClassificationOptionsHelpers", + + ], +) diff --git a/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt b/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt index e69de29bb..ad3fe93cb 100644 --- a/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt +++ b/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt @@ -0,0 +1 @@ +_TFL* \ No newline at end of file diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm index bac0fcdeb..6f2160680 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm @@ -25,10 +25,10 @@ } // namespace -@interface TFLImageClassifierTest () -/** ImageClassifier backed by C API */ -// @property(nonatomic) TfLiteImageClassifier *imageClassifier; -@end +// @interface TFLImageClassifierTest () +// /** ImageClassifier backed by C API */ +// // @property(nonatomic) TfLiteImageClassifier *imageClassifier; +// @end @implementation TFLImageClassifierTest diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD index 06da0ea6b..0614c2f20 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD @@ -84,3 +84,23 @@ ios_unit_test( ":TFLImageClassifierCoreMLDelegateTestLibrary", ], ) + +objc_library( + name = "TFLImageClassifierCPPTestLibrary", + testonly = 1, + srcs = ["TFLImageClassifierCPPTests.m"], + tags = TFL_DEFAULT_TAGS, + deps = [ + "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest", + ], +) + +ios_unit_test( + name = "TFLImageClassifierCPPTest", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + runner = tflite_ios_lab_runner("IOS_LATEST"), + tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS, + deps = [ + ":TFLImageClassifierCPPTestLibrary", + ], +) diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m b/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m new file mode 100644 index 000000000..7d42da9eb --- /dev/null +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m @@ -0,0 +1,140 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ==============================================================================*/ +#import + +#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h" +// #import "tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface TFLImageClassifierCPPTests : XCTestCase +@property(nonatomic, nullable) NSString *modelPath; +@end + +@implementation TFLImageClassifierCPPTests + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the + // class. + [super setUp]; +// self.modelPath = [[NSBundle bundleForClass:self.class] pathForResource:@"mobilenet_v2_1.0_224" +// ofType:@"tflite"]; +// XCTAssertNotNil(self.modelPath); +} + +- (void)testSuccessfullImageInferenceOnMLImageWithUIImage { + TFLImageClassifierTest *test = [[TFLImageClassifierTest alloc] init]; + [test testClassifier]; +// TFLImageClassifierOptions *imageClassifierOptions = +// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; + +// TFLImageClassifier *imageClassifier = +// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; +// XCTAssertNotNil(imageClassifier); + +// GMLImage *gmlImage = +// [GMLImage imageFromBundleWithClass:self.class fileName:@"burger" ofType:@"jpg"]; +// XCTAssertNotNil(gmlImage); + +// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage +// error:nil]; +// XCTAssertTrue(classificationResults.classifications.count > 0); +// XCTAssertTrue(classificationResults.classifications[0].categories.count > 0); + +// TFLCategory *category = classificationResults.classifications[0].categories[0]; +// XCTAssertTrue([category.label isEqual:@"cheeseburger"]); +// // TODO: match the score as image_classifier_test.cc +// XCTAssertEqualWithAccuracy(category.score, 0.748976, 0.001); +} + +// - (void)testModelOptionsWithMaxResults { +// TFLImageClassifierOptions *imageClassifierOptions = +// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; +// int maxResults = 3; +// imageClassifierOptions.classificationOptions.maxResults = maxResults; + +// TFLImageClassifier *imageClassifier = +// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; +// XCTAssertNotNil(imageClassifier); + +// GMLImage *gmlImage = +// [GMLImage imageFromBundleWithClass:self.class fileName:@"burger" ofType:@"jpg"]; +// XCTAssertNotNil(gmlImage); + +// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage +// error:nil]; +// XCTAssertTrue(classificationResults.classifications.count > 0); +// XCTAssertLessThanOrEqual(classificationResults.classifications[0].categories.count, maxResults); + +// TFLCategory *category = classificationResults.classifications[0].categories[0]; +// XCTAssertTrue([category.label isEqual:@"cheeseburger"]); +// // TODO: match the score as image_classifier_test.cc +// XCTAssertEqualWithAccuracy(category.score, 0.748976, 0.001); +// } + +// - (void)testInferenceWithBoundingBox { +// TFLImageClassifierOptions *imageClassifierOptions = +// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; +// int maxResults = 3; +// imageClassifierOptions.classificationOptions.maxResults = maxResults; + +// TFLImageClassifier *imageClassifier = +// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; +// XCTAssertNotNil(imageClassifier); + +// GMLImage *gmlImage = +// [GMLImage imageFromBundleWithClass:self.class fileName:@"multi_objects" ofType:@"jpg"]; +// XCTAssertNotNil(gmlImage); + +// CGRect roi = CGRectMake(406, 110, 148, 153); +// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage +// regionOfInterest:roi +// error:nil]; +// XCTAssertTrue(classificationResults.classifications.count > 0); +// XCTAssertTrue(classificationResults.classifications[0].categories.count > 0); + +// TFLCategory *category = classificationResults.classifications[0].categories[0]; +// // TODO: match the label and score as image_classifier_test.cc +// // XCTAssertTrue([category.label isEqual:@"soccer ball"]); +// // XCTAssertEqualWithAccuracy(category.score, 0.256512, 0.001); +// } + +// - (void)testInferenceWithRGBAImage { +// TFLImageClassifierOptions *imageClassifierOptions = +// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; + +// TFLImageClassifier *imageClassifier = +// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; +// XCTAssertNotNil(imageClassifier); + +// GMLImage *gmlImage = +// [GMLImage imageFromBundleWithClass:self.class fileName:@"sparrow" ofType:@"png"]; +// XCTAssertNotNil(gmlImage); + +// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage +// error:nil]; +// XCTAssertTrue(classificationResults.classifications.count > 0); +// XCTAssertTrue(classificationResults.classifications[0].categories.count > 0); + +// TFLCategory *category = classificationResults.classifications[0].categories[0]; +// XCTAssertTrue([category.label isEqual:@"junco"]); +// // TODO: inspect if score is correct. Better to test againest "burger", because we know the +// // expected result for "burger.jpg". +// XCTAssertEqualWithAccuracy(category.score, 0.253016, 0.001); +//} + +@end + +NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/odml/ios/image/BUILD b/tensorflow_lite_support/odml/ios/image/BUILD index 24fff353f..857e06558 100644 --- a/tensorflow_lite_support/odml/ios/image/BUILD +++ b/tensorflow_lite_support/odml/ios/image/BUILD @@ -15,7 +15,7 @@ load( ) package( - default_visibility = ["//visibility:private"], + default_visibility = ["//tensorflow_lite_support:internal"], licenses = ["notice"], # Apache 2.0 ) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh index c79ee8f2d..693b588ea 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh @@ -67,7 +67,7 @@ function build_c_api_framework { function build_ios_api_framework { "${BAZEL}" build -c opt --config=ios_fat \ - //tensorflow_lite_support/ios/task/vision:TensorFlowLiteTaskImageClassifierTest_framework + //tensorflow_lite_support/ios/task/vision:TTensorFlowLiteCPPTest_framework # "${BAZEL}" build -c opt --config=ios_fat //tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest } @@ -189,9 +189,9 @@ function create_framework_archive { # ----- (2) Unzip the prebuilt C API framework ----- # unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks - unzip "bazel-bin/tensorflow_lite_support/ios/task/vision/TensorFlowLiteTaskImageClassifierTest_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks + unzip "bazel-bin/tensorflow_lite_support/ios/task/vision/TensorFlowLiteCPPTest_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks - cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap" ${TFLS_TMPDIR} + # cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap" ${TFLS_TMPDIR} # cp "${TFLS_ROOT_DIR}/bazel-bin/tensorflow_lite_support/ios/task/vision/libTFLImageClassifierTest.a" ${TFLS_TMPDIR} # cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/libTFLImageClassifierTest.a" ${TFLS_TMPDIR} From 5468a420e10480c487be93bbc2162e82c88d2841 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:13:24 +0530 Subject: [PATCH 04/39] Added files --- tensorflow_lite_support/ios/BUILD | 26 ++ .../TensorFlowLiteTaskVisionObjCPP.podspec | 20 ++ tensorflow_lite_support/ios/ios.bzl | 13 +- tensorflow_lite_support/ios/task/vision/BUILD | 93 +------ .../allowlist_TensorFlowLiteTaskText.txt | 1 - .../TFLTaskVisionImageClassifierCPPTest.h | 17 -- .../task/vision/apis/framework_cpp.modulemap | 4 - .../vision/sources/TFLImageClassifierTest.mm | 49 ---- ...ageClassifierTest.h => TFLImageEmbedder.h} | 6 +- .../task/vision/sources/TFLImageEmbedder.mm | 52 ++++ .../TFLImageClassifierCPPTests.m | 140 ----------- .../ios/test/task/vision/image_embedder/BUILD | 35 +++ .../image_embedder/TFLImageEmbedderTests.m | 42 ++++ .../builds/build_ios_cpp_framework.sh | 238 ------------------ .../ci_build/builds/build_ios_framework.sh | 71 +++--- .../builds/build_obj_cpp_framework.sh | 127 ++++++++++ 16 files changed, 358 insertions(+), 576 deletions(-) create mode 100644 tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec delete mode 100644 tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt delete mode 100644 tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h delete mode 100644 tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap delete mode 100644 tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm rename tensorflow_lite_support/ios/task/vision/sources/{TFLImageClassifierTest.h => TFLImageEmbedder.h} (86%) create mode 100644 tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm delete mode 100644 tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m create mode 100644 tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD create mode 100644 tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m delete mode 100755 tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh create mode 100755 tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 6e3264804..75ff062c2 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -8,6 +8,12 @@ load( load( "//tensorflow_lite_support/ios:ios.bzl", "strip_c_api_include_path_prefix", + "strip_ios_api_include_path_prefix", +) + +load( + "@build_bazel_rules_apple//apple:ios.bzl", + "ios_static_framework", ) package( @@ -37,6 +43,13 @@ strip_c_api_include_path_prefix( ], ) +strip_ios_api_include_path_prefix( + name = "strip_ios_api_include_path", + hdr_labels = [ + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageEmbedder.h", + ], +) + # This target builds a monolithic static framework for the TFLite Text API, # which includes the TFLite runtime in it. # @@ -120,3 +133,16 @@ objc_library( "//tensorflow_lite_support/ios:TFLCommon", ], ) + +ios_static_framework( + name = "TensorFlowLiteTaskVisionObjCPP_framework", + hdrs = [ + ":TFLImageEmbedder.h", + ], + bundle_name = "TensorFlowLiteTaskVisionObjCPP", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/ios/task/vision:TFLImageEmbedder", + ], +) + diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec b/tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec new file mode 100644 index 000000000..ecca79466 --- /dev/null +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec @@ -0,0 +1,20 @@ +Pod::Spec.new do |s| + s.name = 'TensorFlowLiteTaskVisionObjCPP' + s.version = '0.1.1' + s.authors = 'Google Inc.' + s.license = { :type => 'Apache',:file => "LICENSE"} + s.homepage = 'https://github.com/tensorflow/tflite-support' + s.source = { :http => 'https://dl.dropboxusercontent.com/s/5v2775z785b8114/TensorFlowLiteTaskVisionObjCPP-0.1.1-dev.tar.gz?dl=0' } + s.summary = 'TensorFlow Lite Task Library - Vision' + s.description = 'The Computer Vision APIs of the TFLite Task Library' + + s.ios.deployment_target = '10.0' + + s.module_name = 'TensorFlowLiteTaskVisionObjCPP' + s.static_framework = true + s.pod_target_xcconfig = { + 'VALID_ARCHS' => 'x86_64, arm64, armv7', + } + s.library = 'c++' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionObjCPP.framework' +end diff --git a/tensorflow_lite_support/ios/ios.bzl b/tensorflow_lite_support/ios/ios.bzl index ab87777ff..cf2d2207a 100644 --- a/tensorflow_lite_support/ios/ios.bzl +++ b/tensorflow_lite_support/ios/ios.bzl @@ -29,8 +29,12 @@ def strip_c_api_include_path_prefix(name, hdr_labels, prefix = ""): """.format(prefix, hdr_label), ) +# 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 iOS API header files imported by +# other iOS API header files. def strip_ios_api_include_path_prefix(name, hdr_labels, prefix = ""): - """Create modified header files with the common.h include path stripped out. + """Create modified header files with the import path stripped out. Args: name: The name to be used as a prefix to the generated genrules. @@ -38,14 +42,9 @@ def strip_ios_api_include_path_prefix(name, hdr_labels, prefix = ""): label must end with a colon followed by the header file name. prefix: Optional prefix path to prepend to the header inclusion path. """ - for hdr_label in hdr_labels: hdr_filename = hdr_label.split(":")[-1] - if hdr_filename.startswith("sources/"): - hdr_filename = hdr_filename[len("sources/"):] - if hdr_filename.startswith("apis/"): - hdr_filename = hdr_filename[len("apis/"):] - + hdr_filename = hdr_filename.split("/")[-1] hdr_basename = hdr_filename.split(".")[0] native.genrule( name = "{}_{}".format(name, hdr_basename), diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 7f1582944..1cf60b8c3 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -3,46 +3,6 @@ package( licenses = ["notice"], # Apache 2.0 ) -load( - "@org_tensorflow//tensorflow/lite/ios:ios.bzl", - "TFL_MINIMUM_OS_VERSION", - "tflite_ios_framework", -) -load( - "//tensorflow_lite_support/ios:ios.bzl", - "strip_c_api_include_path_prefix", - "strip_ios_api_include_path_prefix" -) - -load( - "@build_bazel_rules_apple//apple:ios.bzl", - "ios_static_framework", - "ios_unit_test", -) - -# exports_files([ -# "sources/TFLImageClassifier.h", -# ]) - - -# strip_c_api_include_path_prefix( -# name = "strip_c_api_include_path", -# hdr_labels = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest.h"], -# ) -strip_ios_api_include_path_prefix( - name = "strip_ios_api_include_path", - hdr_labels = [ - "//tensorflow_lite_support/ios/task/vision:sources/TFLImageClassifier.h", - "//tensorflow_lite_support/ios/task/core:sources/TFLBaseOptions.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationOptions.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLCategory.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationResult.h", - "//tensorflow_lite_support/ios:sources/TFLCommon.h", - "//tensorflow_lite_support/odml/ios/image:apis/GMLImage.h" - - ], -) - objc_library( name = "TFLImageClassifier", srcs = [ @@ -115,60 +75,17 @@ objc_library( ) objc_library( - name = "TFLImageClassifierTest", + name = "TFLImageEmbedder", srcs = [ - "sources/TFLImageClassifierTest.mm", + "sources/TFLImageEmbedder.mm", ], hdrs = [ - "sources/TFLImageClassifierTest.h", + "sources/TFLImageEmbedder.h", ], features = ["-layering_check"], - module_name = "TFLImageClassifierTest", + module_name = "TFLImageEmbedder", deps = [ - "//tensorflow_lite_support/cc/task/vision:image_classifier", + "//tensorflow_lite_support/cc/task/vision:image_embedder", ], copts = ["-ObjC++","-std=c++14"], ) - -ios_static_framework( - name = "TensorFlowLiteCPPTest_framework", - hdrs = [ - "sources/TFLImageClassifierTest.h", - # "sources/TFLObjectDetector.h", - # "sources/TFLImageSegmenter.h", - # "sources/TFLImageClassifier.h", - # "sources/TFLImageClassifier.h", - # "//tensorflow_lite_support/ios/task/processor/sources/TFLCategory.h" - - ], - # allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", - bundle_name = "TensorFlowLiteCPP", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest", - # "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", - # "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", - # "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", - ], -) - -ios_static_framework( - name = "TensorFlowLiteTaskImageClassifier_framework", - hdrs = [ - ":TFLImageClassifier.h", - ":TFLBaseOptions.h", - ":TFLClassificationOptions.h", - ":TFLClassificationResult.h", - ":TFLCategory.h", - ":TFLCommon.h", - ":GMLImage.h", - ], - #allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskText.txt", - bundle_name = "TensorFlowLiteTaskImageClassifierObjC", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", - "//tensorflow_lite_support/ios/task/processor:TFLClassificationOptionsHelpers", - - ], -) diff --git a/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt b/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt deleted file mode 100644 index ad3fe93cb..000000000 --- a/tensorflow_lite_support/ios/task/vision/allowlist_TensorFlowLiteTaskText.txt +++ /dev/null @@ -1 +0,0 @@ -_TFL* \ No newline at end of file diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h deleted file mode 100644 index 7ed6d9083..000000000 --- a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVisionImageClassifierCPPTest.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#import "TFLImageClassifierTest.h" - diff --git a/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap b/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap deleted file mode 100644 index dd117ac09..000000000 --- a/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -framework module TensorFlowLiteTaskVision { - umbrella header "Frameworks/TensorFlowLiteTaskImageClassifierTest.framework/Headers/TensorFlowLiteTaskImageClassifierTests.h" - export * -} diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm deleted file mode 100644 index 6f2160680..000000000 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.mm +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ==============================================================================*/ - -#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h" -#include "tensorflow_lite_support/cc/task/vision/image_classifier.h" - -namespace { -using ImageClassifierCpp = ::tflite::task::vision::ImageClassifier; -using ImageClassifierOptionsCpp = - ::tflite::task::vision::ImageClassifierOptions; -using ::tflite::support::StatusOr; - - -} // namespace - -// @interface TFLImageClassifierTest () -// /** ImageClassifier backed by C API */ -// // @property(nonatomic) TfLiteImageClassifier *imageClassifier; -// @end - -@implementation TFLImageClassifierTest - --(BOOL)testClassifier { - -ImageClassifierOptionsCpp cc_options; - - cc_options.mutable_base_options()->mutable_model_file()->set_file_name( - ""); - - StatusOr> classifier_status = - ImageClassifierCpp::CreateFromOptions(cc_options); - - return classifier_status.ok(); - -} - -@end diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h similarity index 86% rename from tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h rename to tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h index 1dc7b80b3..a4bf963f2 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h @@ -20,10 +20,10 @@ NS_ASSUME_NONNULL_BEGIN /** * A TensorFlow Lite Task Image Classifiier. */ -NS_SWIFT_NAME(ImageClassifierTest) -@interface TFLImageClassifierTest : NSObject +NS_SWIFT_NAME(ImageEmbedder) +@interface TFLImageEmbedder : NSObject --(BOOL)testClassifier; +- (instancetype)initWithModelPath:(NSString *)modelPath; @end NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm new file mode 100644 index 000000000..5926fe708 --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm @@ -0,0 +1,52 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ==============================================================================*/ + +#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h" +#include "tensorflow_lite_support/cc/task/vision/image_embedder.h" + +namespace { +using ImageEmbedderCpp = ::tflite::task::vision::ImageEmbedder; +using ImageEmbedderOptionsCpp = + ::tflite::task::vision::ImageEmbedderOptions; +using ::tflite::support::StatusOr; + + +} + +@implementation TFLImageEmbedder { + std::unique_ptr cppImageEmbedder; +} + +- (instancetype)initWithModelPath:(NSString *)modelPath { + self = [super init]; + if (self) { + ImageEmbedderOptionsCpp cc_options; + + cc_options.mutable_model_file_with_metadata()->set_file_name(modelPath.UTF8String); + + StatusOr> embedder_status = + ImageEmbedderCpp::CreateFromOptions(cc_options); + + if (embedder_status.ok()) { + cppImageEmbedder = std::move(embedder_status.value()); + } + else { + return nil; + } + } + return self; +} + +@end diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m b/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m deleted file mode 100644 index 7d42da9eb..000000000 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCPPTests.m +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ==============================================================================*/ -#import - -#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifierTest.h" -// #import "tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface TFLImageClassifierCPPTests : XCTestCase -@property(nonatomic, nullable) NSString *modelPath; -@end - -@implementation TFLImageClassifierCPPTests - -- (void)setUp { - // Put setup code here. This method is called before the invocation of each test method in the - // class. - [super setUp]; -// self.modelPath = [[NSBundle bundleForClass:self.class] pathForResource:@"mobilenet_v2_1.0_224" -// ofType:@"tflite"]; -// XCTAssertNotNil(self.modelPath); -} - -- (void)testSuccessfullImageInferenceOnMLImageWithUIImage { - TFLImageClassifierTest *test = [[TFLImageClassifierTest alloc] init]; - [test testClassifier]; -// TFLImageClassifierOptions *imageClassifierOptions = -// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; - -// TFLImageClassifier *imageClassifier = -// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; -// XCTAssertNotNil(imageClassifier); - -// GMLImage *gmlImage = -// [GMLImage imageFromBundleWithClass:self.class fileName:@"burger" ofType:@"jpg"]; -// XCTAssertNotNil(gmlImage); - -// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage -// error:nil]; -// XCTAssertTrue(classificationResults.classifications.count > 0); -// XCTAssertTrue(classificationResults.classifications[0].categories.count > 0); - -// TFLCategory *category = classificationResults.classifications[0].categories[0]; -// XCTAssertTrue([category.label isEqual:@"cheeseburger"]); -// // TODO: match the score as image_classifier_test.cc -// XCTAssertEqualWithAccuracy(category.score, 0.748976, 0.001); -} - -// - (void)testModelOptionsWithMaxResults { -// TFLImageClassifierOptions *imageClassifierOptions = -// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; -// int maxResults = 3; -// imageClassifierOptions.classificationOptions.maxResults = maxResults; - -// TFLImageClassifier *imageClassifier = -// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; -// XCTAssertNotNil(imageClassifier); - -// GMLImage *gmlImage = -// [GMLImage imageFromBundleWithClass:self.class fileName:@"burger" ofType:@"jpg"]; -// XCTAssertNotNil(gmlImage); - -// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage -// error:nil]; -// XCTAssertTrue(classificationResults.classifications.count > 0); -// XCTAssertLessThanOrEqual(classificationResults.classifications[0].categories.count, maxResults); - -// TFLCategory *category = classificationResults.classifications[0].categories[0]; -// XCTAssertTrue([category.label isEqual:@"cheeseburger"]); -// // TODO: match the score as image_classifier_test.cc -// XCTAssertEqualWithAccuracy(category.score, 0.748976, 0.001); -// } - -// - (void)testInferenceWithBoundingBox { -// TFLImageClassifierOptions *imageClassifierOptions = -// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; -// int maxResults = 3; -// imageClassifierOptions.classificationOptions.maxResults = maxResults; - -// TFLImageClassifier *imageClassifier = -// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; -// XCTAssertNotNil(imageClassifier); - -// GMLImage *gmlImage = -// [GMLImage imageFromBundleWithClass:self.class fileName:@"multi_objects" ofType:@"jpg"]; -// XCTAssertNotNil(gmlImage); - -// CGRect roi = CGRectMake(406, 110, 148, 153); -// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage -// regionOfInterest:roi -// error:nil]; -// XCTAssertTrue(classificationResults.classifications.count > 0); -// XCTAssertTrue(classificationResults.classifications[0].categories.count > 0); - -// TFLCategory *category = classificationResults.classifications[0].categories[0]; -// // TODO: match the label and score as image_classifier_test.cc -// // XCTAssertTrue([category.label isEqual:@"soccer ball"]); -// // XCTAssertEqualWithAccuracy(category.score, 0.256512, 0.001); -// } - -// - (void)testInferenceWithRGBAImage { -// TFLImageClassifierOptions *imageClassifierOptions = -// [[TFLImageClassifierOptions alloc] initWithModelPath:self.modelPath]; - -// TFLImageClassifier *imageClassifier = -// [TFLImageClassifier imageClassifierWithOptions:imageClassifierOptions error:nil]; -// XCTAssertNotNil(imageClassifier); - -// GMLImage *gmlImage = -// [GMLImage imageFromBundleWithClass:self.class fileName:@"sparrow" ofType:@"png"]; -// XCTAssertNotNil(gmlImage); - -// TFLClassificationResult *classificationResults = [imageClassifier classifyWithGMLImage:gmlImage -// error:nil]; -// XCTAssertTrue(classificationResults.classifications.count > 0); -// XCTAssertTrue(classificationResults.classifications[0].categories.count > 0); - -// TFLCategory *category = classificationResults.classifications[0].categories[0]; -// XCTAssertTrue([category.label isEqual:@"junco"]); -// // TODO: inspect if score is correct. Better to test againest "burger", because we know the -// // expected result for "burger.jpg". -// XCTAssertEqualWithAccuracy(category.score, 0.253016, 0.001); -//} - -@end - -NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD new file mode 100644 index 000000000..fb0d1167c --- /dev/null +++ b/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD @@ -0,0 +1,35 @@ +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") +load("@org_tensorflow//tensorflow/lite/ios:ios.bzl", "TFL_DEFAULT_TAGS", "TFL_DISABLED_SANITIZER_TAGS", "TFL_MINIMUM_OS_VERSION") +load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") +load("@org_tensorflow//tensorflow/lite:special_rules.bzl", "tflite_ios_lab_runner") + +package( + default_visibility = ["//visibility:private"], + licenses = ["notice"], # Apache 2.0 +) + + +objc_library( + name = "TFLImageEmbedderObjcTestLibrary", + testonly = 1, + srcs = ["TFLImageEmbedderTests.m"], + data = [ + "//tensorflow_lite_support/cc/test/testdata/task/vision:test_images", + "//tensorflow_lite_support/cc/test/testdata/task/vision:test_models", + ], + tags = TFL_DEFAULT_TAGS, + deps = [ + "//tensorflow_lite_support/ios/task/vision:TFLImageEmbedder", + "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", + ], +) + +ios_unit_test( + name = "TFLImageEmbedderObjcTest", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + runner = tflite_ios_lab_runner("IOS_LATEST"), + tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS, + deps = [ + ":TFLImageEmbedderObjcTestLibrary", + ], +) \ No newline at end of file diff --git a/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m b/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m new file mode 100644 index 000000000..537edbd38 --- /dev/null +++ b/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m @@ -0,0 +1,42 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ==============================================================================*/ +#import + +#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface TFLImageEmbedderTests : XCTestCase +@property(nonatomic, nullable) NSString *modelPath; +@end + +@implementation TFLImageEmbedderTests + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the + // class. + [super setUp]; + self.modelPath = [[NSBundle bundleForClass:self.class] pathForResource:@"mobilenet_v3_small_100_224_embedder" + ofType:@"tflite"]; + XCTAssertNotNil(self.modelPath); +} + +- (void)testInitSucceeds { + TFLImageEmbedder *embedder = [[TFLImageEmbedder alloc] initWithModelPath:self.modelPath]; + XCTAssertNotNil(embedder); +} +@end + +NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh deleted file mode 100755 index 693b588ea..000000000 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_cpp_framework.sh +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -# Set the following variables as appropriate. -# * BAZEL: path to bazel. defaults to the first one available in PATH -# * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the -# * accepted values are TensorFlowLiteTaskVision, TensorFlowLiteTaskText. -# * TFLS_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev -# * IS_RELEASE_BUILD: set as true if this build should be a release build -# * ARCHIVE_FRAMEWORK: set as true if the framework should be archived -# * DEST_DIR: destination directory to which the framework will be copied - -set -ex - -if [[ "$(uname)" != "Darwin" ]]; then - echo "This build script only works on macOS." - exit 1 -fi - -BAZEL="${BAZEL:-$(which bazel)}" -TFLS_BUILD_VERSION=${TFLS_BUILD_VERSION:-0.0.1-dev} -TFLS_ROOT_DIR=$(git rev-parse --show-toplevel) - -if [[ ! -x "${BAZEL}" ]]; then - echo "bazel executable is not found." - exit 1 -fi - -if [ -z ${FRAMEWORK_NAME+x} ]; then - echo "Name of the iOS framework, which is to be built, must be set." - exit 1 -fi - -case $FRAMEWORK_NAME in - "TensorFlowLiteTaskVision"|"TensorFlowLiteTaskText") - ;; - *) - echo "Wrong framework name" - exit 1 - ;; -esac - -if [[ -z "${DEST_DIR+x}" || "${DEST_DIR}" == ${TFLS_ROOT_DIR}* ]]; then - echo "DEST_DIR variable must be set and not be under the repository root." - exit 1 -fi - - -# Builds the C API framework for the specified framework for iOS. -function build_c_api_framework { - "${BAZEL}" build -c opt --config=ios_fat \ - //tensorflow_lite_support/ios:$1C_framework -} - -function build_ios_api_framework { - "${BAZEL}" build -c opt --config=ios_fat \ - //tensorflow_lite_support/ios/task/vision:TTensorFlowLiteCPPTest_framework - - # "${BAZEL}" build -c opt --config=ios_fat //tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest -} - -function create_framework_archive { - TARGET_FRAMEWORK_NAME="$1" - C_API_FRAMEWORK_NAME="$1C" - - TFLS_IOS_DIR=tensorflow_lite_support/ios - BAZEL_IOS_OUTDIR="bazel-bin/${TFLS_IOS_DIR}" - - # Change to the Bazel iOS output directory. - pushd "${BAZEL_IOS_OUTDIR}" - - # Create the temporary directory for the given framework. - ARCHIVE_NAME="${TARGET_FRAMEWORK_NAME}-${TFLS_BUILD_VERSION}" - TFLS_TMPDIR="$(mktemp -d)" - - # Unzip the framework into the appropriate directory structure for CocoaPods. - # The final archive should contain the C API framework as a vendored framework - # as well as all the Obj-C source code and the header files. - # - # The directory structure will be like: - # - # ${TFLS_TMPDIR}/ - # |-- tensorflow_lite_support/ - # | |-- c/ - # | | +-- - # | +-- ios/ - # | +-- - # +-- Frameworks/ - # +-- TensorFlowLiteTaskTextC.framework - # - - # ----- (1) Copy source files ----- - pushd "${TFLS_ROOT_DIR}" - - # Set Source files and iOS header files which are to be stripped off header - # prefixes, to be archived along with the static framework. - case $FRAMEWORK_NAME in - "TensorFlowLiteTaskVision") - # # SRC_PATTERNS=" - # # */c/common.h - # # */c/task/core/base_options.h - # # */c/task/processor/category.h - # # */c/task/processor/bounding_box.h - # # */c/task/processor/classification_options.h - # # */c/task/processor/classification_result.h - # # */c/task/processor/detection_result.h - # # */c/task/processor/segmentation_result.h - # # */c/task/vision/image_classifier.h - # # */c/task/vision/object_detector.h - # # */c/task/vision/image_segmenter.h - # # */c/task/vision/core/*.h - # # */ios/sources/* - # # */ios/task/core/sources/* - # # */ios/task/processor/sources/* - # # */ios/task/vision/sources/* - # # */ios/task/vision/apis/* - # # */ios/task/vision/*/sources/* - # # */odml/ios/image/apis/*.h - # # */odml/ios/image/sources/*.m - # # " - - # # IOS_HEADER_PATTERNS=" - # # */ios/task/vision/apis/*.h - # # */ios/task/vision/sources/TFLImageClassifierTest.h - # # " - # IOS_HEADER_PATTERNS=" - # */ios/task/vision/sources/TFLImageClassifierTest.h - # " - ;; - "TensorFlowLiteTaskText") - SRC_PATTERNS=" - */c/task/text/*.h - */ios/task/text/*/Sources/* - */ios/task/text/apis/* - " - - IOS_HEADER_PATTERNS=" - */ios/task/text/*/Sources/*.h - " - ;; - *) - echo "FRAMEWORK_NAME provided is not in the list of buildable frameworks. - The accepted values are TensorFlowLiteTaskVision, - TensorFlowLiteTaskText" - exit 1 - ;; - esac - - # # List of individual files obtained from the patterns above. - # SRC_FILES=$(xargs -n1 find * -wholename <<< "${SRC_PATTERNS}" | sort | uniq) - - # # Copy source files with the intermediate directories preserved. - # xargs -n1 -I{} rsync -R {} "${TFLS_TMPDIR}" <<< "${SRC_FILES}" - - # Copy the license file to TFLS_TMPDIR - cp "${TFLS_ROOT_DIR}/LICENSE" ${TFLS_TMPDIR} - - popd - - pushd "${TFLS_ROOT_DIR}" - - # List of individual files obtained from the patterns above. -# IOS_HEADER_FILES=$(xargs -n1 find * -wholename <<< "${IOS_HEADER_PATTERNS}" | sort | uniq) -# popd - -# # The iOS headers should be stripped off the path prefixes in the #imports. -# # This is required for the cocoapods to build fine since the header files in -# # an iOS framework cannot be organised in multilevel directories. -# for filename in ${IOS_HEADER_FILES} -# do -# LAST_PATH_COMPONENT=$(basename ${filename}) -# FULL_SOURCE_PATH="$TFLS_ROOT_DIR/$filename" -# FULL_DEST_PATH="$TFLS_TMPDIR/$filename" -# sed -E 's|#import ".+\/([^/]+.h)"|#import "\1"|' $FULL_SOURCE_PATH > $FULL_DEST_PATH -# done - - # ----- (2) Unzip the prebuilt C API framework ----- - # unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks - unzip "bazel-bin/tensorflow_lite_support/ios/task/vision/TensorFlowLiteCPPTest_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks - - # cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/apis/framework_cpp.modulemap" ${TFLS_TMPDIR} - # cp "${TFLS_ROOT_DIR}/bazel-bin/tensorflow_lite_support/ios/task/vision/libTFLImageClassifierTest.a" ${TFLS_TMPDIR} - # cp "${TFLS_ROOT_DIR}/tensorflow_lite_support/ios/task/vision/libTFLImageClassifierTest.a" ${TFLS_TMPDIR} - - - # unzip "task/vision/libTFLImageClassifierTest.a" -d "${TFLS_TMPDIR}"/Frameworks - - # ----- (3) Move the framework to the destination ----- - if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then - TARGET_DIR="$(realpath "${TARGET_FRAMEWORK_NAME}")" - - # Create the framework archive directory. - if [[ "${IS_RELEASE_BUILD}" == true ]]; then - # Get the first 16 bytes of the sha256 checksum of the root directory. - SHA256_CHECKSUM=$(find "${TFLS_TMPDIR}" -type f -print0 | xargs -0 shasum -a 256 | sort | shasum -a 256 | cut -c1-16) - FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}/${SHA256_CHECKSUM}" - else - FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}" - fi - mkdir -p "${FRAMEWORK_ARCHIVE_DIR}" - - # Zip up the framework and move to the archive directory. - pushd "${TFLS_TMPDIR}" - TFLS_ARCHIVE_FILE="${ARCHIVE_NAME}.tar.gz" - tar -cvzf "${TFLS_ARCHIVE_FILE}" . - mv "${TFLS_ARCHIVE_FILE}" "${FRAMEWORK_ARCHIVE_DIR}" - popd - - # Move the target directory to the Kokoro artifacts directory. - mv "${TARGET_DIR}" "$(realpath "${DEST_DIR}")"/ - else - rsync -r "${TFLS_TMPDIR}/" "$(realpath "${DEST_DIR}")/" - fi - - # Clean up the temporary directory for the framework. - rm -rf "${TFLS_TMPDIR}" - - # Pop back to the TFLS root directory. - popd -} - -cd "${TFLS_ROOT_DIR}" -build_ios_api_framework -# build_c_api_framework $FRAMEWORK_NAME -create_framework_archive $FRAMEWORK_NAME diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index ad7663df2..15b4f4571 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -65,6 +65,37 @@ function build_c_api_framework { //tensorflow_lite_support/ios:$1C_framework } +function strip_path_and_copy_source_files { + # List of individual files obtained from the patterns above. + SRC_FILES=$(xargs -n1 find * -wholename <<< "${SRC_PATTERNS}" | sort | uniq) + + # Copy source files with the intermediate directories preserved. + xargs -n1 -I{} rsync -R {} "${TFLS_TMPDIR}" <<< "${SRC_FILES}" + + popd + + pushd "${TFLS_ROOT_DIR}" + + # List of individual files obtained from the patterns above. + IOS_HEADER_FILES=$(xargs -n1 find * -wholename <<< "${IOS_HEADER_PATTERNS}" | sort | uniq) + popd + + # The iOS headers should be stripped off the path prefixes in the #imports. + # This is required for the cocoapods to build fine since the header files in + # an iOS framework cannot be organised in multilevel directories. + for filename in ${IOS_HEADER_FILES} + do + LAST_PATH_COMPONENT=$(basename ${filename}) + FULL_SOURCE_PATH="$TFLS_ROOT_DIR/$filename" + FULL_DEST_PATH="$TFLS_TMPDIR/$filename" + sed -E 's|#import ".+\/([^/]+.h)"|#import "\1"|' $FULL_SOURCE_PATH > $FULL_DEST_PATH + done + + # ----- (2) Unzip the prebuilt C API framework ----- + unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks +} + + function create_framework_archive { TARGET_FRAMEWORK_NAME="$1" C_API_FRAMEWORK_NAME="$1C" @@ -150,6 +181,14 @@ function create_framework_archive { */ios/task/text/*/Sources/*.h " ;; + + "TensorFlowLiteTaskVisionObjCPP") + SRC_PATTERNS=" + */c/task/text/*.h + */ios/task/text/*/Sources/* + */ios/task/text/apis/* + " + ;; *) echo "FRAMEWORK_NAME provided is not in the list of buildable frameworks. The accepted values are TensorFlowLiteTaskVision, @@ -158,37 +197,11 @@ function create_framework_archive { ;; esac - # List of individual files obtained from the patterns above. - SRC_FILES=$(xargs -n1 find * -wholename <<< "${SRC_PATTERNS}" | sort | uniq) - - # Copy source files with the intermediate directories preserved. - xargs -n1 -I{} rsync -R {} "${TFLS_TMPDIR}" <<< "${SRC_FILES}" - - # Copy the license file to TFLS_TMPDIR + + + # Copy the license file to TFLS_TMPDIR cp "${TFLS_ROOT_DIR}/LICENSE" ${TFLS_TMPDIR} - popd - - pushd "${TFLS_ROOT_DIR}" - - # List of individual files obtained from the patterns above. - IOS_HEADER_FILES=$(xargs -n1 find * -wholename <<< "${IOS_HEADER_PATTERNS}" | sort | uniq) - popd - - # The iOS headers should be stripped off the path prefixes in the #imports. - # This is required for the cocoapods to build fine since the header files in - # an iOS framework cannot be organised in multilevel directories. - for filename in ${IOS_HEADER_FILES} - do - LAST_PATH_COMPONENT=$(basename ${filename}) - FULL_SOURCE_PATH="$TFLS_ROOT_DIR/$filename" - FULL_DEST_PATH="$TFLS_TMPDIR/$filename" - sed -E 's|#import ".+\/([^/]+.h)"|#import "\1"|' $FULL_SOURCE_PATH > $FULL_DEST_PATH - done - - # ----- (2) Unzip the prebuilt C API framework ----- - unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks - # ----- (3) Move the framework to the destination ----- if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then TARGET_DIR="$(realpath "${TARGET_FRAMEWORK_NAME}")" diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh new file mode 100755 index 000000000..51a7609d7 --- /dev/null +++ b/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +# Copyright 2022 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +# Set the following variables as appropriate. +# * BAZEL: path to bazel. defaults to the first one available in PATH +# * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the +# * accepted values are TensorFlowLiteTaskVision, TensorFlowLiteTaskText. +# * TFLS_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev +# * IS_RELEASE_BUILD: set as true if this build should be a release build +# * ARCHIVE_FRAMEWORK: set as true if the framework should be archived +# * DEST_DIR: destination directory to which the framework will be copied + +set -ex + +if [[ "$(uname)" != "Darwin" ]]; then + echo "This build script only works on macOS." + exit 1 +fi + +BAZEL="${BAZEL:-$(which bazel)}" +TFLS_BUILD_VERSION=${TFLS_BUILD_VERSION:-0.0.1-dev} +TFLS_ROOT_DIR=$(git rev-parse --show-toplevel) + +if [[ ! -x "${BAZEL}" ]]; then + echo "bazel executable is not found." + exit 1 +fi + +if [ -z ${FRAMEWORK_NAME+x} ]; then + echo "Name of the iOS framework, which is to be built, must be set." + exit 1 +fi + +case $FRAMEWORK_NAME in + "TensorFlowLiteTaskVisionObjCPP") + ;; + *) + echo "Wrong framework name" + exit 1 + ;; +esac + +if [[ -z "${DEST_DIR+x}" || "${DEST_DIR}" == ${TFLS_ROOT_DIR}* ]]; then + echo "DEST_DIR variable must be set and not be under the repository root." + exit 1 +fi + +function build_ios_api_framework { + "${BAZEL}" build -c opt --config=ios_fat \ + //tensorflow_lite_support/ios:$1_framework +} + +function create_framework_archive { + TARGET_FRAMEWORK_NAME="$1" + # IOS_API_FRAMEWORK_NAME="$1C" + + TFLS_IOS_DIR=tensorflow_lite_support/ios + BAZEL_IOS_OUTDIR="bazel-bin/${TFLS_IOS_DIR}" + + # Change to the Bazel iOS output directory. + pushd "${BAZEL_IOS_OUTDIR}" + + # Create the temporary directory for the given framework. + ARCHIVE_NAME="${TARGET_FRAMEWORK_NAME}-${TFLS_BUILD_VERSION}" + TFLS_TMPDIR="$(mktemp -d)" + + # Copy the license file to TFLS_TMPDIR + cp "${TFLS_ROOT_DIR}/LICENSE" ${TFLS_TMPDIR} + FRAMEWORK_LOCATION=$(find "${TFLS_ROOT_DIR}/bazel-out/" -name ${TARGET_FRAMEWORK_NAME}_framework.zip) + + for path in ${FRAMEWORK_LOCATION} + do + unzip ${path} -d "${TFLS_TMPDIR}"/Frameworks + break + done + + #----- (3) Move the framework to the destination ----- + if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then + TARGET_DIR="$(realpath "${TARGET_FRAMEWORK_NAME}")" + + # Create the framework archive directory. + if [[ "${IS_RELEASE_BUILD}" == true ]]; then + # Get the first 16 bytes of the sha256 checksum of the root directory. + SHA256_CHECKSUM=$(find "${TFLS_TMPDIR}" -type f -print0 | xargs -0 shasum -a 256 | sort | shasum -a 256 | cut -c1-16) + FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}/${SHA256_CHECKSUM}" + else + FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}" + fi + mkdir -p "${FRAMEWORK_ARCHIVE_DIR}" + + # Zip up the framework and move to the archive directory. + pushd "${TFLS_TMPDIR}" + TFLS_ARCHIVE_FILE="${ARCHIVE_NAME}.tar.gz" + tar -cvzf "${TFLS_ARCHIVE_FILE}" . + mv "${TFLS_ARCHIVE_FILE}" "${FRAMEWORK_ARCHIVE_DIR}" + popd + + # Move the target directory to the Kokoro artifacts directory. + mv "${TARGET_DIR}" "$(realpath "${DEST_DIR}")"/ + else + rsync -r "${TFLS_TMPDIR}/" "$(realpath "${DEST_DIR}")/" + fi + + # Clean up the temporary directory for the framework. + rm -rf "${TFLS_TMPDIR}" + echo ${TFLS_TMPDIR} + + # Pop back to the TFLS root directory. + popd +} + +cd "${TFLS_ROOT_DIR}" +build_ios_api_framework $FRAMEWORK_NAME +create_framework_archive $FRAMEWORK_NAME From cf615ba8eeee31d433ed5a43412cdc27359a9230 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:16:44 +0530 Subject: [PATCH 05/39] Reverted vision podspec --- .../ios/TensorFlowLiteTaskVision.podspec.template | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index fc0bf03fa..137d891e9 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -26,8 +26,7 @@ Pod::Spec.new do |s| objc_dir + 'sources/TFLCommon.h', objc_core_dir + 'sources/TFLBaseOptions.h', objc_processor_dir + 'sources/{TFLClassificationOptions,TFLCategory,TFLClassificationResult,TFLDetectionResult,TFLSegmentationResult}.h', - objc_vision_dir + 'sources/*.h', - "Frameworks/TensorFlowLiteTaskImageClassifierTest.framework/Headers/*.h" + objc_vision_dir + 'sources/*.h' ] c_dir = root_dir_name + '/c/' @@ -49,7 +48,6 @@ Pod::Spec.new do |s| objc_vision_dir + 'sources/*', gml_image_dir + 'apis/*.h', gml_image_dir + 'sources/*' - "Frameworks/TensorFlowLiteTaskImageClassifierTest.framework/Headers/*.h" ] s.module_map = objc_vision_dir + 'apis/framework.modulemap' @@ -60,5 +58,5 @@ Pod::Spec.new do |s| } s.library = 'c++' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionC.framework', 'Frameworks/TensorFlowLiteTaskImageClassifierTest.framework' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionC.framework' end From 7b30cb238ea4f37366c554ae0a04c532806fb768 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:17:31 +0530 Subject: [PATCH 06/39] Reverted build file --- tensorflow_lite_support/ios/task/vision/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 1cf60b8c3..6b889e9ec 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -11,7 +11,7 @@ objc_library( hdrs = [ "sources/TFLImageClassifier.h", ], - # features = ["-layering_check"], + features = ["-layering_check"], module_name = "TFLImageClassifier", deps = [ "//tensorflow_lite_support/c/task/vision:image_classifier", From 0e19c84540c777b43956993157798fdebf75b21b Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:18:34 +0530 Subject: [PATCH 07/39] Reverted to version in master --- tensorflow_lite_support/ios/task/vision/BUILD | 1 - tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h | 1 - 2 files changed, 2 deletions(-) diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 6b889e9ec..6c7339d1b 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -55,7 +55,6 @@ objc_library( name = "TFLImageSegmenter", srcs = [ "sources/TFLImageSegmenter.m", - ], hdrs = [ "sources/TFLImageSegmenter.h", diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h index e5de4ed82..9fe449ae9 100644 --- a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h +++ b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h @@ -23,5 +23,4 @@ #import "TFLImageSegmenter.h" #import "TFLObjectDetector.h" #import "TFLSegmentationResult.h" -#import "TFLImageClassifierTest.h" From 9344bb16f0eb3ed8eb606b642ef6a6e473775c7c Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:19:17 +0530 Subject: [PATCH 08/39] Reverted to version in master --- tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h index 9fe449ae9..3eb4f4964 100644 --- a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h +++ b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h @@ -23,4 +23,3 @@ #import "TFLImageSegmenter.h" #import "TFLObjectDetector.h" #import "TFLSegmentationResult.h" - From ae671c7c5197565135cb80175a0536db8f591dcd Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:24:33 +0530 Subject: [PATCH 09/39] Reverted to version in master --- .../task/vision/sources/TFLImageEmbedder.h | 2 +- .../task/vision/sources/TFLImageEmbedder.mm | 4 +- .../test/task/vision/image_classifier/BUILD | 20 ----- .../ios/test/task/vision/image_embedder/BUILD | 3 +- .../image_embedder/TFLImageEmbedderTests.m | 2 +- tensorflow_lite_support/odml/ios/image/BUILD | 2 +- .../ci_build/builds/build_ios_framework.sh | 73 ++++++++----------- 7 files changed, 36 insertions(+), 70 deletions(-) diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h index a4bf963f2..cc17766c4 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h @@ -1,4 +1,4 @@ -/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm index 5926fe708..78deec058 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm @@ -1,4 +1,4 @@ -/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ using ImageEmbedderOptionsCpp = ::tflite::task::vision::ImageEmbedderOptions; using ::tflite::support::StatusOr; - - } @implementation TFLImageEmbedder { diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD index 0614c2f20..06da0ea6b 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD @@ -84,23 +84,3 @@ ios_unit_test( ":TFLImageClassifierCoreMLDelegateTestLibrary", ], ) - -objc_library( - name = "TFLImageClassifierCPPTestLibrary", - testonly = 1, - srcs = ["TFLImageClassifierCPPTests.m"], - tags = TFL_DEFAULT_TAGS, - deps = [ - "//tensorflow_lite_support/ios/task/vision:TFLImageClassifierTest", - ], -) - -ios_unit_test( - name = "TFLImageClassifierCPPTest", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - runner = tflite_ios_lab_runner("IOS_LATEST"), - tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS, - deps = [ - ":TFLImageClassifierCPPTestLibrary", - ], -) diff --git a/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD index fb0d1167c..74224e4ee 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD @@ -32,4 +32,5 @@ ios_unit_test( deps = [ ":TFLImageEmbedderObjcTestLibrary", ], -) \ No newline at end of file +) + diff --git a/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m b/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m index 537edbd38..093c5f22c 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m +++ b/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m @@ -1,4 +1,4 @@ -/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/tensorflow_lite_support/odml/ios/image/BUILD b/tensorflow_lite_support/odml/ios/image/BUILD index 857e06558..24fff353f 100644 --- a/tensorflow_lite_support/odml/ios/image/BUILD +++ b/tensorflow_lite_support/odml/ios/image/BUILD @@ -15,7 +15,7 @@ load( ) package( - default_visibility = ["//tensorflow_lite_support:internal"], + default_visibility = ["//visibility:private"], licenses = ["notice"], # Apache 2.0 ) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 15b4f4571..68c8903ed 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -65,37 +65,6 @@ function build_c_api_framework { //tensorflow_lite_support/ios:$1C_framework } -function strip_path_and_copy_source_files { - # List of individual files obtained from the patterns above. - SRC_FILES=$(xargs -n1 find * -wholename <<< "${SRC_PATTERNS}" | sort | uniq) - - # Copy source files with the intermediate directories preserved. - xargs -n1 -I{} rsync -R {} "${TFLS_TMPDIR}" <<< "${SRC_FILES}" - - popd - - pushd "${TFLS_ROOT_DIR}" - - # List of individual files obtained from the patterns above. - IOS_HEADER_FILES=$(xargs -n1 find * -wholename <<< "${IOS_HEADER_PATTERNS}" | sort | uniq) - popd - - # The iOS headers should be stripped off the path prefixes in the #imports. - # This is required for the cocoapods to build fine since the header files in - # an iOS framework cannot be organised in multilevel directories. - for filename in ${IOS_HEADER_FILES} - do - LAST_PATH_COMPONENT=$(basename ${filename}) - FULL_SOURCE_PATH="$TFLS_ROOT_DIR/$filename" - FULL_DEST_PATH="$TFLS_TMPDIR/$filename" - sed -E 's|#import ".+\/([^/]+.h)"|#import "\1"|' $FULL_SOURCE_PATH > $FULL_DEST_PATH - done - - # ----- (2) Unzip the prebuilt C API framework ----- - unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks -} - - function create_framework_archive { TARGET_FRAMEWORK_NAME="$1" C_API_FRAMEWORK_NAME="$1C" @@ -181,14 +150,6 @@ function create_framework_archive { */ios/task/text/*/Sources/*.h " ;; - - "TensorFlowLiteTaskVisionObjCPP") - SRC_PATTERNS=" - */c/task/text/*.h - */ios/task/text/*/Sources/* - */ios/task/text/apis/* - " - ;; *) echo "FRAMEWORK_NAME provided is not in the list of buildable frameworks. The accepted values are TensorFlowLiteTaskVision, @@ -197,11 +158,37 @@ function create_framework_archive { ;; esac - - - # Copy the license file to TFLS_TMPDIR + # List of individual files obtained from the patterns above. + SRC_FILES=$(xargs -n1 find * -wholename <<< "${SRC_PATTERNS}" | sort | uniq) + + # Copy source files with the intermediate directories preserved. + xargs -n1 -I{} rsync -R {} "${TFLS_TMPDIR}" <<< "${SRC_FILES}" + + # Copy the license file to TFLS_TMPDIR cp "${TFLS_ROOT_DIR}/LICENSE" ${TFLS_TMPDIR} + popd + + pushd "${TFLS_ROOT_DIR}" + + # List of individual files obtained from the patterns above. + IOS_HEADER_FILES=$(xargs -n1 find * -wholename <<< "${IOS_HEADER_PATTERNS}" | sort | uniq) + popd + + # The iOS headers should be stripped off the path prefixes in the #imports. + # This is required for the cocoapods to build fine since the header files in + # an iOS framework cannot be organised in multilevel directories. + for filename in ${IOS_HEADER_FILES} + do + LAST_PATH_COMPONENT=$(basename ${filename}) + FULL_SOURCE_PATH="$TFLS_ROOT_DIR/$filename" + FULL_DEST_PATH="$TFLS_TMPDIR/$filename" + sed -E 's|#import ".+\/([^/]+.h)"|#import "\1"|' $FULL_SOURCE_PATH > $FULL_DEST_PATH + done + + # ----- (2) Unzip the prebuilt C API framework ----- + unzip "${C_API_FRAMEWORK_NAME}_framework.zip" -d "${TFLS_TMPDIR}"/Frameworks + # ----- (3) Move the framework to the destination ----- if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then TARGET_DIR="$(realpath "${TARGET_FRAMEWORK_NAME}")" @@ -238,4 +225,4 @@ function create_framework_archive { cd "${TFLS_ROOT_DIR}" build_c_api_framework $FRAMEWORK_NAME -create_framework_archive $FRAMEWORK_NAME +create_framework_archive $FRAMEWORK_NAME \ No newline at end of file From 54f509a99cfc9109987ce74e730bc4b5f74e2631 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 3 Jun 2022 19:26:07 +0530 Subject: [PATCH 10/39] Updated formatting --- .../tools/ci_build/builds/build_ios_framework.sh | 2 +- .../tools/ci_build/builds/build_obj_cpp_framework.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 68c8903ed..ad7663df2 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -225,4 +225,4 @@ function create_framework_archive { cd "${TFLS_ROOT_DIR}" build_c_api_framework $FRAMEWORK_NAME -create_framework_archive $FRAMEWORK_NAME \ No newline at end of file +create_framework_archive $FRAMEWORK_NAME diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh index 51a7609d7..2072b548a 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh @@ -125,3 +125,4 @@ function create_framework_archive { cd "${TFLS_ROOT_DIR}" build_ios_api_framework $FRAMEWORK_NAME create_framework_archive $FRAMEWORK_NAME + From 135f369ad127bcde595611624dcaca5682ab3de7 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 9 Jun 2022 01:29:11 +0530 Subject: [PATCH 11/39] Added vision framework as vendored framework of cocoapods --- tensorflow_lite_support/ios/BUILD | 69 +++++++++---------- .../TensorFlowLiteTaskVision.podspec.template | 51 ++------------ .../TensorFlowLiteTaskVisionObjCPP.podspec | 20 ------ .../ios/task/vision/apis/TFLTaskVision.h | 25 ------- .../ios/task/vision/apis/framework.modulemap | 4 -- tensorflow_lite_support/odml/ios/image/BUILD | 2 + ...ework.sh => build_ios_vision_framework.sh} | 2 +- 7 files changed, 42 insertions(+), 131 deletions(-) delete mode 100644 tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec delete mode 100644 tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h delete mode 100644 tensorflow_lite_support/ios/task/vision/apis/framework.modulemap rename tensorflow_lite_support/tools/ci_build/builds/{build_obj_cpp_framework.sh => build_ios_vision_framework.sh} (99%) diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 75ff062c2..c3217a613 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -47,6 +47,17 @@ strip_ios_api_include_path_prefix( name = "strip_ios_api_include_path", hdr_labels = [ "//tensorflow_lite_support/ios/task/vision:sources/TFLImageEmbedder.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageClassifier.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLObjectDetector.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageSegmenter.h", + "//tensorflow_lite_support/ios:sources/TFLCommon.h", + "//tensorflow_lite_support/ios/task/core:sources/TFLBaseOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLCategory.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationResult.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLDetectionResult.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLSegmentationResult.h", + "//tensorflow_lite_support/odml/ios/image:apis/GMLImage.h", ], ) @@ -72,39 +83,6 @@ tflite_ios_framework( ], ) -# 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:TensorFlowLiteTaskVisionC_framework -tflite_ios_framework( - name = "TensorFlowLiteTaskVisionC_framework", - hdrs = [ - ":base_options.h", - ":bounding_box.h", - ":category.h", - ":classification_options.h", - ":classification_result.h", - ":common.h", - ":detection_result.h", - ":frame_buffer.h", - ":image_classifier.h", - ":image_segmenter.h", - ":object_detector.h", - ":segmentation_result.h", - ], - allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", - bundle_name = "TensorFlowLiteTaskVisionC", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - "//tensorflow_lite_support/c/task/vision:image_classifier", - "//tensorflow_lite_support/c/task/vision:image_segmenter", - "//tensorflow_lite_support/c/task/vision:object_detector", - ], -) - objc_library( name = "TFLCommon", hdrs = [ @@ -134,15 +112,36 @@ 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 = "TensorFlowLiteTaskVisionObjCPP_framework", + name = "TensorFlowLiteTaskVision_framework", hdrs = [ ":TFLImageEmbedder.h", + ":TFLImageClassifier.h", + ":TFLObjectDetector.h", + ":TFLImageSegmenter.h", + ":TFLCommon.h", + ":TFLBaseOptions.h", + ":TFLClassificationOptions.h", + ":TFLCategory.h", + ":TFLClassificationResult.h", + ":TFLDetectionResult.h", + ":TFLSegmentationResult.h", + ":GMLImage.h", ], - bundle_name = "TensorFlowLiteTaskVisionObjCPP", + bundle_name = "TensorFlowLiteTaskVision", minimum_os_version = TFL_MINIMUM_OS_VERSION, deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageEmbedder", + "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", + "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", + "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", ], ) diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index 137d891e9..81b4b74d9 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -1,10 +1,10 @@ Pod::Spec.new do |s| s.name = 'TensorFlowLiteTaskVision' - s.version = '${TFLS_BUILD_VERSION}' + s.version = '0.0.1' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE"} s.homepage = 'https://github.com/tensorflow/tflite-support' - s.source = { :http => '${TFLS_DOWNLOAD_URL}' } + s.source = { :http => 'https://dl.dropboxusercontent.com/s/kr3ngm6ji9ei8r5/TensorFlowLiteTaskVisionObjCPP-0.1.3-dev.tar.gz?dl=0' } s.summary = 'TensorFlow Lite Task Library - Vision' s.description = 'The Computer Vision APIs of the TFLite Task Library' @@ -12,51 +12,10 @@ Pod::Spec.new do |s| s.module_name = 'TensorFlowLiteTaskVision' s.static_framework = true - - root_dir_name = "tensorflow_lite_support" - objc_dir = root_dir_name + '/ios/' - objc_task_dir = objc_dir + 'task/' - objc_core_dir = objc_task_dir + 'core/' - objc_processor_dir = objc_task_dir + 'processor/' - objc_vision_dir = objc_task_dir + 'vision/' - gml_image_dir = root_dir_name + '/odml/ios/image/' - s.public_header_files = [ - objc_vision_dir + 'apis/*.h', - gml_image_dir + 'apis/*.h', - objc_dir + 'sources/TFLCommon.h', - objc_core_dir + 'sources/TFLBaseOptions.h', - objc_processor_dir + 'sources/{TFLClassificationOptions,TFLCategory,TFLClassificationResult,TFLDetectionResult,TFLSegmentationResult}.h', - objc_vision_dir + 'sources/*.h' - ] - - c_dir = root_dir_name + '/c/' - c_task_dir = c_dir + 'task/' - c_core_dir = c_task_dir + 'core/' - c_processor_dir = c_task_dir + 'processor/' - c_vision_dir = c_task_dir + 'vision/' - s.source_files = [ - c_dir + '*.h', - c_core_dir + '*.h', - c_processor_dir + '{category,bounding_box,classification_options,classification_result,detection_result,segmentation_result}.h', - c_vision_dir + '*.h', - c_vision_dir + 'core/*.h', - objc_dir + 'sources/*', - objc_core_dir + 'sources/*', - objc_processor_dir + 'sources/*', - objc_vision_dir + 'apis/', - objc_vision_dir + '*/sources/*', - objc_vision_dir + 'sources/*', - gml_image_dir + 'apis/*.h', - gml_image_dir + 'sources/*' - ] - - s.module_map = objc_vision_dir + 'apis/framework.modulemap' s.pod_target_xcconfig = { - 'HEADER_SEARCH_PATHS' => - '"${PODS_TARGET_SRCROOT}/' + root_dir_name + '/.."/**', - 'VALID_ARCHS' => 'x86_64 armv7 arm64', + 'VALID_ARCHS' => 'x86_64, arm64, armv7', } - s.library = 'c++' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionC.framework' + s.frameworks = 'CoreMedia', 'Accelerate' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionObjCPP.framework' end diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec b/tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec deleted file mode 100644 index ecca79466..000000000 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVisionObjCPP.podspec +++ /dev/null @@ -1,20 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'TensorFlowLiteTaskVisionObjCPP' - s.version = '0.1.1' - s.authors = 'Google Inc.' - s.license = { :type => 'Apache',:file => "LICENSE"} - s.homepage = 'https://github.com/tensorflow/tflite-support' - s.source = { :http => 'https://dl.dropboxusercontent.com/s/5v2775z785b8114/TensorFlowLiteTaskVisionObjCPP-0.1.1-dev.tar.gz?dl=0' } - s.summary = 'TensorFlow Lite Task Library - Vision' - s.description = 'The Computer Vision APIs of the TFLite Task Library' - - s.ios.deployment_target = '10.0' - - s.module_name = 'TensorFlowLiteTaskVisionObjCPP' - s.static_framework = true - s.pod_target_xcconfig = { - 'VALID_ARCHS' => 'x86_64, arm64, armv7', - } - s.library = 'c++' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionObjCPP.framework' -end diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h deleted file mode 100644 index 3eb4f4964..000000000 --- a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2022 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GMLImage.h" -#import "TFLBaseOptions.h" -#import "TFLCategory.h" -#import "TFLClassificationOptions.h" -#import "TFLClassificationResult.h" -#import "TFLCommon.h" -#import "TFLDetectionResult.h" -#import "TFLImageClassifier.h" -#import "TFLImageSegmenter.h" -#import "TFLObjectDetector.h" -#import "TFLSegmentationResult.h" diff --git a/tensorflow_lite_support/ios/task/vision/apis/framework.modulemap b/tensorflow_lite_support/ios/task/vision/apis/framework.modulemap deleted file mode 100644 index b89443cca..000000000 --- a/tensorflow_lite_support/ios/task/vision/apis/framework.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -framework module TensorFlowLiteTaskVision { - umbrella header "TFLTaskVision.h" - export * -} diff --git a/tensorflow_lite_support/odml/ios/image/BUILD b/tensorflow_lite_support/odml/ios/image/BUILD index 24fff353f..63e3db87d 100644 --- a/tensorflow_lite_support/odml/ios/image/BUILD +++ b/tensorflow_lite_support/odml/ios/image/BUILD @@ -65,6 +65,8 @@ TEST_COPTS = RELEASE_COPTS + [ "-Wno-shadow", ] +exports_files(["apis/GMLImage.h"]) + objc_library( name = "MLImage", srcs = SOURCES, diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh similarity index 99% rename from tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh rename to tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh index 2072b548a..27fea03c6 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_obj_cpp_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh @@ -45,7 +45,7 @@ if [ -z ${FRAMEWORK_NAME+x} ]; then fi case $FRAMEWORK_NAME in - "TensorFlowLiteTaskVisionObjCPP") + "TensorFlowLiteTaskVision") ;; *) echo "Wrong framework name" From 5c7401a32173bf2eb200eff10b88c992d58520d3 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 9 Jun 2022 01:38:35 +0530 Subject: [PATCH 12/39] Fixed typos --- tensorflow_lite_support/ios/ios.bzl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow_lite_support/ios/ios.bzl b/tensorflow_lite_support/ios/ios.bzl index cf2d2207a..75362c57d 100644 --- a/tensorflow_lite_support/ios/ios.bzl +++ b/tensorflow_lite_support/ios/ios.bzl @@ -1,8 +1,8 @@ """TensorFlow Lite Support Library Helper Rules for iOS""" -# When the static framework is built with bazel, the all header files are moved +# When the static framework is built with bazel, all the 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 API header files included by +# is used for stripping the path prefix from the C API header files included by # other C API header files. def strip_c_api_include_path_prefix(name, hdr_labels, prefix = ""): """Create modified header files with the common.h include path stripped out. @@ -29,9 +29,9 @@ def strip_c_api_include_path_prefix(name, hdr_labels, prefix = ""): """.format(prefix, hdr_label), ) -# When the static framework is built with bazel, the all header files are moved +# When the static framework is built with bazel, all the 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 iOS API header files imported by +# is used for stripping the path prefix from the iOS API header files imported by # other iOS API header files. def strip_ios_api_include_path_prefix(name, hdr_labels, prefix = ""): """Create modified header files with the import path stripped out. From 8decd90da9418f6718bb2e234d0c094e680b6bd0 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Jun 2022 20:43:08 +0530 Subject: [PATCH 13/39] Updated bundle name --- .../ios/TensorFlowLiteTaskVision.podspec.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index 81b4b74d9..b4dd87939 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -17,5 +17,5 @@ Pod::Spec.new do |s| } s.library = 'c++' s.frameworks = 'CoreMedia', 'Accelerate' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionObjCPP.framework' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVision.framework' end From 77e85c3679de2e978dcce8450ea71d8ef17359ce Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 16 Jun 2022 20:47:12 +0530 Subject: [PATCH 14/39] Updated build version --- .../ios/TensorFlowLiteTaskVision.podspec.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index b4dd87939..08f90aee6 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TensorFlowLiteTaskVision' - s.version = '0.0.1' + s.version = '${TFLS_BUILD_VERSION}' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE"} s.homepage = 'https://github.com/tensorflow/tflite-support' From 405454bb6a194c3903ea796d00e2ac6eb53df36d Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 22 Jun 2022 21:02:00 +0530 Subject: [PATCH 15/39] Updated coremldelegate tests --- .../c/task/vision/image_classifier.cc | 11 +++++++++++ .../ios/test/task/vision/image_classifier/BUILD | 2 ++ .../TFLImageClassifierCoreMLDelegateTest.mm | 10 +++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tensorflow_lite_support/c/task/vision/image_classifier.cc b/tensorflow_lite_support/c/task/vision/image_classifier.cc index 52e215116..56b725da0 100644 --- a/tensorflow_lite_support/c/task/vision/image_classifier.cc +++ b/tensorflow_lite_support/c/task/vision/image_classifier.cc @@ -88,6 +88,17 @@ StatusOr CreateImageClassifierCppOptionsFromCOptions( cpp_options.set_score_threshold( c_options->classification_options.score_threshold); + cpp_options.mutable_base_options() + ->mutable_compute_settings() + ->mutable_tflite_settings() + ->set_delegate(tflite::proto::Delegate::GPU); + + // 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 diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD index 06da0ea6b..fb05c4e01 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD @@ -45,6 +45,7 @@ objc_library( deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", + "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:gpu_plugin", ], ) @@ -73,6 +74,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( diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCoreMLDelegateTest.mm b/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCoreMLDelegateTest.mm index 698387707..3921baca5 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCoreMLDelegateTest.mm +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/TFLImageClassifierCoreMLDelegateTest.mm @@ -14,10 +14,10 @@ ==============================================================================*/ #import -#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; @@ -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> image_classifier_status = From 8fd27eba36497d8df601f3010ccd8ee1ca4bec81 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 22 Jun 2022 21:02:48 +0530 Subject: [PATCH 16/39] Updated tests --- .../c/task/vision/image_classifier.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tensorflow_lite_support/c/task/vision/image_classifier.cc b/tensorflow_lite_support/c/task/vision/image_classifier.cc index 56b725da0..37abe8182 100644 --- a/tensorflow_lite_support/c/task/vision/image_classifier.cc +++ b/tensorflow_lite_support/c/task/vision/image_classifier.cc @@ -91,13 +91,13 @@ StatusOr CreateImageClassifierCppOptionsFromCOptions( cpp_options.mutable_base_options() ->mutable_compute_settings() ->mutable_tflite_settings() - ->set_delegate(tflite::proto::Delegate::GPU); + ->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); + 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; } From 5753ce970e76f14bff71611a49b409793326c6d8 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 22 Jun 2022 21:07:55 +0530 Subject: [PATCH 17/39] Updated build file --- tensorflow_lite_support/ios/BUILD | 89 +++++++++++++++++++------------ 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 6e3264804..1bec4aad1 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -8,6 +8,12 @@ load( load( "//tensorflow_lite_support/ios:ios.bzl", "strip_c_api_include_path_prefix", + "strip_ios_api_include_path_prefix", +) + +load( + "@build_bazel_rules_apple//apple:ios.bzl", + "ios_static_framework", ) package( @@ -37,6 +43,24 @@ strip_c_api_include_path_prefix( ], ) +strip_ios_api_include_path_prefix( + name = "strip_ios_api_include_path", + hdr_labels = [ + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageEmbedder.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageClassifier.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLObjectDetector.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageSegmenter.h", + "//tensorflow_lite_support/ios:sources/TFLCommon.h", + "//tensorflow_lite_support/ios/task/core:sources/TFLBaseOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLCategory.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationResult.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLDetectionResult.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLSegmentationResult.h", + "//tensorflow_lite_support/odml/ios/image:apis/GMLImage.h", + ], +) + # This target builds a monolithic static framework for the TFLite Text API, # which includes the TFLite runtime in it. # @@ -59,39 +83,6 @@ tflite_ios_framework( ], ) -# 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:TensorFlowLiteTaskVisionC_framework -tflite_ios_framework( - name = "TensorFlowLiteTaskVisionC_framework", - hdrs = [ - ":base_options.h", - ":bounding_box.h", - ":category.h", - ":classification_options.h", - ":classification_result.h", - ":common.h", - ":detection_result.h", - ":frame_buffer.h", - ":image_classifier.h", - ":image_segmenter.h", - ":object_detector.h", - ":segmentation_result.h", - ], - allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", - bundle_name = "TensorFlowLiteTaskVisionC", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - "//tensorflow_lite_support/c/task/vision:image_classifier", - "//tensorflow_lite_support/c/task/vision:image_segmenter", - "//tensorflow_lite_support/c/task/vision:object_detector", - ], -) - objc_library( name = "TFLCommon", hdrs = [ @@ -120,3 +111,35 @@ objc_library( "//tensorflow_lite_support/ios:TFLCommon", ], ) + +# 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", + hdrs = [ + ":TFLImageClassifier.h", + # ":TFLObjectDetector.h", + # ":TFLImageSegmenter.h", + ":TFLCommon.h", + ":TFLBaseOptions.h", + ":TFLClassificationOptions.h", + ":TFLCategory.h", + ":TFLClassificationResult.h", + # ":TFLDetectionResult.h", + # ":TFLSegmentationResult.h", + ":GMLImage.h", + ], + bundle_name = "TensorFlowLiteTaskVision", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", + # "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", + # "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", + ], +) + From 485949cb45a8ddf9418683284e7ee6094f47a65c Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 22 Jun 2022 21:10:13 +0530 Subject: [PATCH 18/39] Updated .bzl --- tensorflow_lite_support/ios/ios.bzl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tensorflow_lite_support/ios/ios.bzl b/tensorflow_lite_support/ios/ios.bzl index cb8c92ac2..abcac553a 100644 --- a/tensorflow_lite_support/ios/ios.bzl +++ b/tensorflow_lite_support/ios/ios.bzl @@ -28,3 +28,32 @@ def strip_c_api_include_path_prefix(name, hdr_labels, prefix = ""): > "$@" """.format(prefix, hdr_label), ) + +# When the static framework is built with bazel, all the header files are moved +# to the "Headers" directory with no header path prefixes. This auxiliary rule +# is used for stripping the path prefix from the iOS API header files imported by +# other iOS API header files. +def strip_ios_api_include_path_prefix(name, hdr_labels, prefix = ""): + """Create modified header files with the import path stripped out. + + Args: + name: The name to be used as a prefix to the generated genrules. + hdr_labels: List of header labels to strip out the include path. Each + label must end with a colon followed by the header file name. + prefix: Optional prefix path to prepend to the header inclusion path. + """ + for hdr_label in hdr_labels: + hdr_filename = hdr_label.split(":")[-1] + hdr_filename = hdr_filename.split("/")[-1] + hdr_basename = hdr_filename.split(".")[0] + native.genrule( + name = "{}_{}".format(name, hdr_basename), + srcs = [hdr_label], + outs = [hdr_filename], + cmd = """ + sed 's|#import ".*/\\([^/]\\{{1,\\}}\\.h\\)"|#import "{}\\1"|'\ + "$(location {})"\ + > "$@" + """.format(prefix, hdr_label), + ) + From 00d8993c8fc7a12a35e2255a7f29faa100c09b5a Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 22 Jun 2022 23:56:58 +0530 Subject: [PATCH 19/39] Updated files --- .../c/task/vision/image_classifier.cc | 20 +++++++++---------- tensorflow_lite_support/ios/BUILD | 4 ++-- tensorflow_lite_support/ios/task/vision/BUILD | 3 +++ .../test/task/vision/image_classifier/BUILD | 2 +- tensorflow_lite_support/odml/ios/image/BUILD | 2 ++ 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/tensorflow_lite_support/c/task/vision/image_classifier.cc b/tensorflow_lite_support/c/task/vision/image_classifier.cc index 37abe8182..701bec82e 100644 --- a/tensorflow_lite_support/c/task/vision/image_classifier.cc +++ b/tensorflow_lite_support/c/task/vision/image_classifier.cc @@ -88,16 +88,16 @@ StatusOr CreateImageClassifierCppOptionsFromCOptions( cpp_options.set_score_threshold( c_options->classification_options.score_threshold); - cpp_options.mutable_base_options() - ->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); + // cpp_options.mutable_base_options() + // ->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; } diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 1bec4aad1..4f38198f4 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -120,7 +120,7 @@ objc_library( # iOS devices. # bazel build -c opt --config=ios_arm64 //tensorflow_lite_support/ios:TensorFlowLiteTaskVision_framework ios_static_framework( - name = "TensorFlowLiteTaskVision_framework", + name = "TensorFlowLiteTaskVisionCoreml_framework", hdrs = [ ":TFLImageClassifier.h", # ":TFLObjectDetector.h", @@ -134,7 +134,7 @@ ios_static_framework( # ":TFLSegmentationResult.h", ":GMLImage.h", ], - bundle_name = "TensorFlowLiteTaskVision", + bundle_name = "TensorFlowLiteTaskVisionCoreml_framework", minimum_os_version = TFL_MINIMUM_OS_VERSION, deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 0a756dc56..f43cc6cc3 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -1,3 +1,5 @@ +load("@org_tensorflow//tensorflow/lite/ios:ios.bzl", "TFL_DEFAULT_TAGS", "TFL_DISABLED_SANITIZER_TAGS", "TFL_MINIMUM_OS_VERSION") + package( default_visibility = ["//tensorflow_lite_support:internal"], licenses = ["notice"], # Apache 2.0 @@ -24,6 +26,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:gpu_plugin", ], ) diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD index fb05c4e01..0c31e21b6 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD @@ -45,7 +45,7 @@ objc_library( deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:gpu_plugin", + # "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:_plugin", ], ) diff --git a/tensorflow_lite_support/odml/ios/image/BUILD b/tensorflow_lite_support/odml/ios/image/BUILD index 24fff353f..63e3db87d 100644 --- a/tensorflow_lite_support/odml/ios/image/BUILD +++ b/tensorflow_lite_support/odml/ios/image/BUILD @@ -65,6 +65,8 @@ TEST_COPTS = RELEASE_COPTS + [ "-Wno-shadow", ] +exports_files(["apis/GMLImage.h"]) + objc_library( name = "MLImage", srcs = SOURCES, From c940ef6d56808c8bfc74db8902a0e175b84b2000 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 23 Jun 2022 11:58:08 +0530 Subject: [PATCH 20/39] Updated files --- .../c/task/vision/image_classifier.cc | 20 +++++++++---------- tensorflow_lite_support/ios/BUILD | 2 +- ...plate => TensorFlowLiteTaskVision.podspec} | 10 +++++----- tensorflow_lite_support/ios/task/vision/BUILD | 2 +- .../test/task/vision/image_classifier/BUILD | 2 +- .../builds/build_ios_vision_framework.sh | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) rename tensorflow_lite_support/ios/{TensorFlowLiteTaskVision.podspec.template => TensorFlowLiteTaskVision.podspec} (70%) diff --git a/tensorflow_lite_support/c/task/vision/image_classifier.cc b/tensorflow_lite_support/c/task/vision/image_classifier.cc index 701bec82e..37abe8182 100644 --- a/tensorflow_lite_support/c/task/vision/image_classifier.cc +++ b/tensorflow_lite_support/c/task/vision/image_classifier.cc @@ -88,16 +88,16 @@ StatusOr CreateImageClassifierCppOptionsFromCOptions( cpp_options.set_score_threshold( c_options->classification_options.score_threshold); - // cpp_options.mutable_base_options() - // ->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); + cpp_options.mutable_base_options() + ->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; } diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 4f38198f4..19e12372b 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -135,7 +135,7 @@ ios_static_framework( ":GMLImage.h", ], bundle_name = "TensorFlowLiteTaskVisionCoreml_framework", - minimum_os_version = TFL_MINIMUM_OS_VERSION, + minimum_os_version = "11.0", deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", # "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec similarity index 70% rename from tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template rename to tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec index 08f90aee6..e6b4b902b 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec @@ -1,14 +1,14 @@ Pod::Spec.new do |s| s.name = 'TensorFlowLiteTaskVision' - s.version = '${TFLS_BUILD_VERSION}' + s.version = '0.1.6' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE"} s.homepage = 'https://github.com/tensorflow/tflite-support' - s.source = { :http => 'https://dl.dropboxusercontent.com/s/kr3ngm6ji9ei8r5/TensorFlowLiteTaskVisionObjCPP-0.1.3-dev.tar.gz?dl=0' } + s.source = { :http => 'https://dl.dropboxusercontent.com/s/47aapsp0a00i1q4/TensorFlowLiteTaskVisionCoreml-0.1.6-dev.tar.gz?dl=0' } s.summary = 'TensorFlow Lite Task Library - Vision' s.description = 'The Computer Vision APIs of the TFLite Task Library' - s.ios.deployment_target = '10.0' + s.ios.deployment_target = '11.0' s.module_name = 'TensorFlowLiteTaskVision' s.static_framework = true @@ -16,6 +16,6 @@ Pod::Spec.new do |s| 'VALID_ARCHS' => 'x86_64, arm64, armv7', } s.library = 'c++' - s.frameworks = 'CoreMedia', 'Accelerate' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVision.framework' + s.frameworks = 'CoreMedia', 'Accelerate', 'CoreML' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionCoreml_framework.framework' end diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 6915228da..f9325f504 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -26,7 +26,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:gpu_plugin", + "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", ], ) diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD index 0c31e21b6..407b5ddc1 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD @@ -72,7 +72,7 @@ objc_library( "//tensorflow_lite_support/c/task/vision/utils:frame_buffer_cpp_c_utils", "//tensorflow_lite_support/cc/task/vision:image_classifier", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", + # "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", ], copts = ["-std=c++14"], ) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh index 27fea03c6..e8b3ef40d 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh @@ -45,7 +45,7 @@ if [ -z ${FRAMEWORK_NAME+x} ]; then fi case $FRAMEWORK_NAME in - "TensorFlowLiteTaskVision") + "TensorFlowLiteTaskVisionCoreml") ;; *) echo "Wrong framework name" From 613238cfe21e15c7013c8e7d2df37bb8a2444d56 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 22:55:06 +0530 Subject: [PATCH 21/39] Removed comments --- tensorflow_lite_support/ios/BUILD | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 19e12372b..2dbb06b67 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -120,26 +120,25 @@ objc_library( # iOS devices. # bazel build -c opt --config=ios_arm64 //tensorflow_lite_support/ios:TensorFlowLiteTaskVision_framework ios_static_framework( - name = "TensorFlowLiteTaskVisionCoreml_framework", + name = "TensorFlowLiteTaskVision_framework", hdrs = [ ":TFLImageClassifier.h", - # ":TFLObjectDetector.h", - # ":TFLImageSegmenter.h", + ":TFLObjectDetector.h", + ":TFLImageSegmenter.h", ":TFLCommon.h", ":TFLBaseOptions.h", ":TFLClassificationOptions.h", ":TFLCategory.h", ":TFLClassificationResult.h", - # ":TFLDetectionResult.h", - # ":TFLSegmentationResult.h", + ":TFLDetectionResult.h", + ":TFLSegmentationResult.h", ":GMLImage.h", ], - bundle_name = "TensorFlowLiteTaskVisionCoreml_framework", + bundle_name = "TensorFlowLiteTaskVision_framework", minimum_os_version = "11.0", deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", - # "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", - # "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", + "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", + "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", ], ) - From 937c75327c2cd3e5398450f3e377e9f5feb85d4f Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:20:39 +0530 Subject: [PATCH 22/39] Updated files --- tensorflow_lite_support/ios/BUILD | 18 --- tensorflow_lite_support/ios/ios.bzl | 14 +- .../builds/build_ios_vision_framework.sh | 128 ------------------ 3 files changed, 7 insertions(+), 153 deletions(-) delete mode 100755 tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 58ee14dc5..4d294d03f 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -59,24 +59,6 @@ strip_api_include_path_prefix( ], ) -strip_ios_api_include_path_prefix( - name = "strip_ios_api_include_path", - hdr_labels = [ - "//tensorflow_lite_support/ios/task/vision:sources/TFLImageEmbedder.h", - "//tensorflow_lite_support/ios/task/vision:sources/TFLImageClassifier.h", - "//tensorflow_lite_support/ios/task/vision:sources/TFLObjectDetector.h", - "//tensorflow_lite_support/ios/task/vision:sources/TFLImageSegmenter.h", - "//tensorflow_lite_support/ios:sources/TFLCommon.h", - "//tensorflow_lite_support/ios/task/core:sources/TFLBaseOptions.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationOptions.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLCategory.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLClassificationResult.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLDetectionResult.h", - "//tensorflow_lite_support/ios/task/processor:sources/TFLSegmentationResult.h", - "//tensorflow_lite_support/odml/ios/image:apis/GMLImage.h", - ], -) - # This target builds a monolithic static framework for the TFLite Text API, # which includes the TFLite runtime in it. # diff --git a/tensorflow_lite_support/ios/ios.bzl b/tensorflow_lite_support/ios/ios.bzl index 3889c65cf..addb8768f 100644 --- a/tensorflow_lite_support/ios/ios.bzl +++ b/tensorflow_lite_support/ios/ios.bzl @@ -1,15 +1,14 @@ """TensorFlow Lite Support Library Helper Rules for iOS""" -# When the static framework is built with bazel, all the header files are moved +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" -TFL_TASK_COREML_MINIMUM_OS_VERSION = "11.0" - def strip_api_include_path_prefix(name, hdr_labels, prefix = ""): """Create modified header files with the import path stripped out. @@ -21,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] diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh deleted file mode 100755 index e8b3ef40d..000000000 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_vision_framework.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== - -# Set the following variables as appropriate. -# * BAZEL: path to bazel. defaults to the first one available in PATH -# * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the -# * accepted values are TensorFlowLiteTaskVision, TensorFlowLiteTaskText. -# * TFLS_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev -# * IS_RELEASE_BUILD: set as true if this build should be a release build -# * ARCHIVE_FRAMEWORK: set as true if the framework should be archived -# * DEST_DIR: destination directory to which the framework will be copied - -set -ex - -if [[ "$(uname)" != "Darwin" ]]; then - echo "This build script only works on macOS." - exit 1 -fi - -BAZEL="${BAZEL:-$(which bazel)}" -TFLS_BUILD_VERSION=${TFLS_BUILD_VERSION:-0.0.1-dev} -TFLS_ROOT_DIR=$(git rev-parse --show-toplevel) - -if [[ ! -x "${BAZEL}" ]]; then - echo "bazel executable is not found." - exit 1 -fi - -if [ -z ${FRAMEWORK_NAME+x} ]; then - echo "Name of the iOS framework, which is to be built, must be set." - exit 1 -fi - -case $FRAMEWORK_NAME in - "TensorFlowLiteTaskVisionCoreml") - ;; - *) - echo "Wrong framework name" - exit 1 - ;; -esac - -if [[ -z "${DEST_DIR+x}" || "${DEST_DIR}" == ${TFLS_ROOT_DIR}* ]]; then - echo "DEST_DIR variable must be set and not be under the repository root." - exit 1 -fi - -function build_ios_api_framework { - "${BAZEL}" build -c opt --config=ios_fat \ - //tensorflow_lite_support/ios:$1_framework -} - -function create_framework_archive { - TARGET_FRAMEWORK_NAME="$1" - # IOS_API_FRAMEWORK_NAME="$1C" - - TFLS_IOS_DIR=tensorflow_lite_support/ios - BAZEL_IOS_OUTDIR="bazel-bin/${TFLS_IOS_DIR}" - - # Change to the Bazel iOS output directory. - pushd "${BAZEL_IOS_OUTDIR}" - - # Create the temporary directory for the given framework. - ARCHIVE_NAME="${TARGET_FRAMEWORK_NAME}-${TFLS_BUILD_VERSION}" - TFLS_TMPDIR="$(mktemp -d)" - - # Copy the license file to TFLS_TMPDIR - cp "${TFLS_ROOT_DIR}/LICENSE" ${TFLS_TMPDIR} - FRAMEWORK_LOCATION=$(find "${TFLS_ROOT_DIR}/bazel-out/" -name ${TARGET_FRAMEWORK_NAME}_framework.zip) - - for path in ${FRAMEWORK_LOCATION} - do - unzip ${path} -d "${TFLS_TMPDIR}"/Frameworks - break - done - - #----- (3) Move the framework to the destination ----- - if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then - TARGET_DIR="$(realpath "${TARGET_FRAMEWORK_NAME}")" - - # Create the framework archive directory. - if [[ "${IS_RELEASE_BUILD}" == true ]]; then - # Get the first 16 bytes of the sha256 checksum of the root directory. - SHA256_CHECKSUM=$(find "${TFLS_TMPDIR}" -type f -print0 | xargs -0 shasum -a 256 | sort | shasum -a 256 | cut -c1-16) - FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}/${SHA256_CHECKSUM}" - else - FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${TFLS_BUILD_VERSION}" - fi - mkdir -p "${FRAMEWORK_ARCHIVE_DIR}" - - # Zip up the framework and move to the archive directory. - pushd "${TFLS_TMPDIR}" - TFLS_ARCHIVE_FILE="${ARCHIVE_NAME}.tar.gz" - tar -cvzf "${TFLS_ARCHIVE_FILE}" . - mv "${TFLS_ARCHIVE_FILE}" "${FRAMEWORK_ARCHIVE_DIR}" - popd - - # Move the target directory to the Kokoro artifacts directory. - mv "${TARGET_DIR}" "$(realpath "${DEST_DIR}")"/ - else - rsync -r "${TFLS_TMPDIR}/" "$(realpath "${DEST_DIR}")/" - fi - - # Clean up the temporary directory for the framework. - rm -rf "${TFLS_TMPDIR}" - echo ${TFLS_TMPDIR} - - # Pop back to the TFLS root directory. - popd -} - -cd "${TFLS_ROOT_DIR}" -build_ios_api_framework $FRAMEWORK_NAME -create_framework_archive $FRAMEWORK_NAME - From eb8d04e2ace1675a98f0281c9b3100e4f063bf58 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:34:04 +0530 Subject: [PATCH 23/39] Added back missing target --- tensorflow_lite_support/ios/BUILD | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index 4d294d03f..e718cda29 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -81,6 +81,39 @@ tflite_ios_framework( ], ) +# 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:TensorFlowLiteTaskVisionC_framework +tflite_ios_framework( + name = "TensorFlowLiteTaskVisionC_framework", + hdrs = [ + ":base_options.h", + ":bounding_box.h", + ":category.h", + ":classification_options.h", + ":classification_result.h", + ":common.h", + ":detection_result.h", + ":frame_buffer.h", + ":image_classifier.h", + ":image_segmenter.h", + ":object_detector.h", + ":segmentation_result.h", + ], + allowlist_symbols_file = ":allowlist_TensorFlowLiteTaskVision.txt", + bundle_name = "TensorFlowLiteTaskVisionC", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow_lite_support/c/task/vision:image_classifier", + "//tensorflow_lite_support/c/task/vision:image_segmenter", + "//tensorflow_lite_support/c/task/vision:object_detector", + ], +) + objc_library( name = "TFLCommon", hdrs = [ From 0e16c33081dd2d0a267f8ffa79267ffef810aed5 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:34:38 +0530 Subject: [PATCH 24/39] Deleted podspec --- .../ios/TensorFlowLiteTaskVision.podspec | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec deleted file mode 100644 index e6b4b902b..000000000 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec +++ /dev/null @@ -1,21 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'TensorFlowLiteTaskVision' - s.version = '0.1.6' - s.authors = 'Google Inc.' - s.license = { :type => 'Apache',:file => "LICENSE"} - s.homepage = 'https://github.com/tensorflow/tflite-support' - s.source = { :http => 'https://dl.dropboxusercontent.com/s/47aapsp0a00i1q4/TensorFlowLiteTaskVisionCoreml-0.1.6-dev.tar.gz?dl=0' } - s.summary = 'TensorFlow Lite Task Library - Vision' - s.description = 'The Computer Vision APIs of the TFLite Task Library' - - s.ios.deployment_target = '11.0' - - s.module_name = 'TensorFlowLiteTaskVision' - s.static_framework = true - s.pod_target_xcconfig = { - 'VALID_ARCHS' => 'x86_64, arm64, armv7', - } - s.library = 'c++' - s.frameworks = 'CoreMedia', 'Accelerate', 'CoreML' - s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVisionCoreml_framework.framework' -end From 5578f2cf2185bc46aa0fec941924b4837122d0d7 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:36:46 +0530 Subject: [PATCH 25/39] Removed unnecessary files --- tensorflow_lite_support/ios/task/vision/BUILD | 20 +------- .../task/vision/sources/TFLImageEmbedder.h | 29 ----------- .../task/vision/sources/TFLImageEmbedder.mm | 50 ------------------- 3 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h delete mode 100644 tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index f9325f504..37f9db4c2 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -1,5 +1,3 @@ -load("@org_tensorflow//tensorflow/lite/ios:ios.bzl", "TFL_DEFAULT_TAGS", "TFL_DISABLED_SANITIZER_TAGS", "TFL_MINIMUM_OS_VERSION") - package( default_visibility = ["//tensorflow_lite_support:internal"], licenses = ["notice"], # Apache 2.0 @@ -26,7 +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", + "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:gpu_plugin", ], ) @@ -75,19 +73,3 @@ objc_library( "//tensorflow_lite_support/odml/ios/image:MLImage", ], ) - -objc_library( - name = "TFLImageEmbedder", - srcs = [ - "sources/TFLImageEmbedder.mm", - ], - hdrs = [ - "sources/TFLImageEmbedder.h", - ], - features = ["-layering_check"], - module_name = "TFLImageEmbedder", - deps = [ - "//tensorflow_lite_support/cc/task/vision:image_embedder", - ], - copts = ["-ObjC++","-std=c++14"], -) diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h deleted file mode 100644 index cc17766c4..000000000 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ==============================================================================*/ -#import - - -NS_ASSUME_NONNULL_BEGIN - -/** - * A TensorFlow Lite Task Image Classifiier. - */ -NS_SWIFT_NAME(ImageEmbedder) -@interface TFLImageEmbedder : NSObject - -- (instancetype)initWithModelPath:(NSString *)modelPath; -@end - -NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm b/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm deleted file mode 100644 index 78deec058..000000000 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.mm +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ==============================================================================*/ - -#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h" -#include "tensorflow_lite_support/cc/task/vision/image_embedder.h" - -namespace { -using ImageEmbedderCpp = ::tflite::task::vision::ImageEmbedder; -using ImageEmbedderOptionsCpp = - ::tflite::task::vision::ImageEmbedderOptions; -using ::tflite::support::StatusOr; -} - -@implementation TFLImageEmbedder { - std::unique_ptr cppImageEmbedder; -} - -- (instancetype)initWithModelPath:(NSString *)modelPath { - self = [super init]; - if (self) { - ImageEmbedderOptionsCpp cc_options; - - cc_options.mutable_model_file_with_metadata()->set_file_name(modelPath.UTF8String); - - StatusOr> embedder_status = - ImageEmbedderCpp::CreateFromOptions(cc_options); - - if (embedder_status.ok()) { - cppImageEmbedder = std::move(embedder_status.value()); - } - else { - return nil; - } - } - return self; -} - -@end From ceab44c636d0e416b669f08601c75e1f8187b706 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:38:51 +0530 Subject: [PATCH 26/39] Added back missing files --- .../ios/task/vision/apis/TFLTaskVision.h | 25 +++++++++++++++++++ .../ios/task/vision/apis/framework.modulemap | 4 +++ 2 files changed, 29 insertions(+) create mode 100644 tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h create mode 100644 tensorflow_lite_support/ios/task/vision/apis/framework.modulemap diff --git a/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h new file mode 100644 index 000000000..3eb4f4964 --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/apis/TFLTaskVision.h @@ -0,0 +1,25 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GMLImage.h" +#import "TFLBaseOptions.h" +#import "TFLCategory.h" +#import "TFLClassificationOptions.h" +#import "TFLClassificationResult.h" +#import "TFLCommon.h" +#import "TFLDetectionResult.h" +#import "TFLImageClassifier.h" +#import "TFLImageSegmenter.h" +#import "TFLObjectDetector.h" +#import "TFLSegmentationResult.h" diff --git a/tensorflow_lite_support/ios/task/vision/apis/framework.modulemap b/tensorflow_lite_support/ios/task/vision/apis/framework.modulemap new file mode 100644 index 000000000..b89443cca --- /dev/null +++ b/tensorflow_lite_support/ios/task/vision/apis/framework.modulemap @@ -0,0 +1,4 @@ +framework module TensorFlowLiteTaskVision { + umbrella header "TFLTaskVision.h" + export * +} From af96597c50c6ccdf54d968f42120169565abc8f3 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:42:37 +0530 Subject: [PATCH 27/39] Removed image embedder files --- .../ios/test/task/vision/image_embedder/BUILD | 36 ---------------- .../image_embedder/TFLImageEmbedderTests.m | 42 ------------------- 2 files changed, 78 deletions(-) delete mode 100644 tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD delete mode 100644 tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m diff --git a/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD deleted file mode 100644 index 74224e4ee..000000000 --- a/tensorflow_lite_support/ios/test/task/vision/image_embedder/BUILD +++ /dev/null @@ -1,36 +0,0 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") -load("@org_tensorflow//tensorflow/lite/ios:ios.bzl", "TFL_DEFAULT_TAGS", "TFL_DISABLED_SANITIZER_TAGS", "TFL_MINIMUM_OS_VERSION") -load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") -load("@org_tensorflow//tensorflow/lite:special_rules.bzl", "tflite_ios_lab_runner") - -package( - default_visibility = ["//visibility:private"], - licenses = ["notice"], # Apache 2.0 -) - - -objc_library( - name = "TFLImageEmbedderObjcTestLibrary", - testonly = 1, - srcs = ["TFLImageEmbedderTests.m"], - data = [ - "//tensorflow_lite_support/cc/test/testdata/task/vision:test_images", - "//tensorflow_lite_support/cc/test/testdata/task/vision:test_models", - ], - tags = TFL_DEFAULT_TAGS, - deps = [ - "//tensorflow_lite_support/ios/task/vision:TFLImageEmbedder", - "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - ], -) - -ios_unit_test( - name = "TFLImageEmbedderObjcTest", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - runner = tflite_ios_lab_runner("IOS_LATEST"), - tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS, - deps = [ - ":TFLImageEmbedderObjcTestLibrary", - ], -) - diff --git a/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m b/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m deleted file mode 100644 index 093c5f22c..000000000 --- a/tensorflow_lite_support/ios/test/task/vision/image_embedder/TFLImageEmbedderTests.m +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ==============================================================================*/ -#import - -#import "tensorflow_lite_support/ios/task/vision/sources/TFLImageEmbedder.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface TFLImageEmbedderTests : XCTestCase -@property(nonatomic, nullable) NSString *modelPath; -@end - -@implementation TFLImageEmbedderTests - -- (void)setUp { - // Put setup code here. This method is called before the invocation of each test method in the - // class. - [super setUp]; - self.modelPath = [[NSBundle bundleForClass:self.class] pathForResource:@"mobilenet_v3_small_100_224_embedder" - ofType:@"tflite"]; - XCTAssertNotNil(self.modelPath); -} - -- (void)testInitSucceeds { - TFLImageEmbedder *embedder = [[TFLImageEmbedder alloc] initWithModelPath:self.modelPath]; - XCTAssertNotNil(embedder); -} -@end - -NS_ASSUME_NONNULL_END From 90bc6890c6b45e2548ae745a14d84204fa81dce3 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 14 Jul 2022 23:53:32 +0530 Subject: [PATCH 28/39] Added back coreml plugin --- tensorflow_lite_support/ios/task/vision/BUILD | 2 +- .../ios/test/task/vision/image_classifier/BUILD | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 37f9db4c2..d4c38a866 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -24,7 +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:gpu_plugin", + "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", ], ) diff --git a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD index 407b5ddc1..ca4753646 100644 --- a/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD +++ b/tensorflow_lite_support/ios/test/task/vision/image_classifier/BUILD @@ -45,7 +45,6 @@ objc_library( deps = [ "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - # "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:_plugin", ], ) @@ -72,7 +71,7 @@ objc_library( "//tensorflow_lite_support/c/task/vision/utils:frame_buffer_cpp_c_utils", "//tensorflow_lite_support/cc/task/vision:image_classifier", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - # "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", + "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", ], copts = ["-std=c++14"], ) From c4271845846c66c955f4d9bd99f60d08dd36fa04 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 15 Jul 2022 01:02:09 +0530 Subject: [PATCH 29/39] Updated vision podspec --- tensorflow_lite_support/ios/BUILD | 2 +- .../ios/TensorFlowLiteTaskVision.podspec.template | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index e718cda29..d3a60ee8b 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -171,7 +171,7 @@ ios_static_framework( "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", - ], + ], ) ios_static_framework( diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index e229b92b8..c1d052631 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.summary = 'TensorFlow Lite Task Library - Vision' s.description = 'The Computer Vision APIs of the TFLite Task Library' - s.ios.deployment_target = '10.0' + s.ios.deployment_target = '11.0' s.module_name = 'TensorFlowLiteTaskVision' s.static_framework = true @@ -16,6 +16,6 @@ Pod::Spec.new do |s| 'VALID_ARCHS' => 'x86_64, arm64, armv7', } s.library = 'c++' - s.frameworks = 'CoreMedia', 'Accelerate' + s.frameworks = 'CoreMedia', 'Accelerate', 'CoreML' s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVision.framework' end \ No newline at end of file From c0518c9e1b4ee159e2b1036096cf561bc113ae0f Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Mon, 25 Jul 2022 10:32:19 +0530 Subject: [PATCH 30/39] Updated podspec --- tensorflow_lite_support/c/task/vision/image_classifier.cc | 2 ++ ...ion.podspec.template => TensorFlowLiteTaskVision.podspec} | 5 +++-- .../tools/ci_build/builds/build_ios_framework.sh | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) rename tensorflow_lite_support/ios/{TensorFlowLiteTaskVision.podspec.template => TensorFlowLiteTaskVision.podspec} (73%) diff --git a/tensorflow_lite_support/c/task/vision/image_classifier.cc b/tensorflow_lite_support/c/task/vision/image_classifier.cc index 37abe8182..9b74ad317 100644 --- a/tensorflow_lite_support/c/task/vision/image_classifier.cc +++ b/tensorflow_lite_support/c/task/vision/image_classifier.cc @@ -99,6 +99,8 @@ StatusOr CreateImageClassifierCppOptionsFromCOptions( ->mutable_coreml_settings() ->set_enabled_devices(tflite::proto::CoreMLSettings::DEVICES_ALL); + std::cout << "Linked core ml" << std::endl; + return cpp_options; } } // namespace diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec similarity index 73% rename from tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template rename to tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec index c1d052631..99c3b6ce2 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec @@ -1,10 +1,11 @@ Pod::Spec.new do |s| s.name = 'TensorFlowLiteTaskVision' - s.version = '${TFLS_BUILD_VERSION}' + s.version = '5.0.0' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE" } + #https://www.dropbox.com/s/vns5malr1sxy8u4/TensorFlowLiteTaskVision-5.0.0-dev.tar.gz?dl=0 s.homepage = 'https://github.com/tensorflow/tflite-support' - s.source = { :http => '${TFLS_DOWNLOAD_URL}' } + s.source = { :http => 'https://dl.dropboxusercontent.com/s/vns5malr1sxy8u4/TensorFlowLiteTaskVision-5.0.0-dev.tar.gz?dl=0' } s.summary = 'TensorFlow Lite Task Library - Vision' s.description = 'The Computer Vision APIs of the TFLite Task Library' diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 9dfd8746e..82e40862a 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -84,7 +84,7 @@ function build_ios_api_framework { local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + "${BAZEL}" build -c opt --config=ios_fat --apple_platform_type=ios ${FULL_TARGET} # Find the path of the iOS framework generated by the above bazel build command local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" From b5d82162cfa26c5554ea0c14a19ff543cfe813d0 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 28 Jul 2022 15:51:06 +0530 Subject: [PATCH 31/39] Removed log --- tensorflow_lite_support/c/task/vision/image_classifier.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/tensorflow_lite_support/c/task/vision/image_classifier.cc b/tensorflow_lite_support/c/task/vision/image_classifier.cc index 9b74ad317..37abe8182 100644 --- a/tensorflow_lite_support/c/task/vision/image_classifier.cc +++ b/tensorflow_lite_support/c/task/vision/image_classifier.cc @@ -99,8 +99,6 @@ StatusOr CreateImageClassifierCppOptionsFromCOptions( ->mutable_coreml_settings() ->set_enabled_devices(tflite::proto::CoreMLSettings::DEVICES_ALL); - std::cout << "Linked core ml" << std::endl; - return cpp_options; } } // namespace From bed5efe573639b0181f446cba717b8c130c8ef52 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:10:38 +0530 Subject: [PATCH 32/39] Added manual triggering of registration --- .../acceleration/configuration/BUILD | 12 +++++++++ .../configuration/coreml_plugin.h | 27 +++++++++++++++++++ tensorflow_lite_support/cc/port/default/BUILD | 1 + .../cc/port/default/tflite_wrapper.cc | 5 ++++ ...TensorFlowLiteTaskVision.podspec.template} | 9 +++---- tensorflow_lite_support/ios/ios.bzl | 2 +- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 tensorflow_lite_support/acceleration/configuration/coreml_plugin.h rename tensorflow_lite_support/ios/{TensorFlowLiteTaskVision.podspec => TensorFlowLiteTaskVision.podspec.template} (64%) diff --git a/tensorflow_lite_support/acceleration/configuration/BUILD b/tensorflow_lite_support/acceleration/configuration/BUILD index e48a288f9..7709ea9a8 100644 --- a/tensorflow_lite_support/acceleration/configuration/BUILD +++ b/tensorflow_lite_support/acceleration/configuration/BUILD @@ -31,6 +31,18 @@ cc_library( alwayslink = 1, # For registration to always run. ) +cc_library( + name = "coreml_plugin", + hdrs = ["coreml_plugin.h"], + visibility = [ + "//visibility:public", + ], + deps = [ + "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:coreml_plugin", + ], + alwayslink = 1, # For registration to always run. +) + cc_library( name = "hexagon_plugin", visibility = [ diff --git a/tensorflow_lite_support/acceleration/configuration/coreml_plugin.h b/tensorflow_lite_support/acceleration/configuration/coreml_plugin.h new file mode 100644 index 000000000..4b4d14fe5 --- /dev/null +++ b/tensorflow_lite_support/acceleration/configuration/coreml_plugin.h @@ -0,0 +1,27 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_SUPPORT_ACCELERATION_CONFIGURATION_COREML_PLUGIN_H_ +#define TENSORFLOW_LITE_SUPPORT_ACCELERATION_CONFIGURATION_COREML_PLUGIN_H_ + +namespace tflite { +namespace delegates { +// This function can be called to force link the coreml plugin. +void register_new(); + +} // namespace delegates +} // namespace tflite + + +#endif // TENSORFLOW_LITE_SUPPORT_ACCELERATION_CONFIGURATION_COREML_PLUGIN_H_ diff --git a/tensorflow_lite_support/cc/port/default/BUILD b/tensorflow_lite_support/cc/port/default/BUILD index f506a7c35..547b66325 100644 --- a/tensorflow_lite_support/cc/port/default/BUILD +++ b/tensorflow_lite_support/cc/port/default/BUILD @@ -41,6 +41,7 @@ cc_library( "@org_tensorflow//tensorflow/lite:minimal_logging", "@org_tensorflow//tensorflow/lite/c:common", "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:nnapi_plugin", + "//tensorflow_lite_support/acceleration/configuration:coreml_plugin", "@org_tensorflow//tensorflow/lite/delegates:interpreter_utils", "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:configuration_cc_proto", "@org_tensorflow//tensorflow/lite/experimental/acceleration/configuration:delegate_registry", diff --git a/tensorflow_lite_support/cc/port/default/tflite_wrapper.cc b/tensorflow_lite_support/cc/port/default/tflite_wrapper.cc index d47c1ce7e..4c2bd1e33 100644 --- a/tensorflow_lite_support/cc/port/default/tflite_wrapper.cc +++ b/tensorflow_lite_support/cc/port/default/tflite_wrapper.cc @@ -23,6 +23,7 @@ limitations under the License. #include "tensorflow/lite/experimental/acceleration/configuration/proto_to_flatbuffer.h" #include "tensorflow/lite/minimal_logging.h" #include "tensorflow_lite_support/cc/port/status_macros.h" +#include "tensorflow/lite/experimental/acceleration/configuration/coreml_plugin.h" namespace tflite { namespace support { @@ -318,6 +319,10 @@ void TfLiteInterpreterWrapper::SetTfLiteCancellation() { absl::Status TfLiteInterpreterWrapper::LoadDelegatePlugin( const std::string& name, const tflite::TFLiteSettings& tflite_settings) { + + // Calling this function from coreml_plugin to force linking of core ml plugin for device builds. + tflite::delegates::register_new(); + delegate_plugin_ = DelegatePluginRegistry::CreateByName( absl::StrFormat("%sPlugin", name), tflite_settings); diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template similarity index 64% rename from tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec rename to tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index 99c3b6ce2..e229b92b8 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -1,15 +1,14 @@ Pod::Spec.new do |s| s.name = 'TensorFlowLiteTaskVision' - s.version = '5.0.0' + s.version = '${TFLS_BUILD_VERSION}' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE" } - #https://www.dropbox.com/s/vns5malr1sxy8u4/TensorFlowLiteTaskVision-5.0.0-dev.tar.gz?dl=0 s.homepage = 'https://github.com/tensorflow/tflite-support' - s.source = { :http => 'https://dl.dropboxusercontent.com/s/vns5malr1sxy8u4/TensorFlowLiteTaskVision-5.0.0-dev.tar.gz?dl=0' } + s.source = { :http => '${TFLS_DOWNLOAD_URL}' } s.summary = 'TensorFlow Lite Task Library - Vision' s.description = 'The Computer Vision APIs of the TFLite Task Library' - s.ios.deployment_target = '11.0' + s.ios.deployment_target = '10.0' s.module_name = 'TensorFlowLiteTaskVision' s.static_framework = true @@ -17,6 +16,6 @@ Pod::Spec.new do |s| 'VALID_ARCHS' => 'x86_64, arm64, armv7', } s.library = 'c++' - s.frameworks = 'CoreMedia', 'Accelerate', 'CoreML' + s.frameworks = 'CoreMedia', 'Accelerate' s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVision.framework' end \ No newline at end of file diff --git a/tensorflow_lite_support/ios/ios.bzl b/tensorflow_lite_support/ios/ios.bzl index addb8768f..1a2d307a7 100644 --- a/tensorflow_lite_support/ios/ios.bzl +++ b/tensorflow_lite_support/ios/ios.bzl @@ -1,7 +1,7 @@ """TensorFlow Lite Support Library Helper Rules for iOS""" TFL_TASK_MINIMUM_OS_VERSION = "10.0" -TFL_TASK_COREML_MINIMUM_OS_VERSION = "11.0" +TFL_TASK_COREML_MINIMUM_OS_VERSION = "12.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 From c3c867e9faddaf4a4af232c7bde9491fae4ca2e6 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:12:57 +0530 Subject: [PATCH 33/39] Reverted build command --- .../tools/ci_build/builds/build_ios_framework.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 82e40862a..03f21edfc 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -84,8 +84,8 @@ function build_ios_api_framework { local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat --apple_platform_type=ios ${FULL_TARGET} - + "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + # Find the path of the iOS framework generated by the above bazel build command local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH} From 9f2e68ef8741b5704c8691fb525599814c4fd646 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:13:53 +0530 Subject: [PATCH 34/39] Reverted changes --- tensorflow_lite_support/ios/task/vision/BUILD | 1 - .../tools/ci_build/builds/build_ios_framework.sh | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index d4c38a866..0a756dc56 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -24,7 +24,6 @@ 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", ], ) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 03f21edfc..50a480c31 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -84,8 +84,7 @@ function build_ios_api_framework { local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} - + "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} # Find the path of the iOS framework generated by the above bazel build command local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH} From d7ee00eb009e1b6f8a3b12cb8029731bc984d417 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:15:14 +0530 Subject: [PATCH 35/39] Reverted changes in shell script --- .../ci_build/builds/build_ios_framework.sh | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 50a480c31..e60b7e539 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -49,8 +49,10 @@ case $FRAMEWORK_NAME in ;; "TensorFlowLiteTaskText") ;; + "TensorFlowLiteTaskAudio") + ;; *) - echo "Wrong framework name. The following framework names are allowed: TensorFlowLiteTaskVision, TensorFlowLiteTaskText" + echo "Wrong framework name. The following framework names are allowed: TensorFlowLiteTaskVision, TensorFlowLiteTaskText, TensorFlowLiteTaskAudio" exit 1 ;; esac @@ -73,7 +75,7 @@ EOF local FRAMEWORK_PATH=$(bazel cquery --config=ios_fat $1 \ --output=starlark --starlark:file="${STARLARK_FILE}" 2> /dev/null) - # Clean up the temporary directory for bazel cquery. + # Clean up the temporary directory for bazel cquery. rm -rf "${STARLARK_OUTPUT_TMPDIR}" echo ${FRAMEWORK_PATH} @@ -81,12 +83,12 @@ EOF function build_ios_api_framework { local TARGET_PREFIX="//tensorflow_lite_support/ios" - local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + # Find the path of the iOS framework generated by the above bazel build command - local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" + IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH} } @@ -102,8 +104,8 @@ function create_framework_archive { cp "LICENSE" ${TFLS_TMPDIR} # Unzip the iOS framework zip generated by bazel to TFLS_TMPDIR - IOS_FRAMEWORK_PATH="$1" - unzip "${IOS_FRAMEWORK_PATH}" -d "${TFLS_TMPDIR}"/Frameworks + echo ${IOS_FRAMEWORK_PATH} + unzip "${IOS_FRAMEWORK_PATH}" -d "${TFLS_TMPDIR}"/Frameworks #----- (3) Move the framework to the destination ----- if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then @@ -138,5 +140,5 @@ function create_framework_archive { } cd "${TFLS_ROOT_DIR}" -ZIPPED_FRAMEWORK_PATH=$(build_ios_api_framework ${FRAMEWORK_NAME}) -create_framework_archive ${ZIPPED_FRAMEWORK_PATH} \ No newline at end of file +build_ios_api_framework +create_framework_archive \ No newline at end of file From 7985c8f0cc32058bc2a87ac488daef3709251869 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:16:56 +0530 Subject: [PATCH 36/39] Revert "Reverted changes in shell script" This reverts commit d7ee00eb009e1b6f8a3b12cb8029731bc984d417. --- .../ci_build/builds/build_ios_framework.sh | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index e60b7e539..50a480c31 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -49,10 +49,8 @@ case $FRAMEWORK_NAME in ;; "TensorFlowLiteTaskText") ;; - "TensorFlowLiteTaskAudio") - ;; *) - echo "Wrong framework name. The following framework names are allowed: TensorFlowLiteTaskVision, TensorFlowLiteTaskText, TensorFlowLiteTaskAudio" + echo "Wrong framework name. The following framework names are allowed: TensorFlowLiteTaskVision, TensorFlowLiteTaskText" exit 1 ;; esac @@ -75,7 +73,7 @@ EOF local FRAMEWORK_PATH=$(bazel cquery --config=ios_fat $1 \ --output=starlark --starlark:file="${STARLARK_FILE}" 2> /dev/null) - # Clean up the temporary directory for bazel cquery. + # Clean up the temporary directory for bazel cquery. rm -rf "${STARLARK_OUTPUT_TMPDIR}" echo ${FRAMEWORK_PATH} @@ -83,12 +81,12 @@ EOF function build_ios_api_framework { local TARGET_PREFIX="//tensorflow_lite_support/ios" + local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} - + "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} # Find the path of the iOS framework generated by the above bazel build command - IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" + local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH} } @@ -104,8 +102,8 @@ function create_framework_archive { cp "LICENSE" ${TFLS_TMPDIR} # Unzip the iOS framework zip generated by bazel to TFLS_TMPDIR - echo ${IOS_FRAMEWORK_PATH} - unzip "${IOS_FRAMEWORK_PATH}" -d "${TFLS_TMPDIR}"/Frameworks + IOS_FRAMEWORK_PATH="$1" + unzip "${IOS_FRAMEWORK_PATH}" -d "${TFLS_TMPDIR}"/Frameworks #----- (3) Move the framework to the destination ----- if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then @@ -140,5 +138,5 @@ function create_framework_archive { } cd "${TFLS_ROOT_DIR}" -build_ios_api_framework -create_framework_archive \ No newline at end of file +ZIPPED_FRAMEWORK_PATH=$(build_ios_api_framework ${FRAMEWORK_NAME}) +create_framework_archive ${ZIPPED_FRAMEWORK_PATH} \ No newline at end of file From e9c16350581c4fa366913a15ec61f80ce869ef9c Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:17:43 +0530 Subject: [PATCH 37/39] Added space --- .../tools/ci_build/builds/build_ios_framework.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 50a480c31..0c2675123 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -84,7 +84,8 @@ function build_ios_api_framework { local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + # Find the path of the iOS framework generated by the above bazel build command local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH} From 038c044d5db29416e56d2983efe35a17d3b496af Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:18:26 +0530 Subject: [PATCH 38/39] Updated formatting --- .../tools/ci_build/builds/build_ios_framework.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index 0c2675123..f22637028 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -84,8 +84,8 @@ function build_ios_api_framework { local FRAMEWORK_NAME=$1 FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" - "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} - + "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} + # Find the path of the iOS framework generated by the above bazel build command local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH} From 50ac23770e3d2b091923567f9b15ba32347eff8c Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 12 Aug 2022 13:19:10 +0530 Subject: [PATCH 39/39] Updated formatting --- .../tools/ci_build/builds/build_ios_framework.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh index f22637028..9dfd8746e 100755 --- a/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh +++ b/tensorflow_lite_support/tools/ci_build/builds/build_ios_framework.sh @@ -85,7 +85,7 @@ function build_ios_api_framework { FULL_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" "${BAZEL}" build -c opt --config=ios_fat ${FULL_TARGET} - + # Find the path of the iOS framework generated by the above bazel build command local IOS_FRAMEWORK_PATH="$(get_output_file_path "${FULL_TARGET}")" echo ${IOS_FRAMEWORK_PATH}