diff --git a/tensorflow_lite_support/ios/BUILD b/tensorflow_lite_support/ios/BUILD index cf68522d8..a78c0df7b 100644 --- a/tensorflow_lite_support/ios/BUILD +++ b/tensorflow_lite_support/ios/BUILD @@ -44,15 +44,19 @@ strip_api_include_path_prefix( "//tensorflow_lite_support/ios/task/text/qa:Sources/TFLBertQuestionAnswerer.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/task/vision:sources/TFLImageSegmenter.h", + "//tensorflow_lite_support/ios/task/vision:sources/TFLImageSearcher.h", "//tensorflow_lite_support/ios:sources/TFLCommon.h", "//tensorflow_lite_support/ios/task/core:sources/TFLBaseOptions.h", + "//tensorflow_lite_support/ios/task/core:sources/TFLExternalFile.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLEmbeddingOptions.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLSearchOptions.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", + "//tensorflow_lite_support/ios/task/processor:sources/TFLSegmentationResult.h", + "//tensorflow_lite_support/ios/task/processor:sources/TFLSearchResult.h", "//tensorflow_lite_support/ios/task/audio/core:sources/TFLAudioFormat.h", "//tensorflow_lite_support/ios/task/audio/core:sources/TFLFloatBuffer.h", "//tensorflow_lite_support/ios/task/audio/core/audio_record:sources/TFLAudioRecord.h", @@ -153,6 +157,10 @@ objc_library( hdrs = [ "sources/TFLCommonCppUtils.h", ], + copts = [ + "-ObjC++", + "-std=c++17", + ], module_name = "TFLCommonCppUtils", deps = [ ":TFLCommon", @@ -168,8 +176,10 @@ objc_library( ios_static_framework( name = "TensorFlowLiteTaskVision_framework", hdrs = [ - ":GMLImage.h", ":TFLBaseOptions.h", + ":TFLExternalFile.h", + ":TFLSearchOptions.h", + ":TFLEmbeddingOptions.h", ":TFLCategory.h", ":TFLClassificationOptions.h", ":TFLClassificationResult.h", @@ -177,8 +187,11 @@ ios_static_framework( ":TFLDetectionResult.h", ":TFLImageClassifier.h", ":TFLImageSegmenter.h", + ":TFLImageSearcher.h", ":TFLObjectDetector.h", ":TFLSegmentationResult.h", + ":TFLSearchResult.h" + ], bundle_name = "TensorFlowLiteTaskVision", minimum_os_version = TFL_TASK_MINIMUM_OS_VERSION, @@ -186,6 +199,7 @@ ios_static_framework( "//tensorflow_lite_support/ios/task/vision:TFLImageClassifier", "//tensorflow_lite_support/ios/task/vision:TFLImageSegmenter", "//tensorflow_lite_support/ios/task/vision:TFLObjectDetector", + "//tensorflow_lite_support/ios/task/vision:TFLImageSearcher", ], ) @@ -213,6 +227,7 @@ ios_static_framework( ":TFLAudioRecord.h", ":TFLAudioTensor.h", ":TFLBaseOptions.h", + ":TFLExternalFile.h", ":TFLCategory.h", ":TFLClassificationOptions.h", ":TFLClassificationResult.h", diff --git a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template index e229b92b8..95f85e59c 100644 --- a/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template +++ b/tensorflow_lite_support/ios/TensorFlowLiteTaskVision.podspec.template @@ -18,4 +18,5 @@ Pod::Spec.new do |s| s.library = 'c++' s.frameworks = 'CoreMedia', 'Accelerate' s.vendored_frameworks = 'Frameworks/TensorFlowLiteTaskVision.framework' -end \ No newline at end of file + s.dependency 'MLImage', '~> 1.0.0-beta3' +end diff --git a/tensorflow_lite_support/ios/task/core/BUILD b/tensorflow_lite_support/ios/task/core/BUILD index d047db93d..1109e5589 100644 --- a/tensorflow_lite_support/ios/task/core/BUILD +++ b/tensorflow_lite_support/ios/task/core/BUILD @@ -51,7 +51,7 @@ objc_library( hdrs = [ "sources/TFLBaseOptions+CppHelpers.h", ], - module_name = "TFLBaseOptionsHelpers", + module_name = "TFLBaseOptionsCppHelpers", deps = [ "//tensorflow_lite_support/cc/task/core/proto:base_options_proto_inc", "//tensorflow_lite_support/ios/task/core:TFLBaseOptions", diff --git a/tensorflow_lite_support/ios/task/vision/BUILD b/tensorflow_lite_support/ios/task/vision/BUILD index 52ce3b026..fddfbd0c9 100644 --- a/tensorflow_lite_support/ios/task/vision/BUILD +++ b/tensorflow_lite_support/ios/task/vision/BUILD @@ -23,7 +23,7 @@ objc_library( "//tensorflow_lite_support/ios/task/processor:TFLClassificationResult", "//tensorflow_lite_support/ios/task/processor:TFLClassificationResultHelpers", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - "//tensorflow_lite_support/odml/ios/image:MLImage", + "//tensorflow_lite_support/ios/third_party_frameworks:MLImage", ], ) @@ -46,8 +46,8 @@ objc_library( "//tensorflow_lite_support/ios/task/processor:TFLClassificationOptionsHelpers", "//tensorflow_lite_support/ios/task/processor:TFLDetectionResult", "//tensorflow_lite_support/ios/task/processor:TFLDetectionResultHelpers", - "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - "//tensorflow_lite_support/odml/ios/image:MLImage", + "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", + "//tensorflow_lite_support/ios/third_party_frameworks:MLImage", ], ) @@ -69,7 +69,7 @@ objc_library( "//tensorflow_lite_support/ios/task/processor:TFLSegmentationResult", "//tensorflow_lite_support/ios/task/processor:TFLSegmentationResultHelpers", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageUtils", - "//tensorflow_lite_support/odml/ios/image:MLImage", + "//tensorflow_lite_support/ios/third_party_frameworks:MLImage", ], ) @@ -95,5 +95,7 @@ objc_library( "//tensorflow_lite_support/ios/task/processor:TFLSearchOptionsHelpers", "//tensorflow_lite_support/ios/task/processor:TFLSearchResultHelpers", "//tensorflow_lite_support/ios/task/vision/utils:GMLImageCppUtils", - ], + "//tensorflow_lite_support/ios/third_party_frameworks:MLImage", + ], + ) diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifier.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifier.h index f22803414..3c3023b6d 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifier.h +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageClassifier.h @@ -17,7 +17,7 @@ #import "tensorflow_lite_support/ios/task/core/sources/TFLBaseOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLClassificationOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLClassificationResult.h" -#import "tensorflow_lite_support/odml/ios/image/apis/GMLImage.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageSearcher.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageSearcher.h index 667ea674f..583d141e7 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageSearcher.h +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageSearcher.h @@ -18,7 +18,7 @@ #import "tensorflow_lite_support/ios/task/processor/sources/TFLEmbeddingOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLSearchOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLSearchResult.h" -#import "tensorflow_lite_support/odml/ios/image/apis/GMLImage.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLImageSegmenter.h b/tensorflow_lite_support/ios/task/vision/sources/TFLImageSegmenter.h index 7b556dcd3..1302c1221 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLImageSegmenter.h +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLImageSegmenter.h @@ -15,7 +15,7 @@ #import #import "tensorflow_lite_support/ios/task/core/sources/TFLBaseOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLSegmentationResult.h" -#import "tensorflow_lite_support/odml/ios/image/apis/GMLImage.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/tensorflow_lite_support/ios/task/vision/sources/TFLObjectDetector.h b/tensorflow_lite_support/ios/task/vision/sources/TFLObjectDetector.h index 5e3a0e718..32d7e4bf6 100644 --- a/tensorflow_lite_support/ios/task/vision/sources/TFLObjectDetector.h +++ b/tensorflow_lite_support/ios/task/vision/sources/TFLObjectDetector.h @@ -16,7 +16,7 @@ #import "tensorflow_lite_support/ios/task/core/sources/TFLBaseOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLClassificationOptions.h" #import "tensorflow_lite_support/ios/task/processor/sources/TFLDetectionResult.h" -#import "tensorflow_lite_support/odml/ios/image/apis/GMLImage.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/tensorflow_lite_support/ios/task/vision/utils/BUILD b/tensorflow_lite_support/ios/task/vision/utils/BUILD index ccb6c4537..39f2bf0fc 100644 --- a/tensorflow_lite_support/ios/task/vision/utils/BUILD +++ b/tensorflow_lite_support/ios/task/vision/utils/BUILD @@ -22,8 +22,8 @@ objc_library( deps = [ "//tensorflow_lite_support/c/task/vision/core:frame_buffer", "//tensorflow_lite_support/ios:TFLCommonUtils", - "//tensorflow_lite_support/odml/ios/image:MLImage", - ], + "//tensorflow_lite_support/ios/third_party_frameworks:MLImage", + ], ) objc_library( @@ -41,7 +41,7 @@ objc_library( "//tensorflow_lite_support/cc/task/vision/core:frame_buffer", "//tensorflow_lite_support/cc/task/vision/utils:frame_buffer_common_utils", "//tensorflow_lite_support/ios:TFLCommonCppUtils", - "//tensorflow_lite_support/odml/ios/image:MLImage", + "//tensorflow_lite_support/ios/third_party_frameworks:MLImage", "@com_google_absl//absl/strings:str_format", ], ) diff --git a/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+CppUtils.h b/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+CppUtils.h index f5b38903a..ce02dd9bc 100644 --- a/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+CppUtils.h +++ b/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+CppUtils.h @@ -16,7 +16,7 @@ #include "tensorflow_lite_support/cc/task/vision/core/frame_buffer.h" -#import "tensorflow_lite_support/odml/ios/image/apis/GMLImage.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h b/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h index b76870914..a292d1b56 100644 --- a/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h +++ b/tensorflow_lite_support/ios/task/vision/utils/sources/GMLImage+Utils.h @@ -16,7 +16,7 @@ #include "tensorflow_lite_support/c/task/vision/core/frame_buffer.h" -#import "tensorflow_lite_support/odml/ios/image/apis/GMLImage.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/tensorflow_lite_support/ios/third_party_frameworks/BUILD b/tensorflow_lite_support/ios/third_party_frameworks/BUILD new file mode 100644 index 000000000..215b548e8 --- /dev/null +++ b/tensorflow_lite_support/ios/third_party_frameworks/BUILD @@ -0,0 +1,10 @@ +package( + default_visibility = ["//tensorflow_lite_support:internal"], + licenses = ["notice"], # Apache 2.0 +) +load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_framework_import") + +apple_static_framework_import( + name = "MLImage", + framework_imports = glob(["MLImage.framework/**"]), +) diff --git a/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Headers/GMLImage.h b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Headers/GMLImage.h new file mode 100755 index 000000000..110186bb6 --- /dev/null +++ b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Headers/GMLImage.h @@ -0,0 +1,96 @@ +// Copyright 2021 Google LLC. 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 +#import + +NS_ASSUME_NONNULL_BEGIN + +/** Types of image sources. */ +typedef NSInteger GMLImageSourceType NS_TYPED_ENUM NS_SWIFT_NAME(MLImageSourceType); +/** Image source is a `UIImage`. */ +static const GMLImageSourceType GMLImageSourceTypeImage = 0; +/** Image source is a `CVPixelBuffer`. */ +static const GMLImageSourceType GMLImageSourceTypePixelBuffer = 1; +/** Image source is a `CMSampleBuffer`. */ +static const GMLImageSourceType GMLImageSourceTypeSampleBuffer = 2; + +/** An image used in on-device machine learning. */ +NS_SWIFT_NAME(MLImage) +@interface GMLImage : NSObject + +/** Width of the image in pixels. */ +@property(nonatomic, readonly) CGFloat width; + +/** Height of the image in pixels. */ +@property(nonatomic, readonly) CGFloat height; + +/** + * The display orientation of the image. If `imageSourceType` is `.image`, the default value is + * `image.imageOrientation`; otherwise the default value is `.up`. + */ +@property(nonatomic) UIImageOrientation orientation; + +/** The type of the image source. */ +@property(nonatomic, readonly) GMLImageSourceType imageSourceType; + +/** The source image. `nil` if `imageSourceType` is not `.image`. */ +@property(nonatomic, readonly, nullable) UIImage *image; + +/** The source pixel buffer. `nil` if `imageSourceType` is not `.pixelBuffer`. */ +@property(nonatomic, readonly, nullable) CVPixelBufferRef pixelBuffer; + +/** The source sample buffer. `nil` if `imageSourceType` is not `.sampleBuffer`. */ +@property(nonatomic, readonly, nullable) CMSampleBufferRef sampleBuffer; + +/** + * Initializes an `MLImage` object with the given image. + * + * @param image The image to use as the source. Its `CGImage` property must not be `NULL`. + * @return A new `MLImage` instance with the given image as the source. `nil` if the given `image` + * is `nil` or invalid. + */ +- (nullable instancetype)initWithImage:(UIImage *)image NS_DESIGNATED_INITIALIZER; + +/** + * Initializes an `MLImage` object with the given pixel buffer. + * + * @param pixelBuffer The pixel buffer to use as the source. It will be retained by the new + * `MLImage` instance for the duration of its lifecycle. + * @return A new `MLImage` instance with the given pixel buffer as the source. `nil` if the given + * pixel buffer is `nil` or invalid. + */ +- (nullable instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer + NS_DESIGNATED_INITIALIZER; + +/** + * Initializes an `MLImage` object with the given sample buffer. + * + * @param sampleBuffer The sample buffer to use as the source. It will be retained by the new + * `MLImage` instance for the duration of its lifecycle. The sample buffer must be based on a + * pixel buffer (not compressed data). In practice, it should be the video output of the camera + * on an iOS device, not other arbitrary types of `CMSampleBuffer`s. + * @return A new `MLImage` instance with the given sample buffer as the source. `nil` if the given + * sample buffer is `nil` or invalid. + */ +- (nullable instancetype)initWithSampleBuffer:(CMSampleBufferRef)sampleBuffer + NS_DESIGNATED_INITIALIZER; + +/** Unavailable. */ +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Headers/MLImage.h b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Headers/MLImage.h new file mode 100755 index 000000000..9d59ff077 --- /dev/null +++ b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Headers/MLImage.h @@ -0,0 +1 @@ +#import "GMLImage.h" diff --git a/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/MLImage b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/MLImage new file mode 100755 index 000000000..2b045b507 Binary files /dev/null and b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/MLImage differ diff --git a/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Modules/module.modulemap b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Modules/module.modulemap new file mode 100755 index 000000000..9c8e98acd --- /dev/null +++ b/tensorflow_lite_support/ios/third_party_frameworks/MLImage.framework/Modules/module.modulemap @@ -0,0 +1,9 @@ +framework module MLImage { + umbrella header "MLImage.h" + export * + module * { export * } + link framework "CoreGraphics" + link framework "CoreMedia" + link framework "CoreVideo" + link framework "UIKit" +}