-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NOT FOR MERGING] iOS Image Embedder Objective C++ #830
base: master
Are you sure you want to change the base?
Changes from all commits
c9a7767
dc5c057
95522de
5468a42
cf615ba
7b30cb2
0e19c84
9344bb1
ae671c7
54f509a
135f369
5c7401a
8decd90
77e85c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,19 @@ 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"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding was that "-ObjC++" is needed when you are building with |
||
) |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* 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 <Foundation/Foundation.h> | ||
|
||
|
||
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 |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||
/* 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<ImageEmbedderCpp> 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<std::unique_ptr<ImageEmbedderCpp>> embedder_status = | ||||||||
ImageEmbedderCpp::CreateFromOptions(cc_options); | ||||||||
|
||||||||
if (embedder_status.ok()) { | ||||||||
cppImageEmbedder = std::move(embedder_status.value()); | ||||||||
} | ||||||||
else { | ||||||||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return nil; | ||||||||
} | ||||||||
} | ||||||||
return self; | ||||||||
} | ||||||||
|
||||||||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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", | ||
], | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the new iOS header files (e.g.,
TFLImageEmbedder.h
) are all using plain header filenames in their import statements. That is, it's likely that the processed header file will be the same as the original header file.strip_c_api_include_path_prefix
helper above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a separate method since objective c files are imported using
#import
as opposed to c files which are included using#include
.strip_c_api_include_path_prefix
and call itstrip_api_include_path_prefix
which will strip path prefixes irrespective of#import
or#include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. If it's needed, I'd recommend consolidating these two functions into a single one as mentioned before.