Skip to content

Commit 9935172

Browse files
author
Daniel Llewellyn
committed
Add experimental CoreML delegate
* Update TensorFlowLiteC to TensorFlowLiteC/Core (version 2.4.0) * Add TensorFlowLiteC/Metal to restore Metal delegate after v2.4.0 moved it to a separate pod. * Add TensorflowLiteC/CoreML to add experimental CoreML delegate. Signed-off-by: Daniel Llewellyn <[email protected]>
1 parent 1ba5faf commit 9935172

File tree

9 files changed

+47
-106
lines changed

9 files changed

+47
-106
lines changed

example/ios/Flutter/Debug.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
23
#include "Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
23
#include "Generated.xcconfig"

example/ios/Podfile

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,29 @@ project 'Runner', {
1010
'Release' => :release,
1111
}
1212

13-
def parse_KV_file(file, separator='=')
14-
file_abs_path = File.expand_path(file)
15-
if !File.exists? file_abs_path
16-
return [];
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
1717
end
18-
generated_key_values = {}
19-
skip_line_start_symbols = ["#", "/"]
20-
File.foreach(file_abs_path) do |line|
21-
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
22-
plugin = line.split(pattern=separator)
23-
if plugin.length == 2
24-
podname = plugin[0].strip()
25-
path = plugin[1].strip()
26-
podpath = File.expand_path("#{path}", file_abs_path)
27-
generated_key_values[podname] = podpath
28-
else
29-
puts "Invalid plugin specification: #{line}"
30-
end
31-
end
32-
generated_key_values
33-
end
34-
35-
target 'Runner' do
36-
# Flutter Pod
37-
38-
copied_flutter_dir = File.join(__dir__, 'Flutter')
39-
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
40-
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
41-
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
42-
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
43-
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
44-
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
4518

46-
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
47-
unless File.exist?(generated_xcode_build_settings_path)
48-
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
49-
end
50-
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
51-
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
52-
53-
unless File.exist?(copied_framework_path)
54-
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
55-
end
56-
unless File.exist?(copied_podspec_path)
57-
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
58-
end
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
5922
end
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24+
end
6025

61-
# Keep pod path relative so it can be checked into Podfile.lock.
62-
pod 'Flutter', :path => 'Flutter'
26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
6327

64-
# Plugin Pods
28+
flutter_ios_podfile_setup
6529

66-
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
67-
# referring to absolute paths on developers' machines.
68-
system('rm -rf .symlinks')
69-
system('mkdir -p .symlinks/plugins')
70-
plugin_pods = parse_KV_file('../.flutter-plugins')
71-
plugin_pods.each do |name, path|
72-
symlink = File.join('.symlinks', 'plugins', name)
73-
File.symlink(path, symlink)
74-
pod name, :path => File.join(symlink, 'ios')
75-
end
30+
target 'Runner' do
31+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
7632
end
7733

78-
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
79-
install! 'cocoapods', :disable_input_output_paths => true
80-
8134
post_install do |installer|
8235
installer.pods_project.targets.each do |target|
83-
target.build_configurations.each do |config|
84-
config.build_settings['ENABLE_BITCODE'] = 'NO'
85-
end
36+
flutter_additional_ios_build_settings(target)
8637
end
8738
end

example/ios/Podfile.lock

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ PODS:
22
- Flutter (1.0.0)
33
- image_picker (0.0.1):
44
- Flutter
5-
- TensorFlowLiteC (2.2.0)
5+
- TensorFlowLiteC/Core (2.4.0)
6+
- TensorFlowLiteC/CoreML (2.4.0):
7+
- TensorFlowLiteC/Core
8+
- TensorFlowLiteC/Metal (2.4.0):
9+
- TensorFlowLiteC/Core
610
- tflite (1.1.1):
711
- Flutter
8-
- TensorFlowLiteC
12+
- TensorFlowLiteC/Core
13+
- TensorFlowLiteC/CoreML
14+
- TensorFlowLiteC/Metal
915

1016
DEPENDENCIES:
1117
- Flutter (from `Flutter`)
@@ -25,11 +31,11 @@ EXTERNAL SOURCES:
2531
:path: ".symlinks/plugins/tflite/ios"
2632

2733
SPEC CHECKSUMS:
28-
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
34+
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
2935
image_picker: a211f28b95a560433c00f5cd3773f4710a20404d
30-
TensorFlowLiteC: b3ab9e867b0b71052ca102a32a786555b330b02e
31-
tflite: f0403a894740019d63ab5662253bba5b2dd37296
36+
TensorFlowLiteC: 09f8ac75a76caeadb19bcfa694e97454cc1ecf87
37+
tflite: d701e08676abd255d3340a79bb8cb4ba1594723c
3238

33-
PODFILE CHECKSUM: 3dbe063e9c90a5d7c9e4e76e70a821b9e2c1d271
39+
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
3440

35-
COCOAPODS: 1.9.0
41+
COCOAPODS: 1.10.1

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
13-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
14-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
15-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1612
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
1713
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
1814
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
@@ -29,8 +25,6 @@
2925
dstPath = "";
3026
dstSubfolderSpec = 10;
3127
files = (
32-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
33-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
3428
);
3529
name = "Embed Frameworks";
3630
runOnlyForDeploymentPostprocessing = 0;
@@ -41,14 +35,12 @@
4135
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4236
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4337
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
44-
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4538
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4639
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4740
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
4841
864E0E2308AE5F3A9409E901 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
4942
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
5043
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
51-
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
5244
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
5345
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
5446
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -64,8 +56,6 @@
6456
isa = PBXFrameworksBuildPhase;
6557
buildActionMask = 2147483647;
6658
files = (
67-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
68-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
6959
A8FCB07931B147D0C738D807 /* libPods-Runner.a in Frameworks */,
7060
);
7161
runOnlyForDeploymentPostprocessing = 0;
@@ -93,9 +83,7 @@
9383
9740EEB11CF90186004384FC /* Flutter */ = {
9484
isa = PBXGroup;
9585
children = (
96-
3B80C3931E831B6300D905FE /* App.framework */,
9786
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
98-
9740EEBA1CF902C7004384FC /* Flutter.framework */,
9987
9740EEB21CF90195004384FC /* Debug.xcconfig */,
10088
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
10189
9740EEB31CF90195004384FC /* Generated.xcconfig */,
@@ -160,7 +148,6 @@
160148
97C146EC1CF9000F007C117D /* Resources */,
161149
9705A1C41CF9048500538489 /* Embed Frameworks */,
162150
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
163-
739FAA0FA24243FB33B8F517 /* [CP] Embed Pods Frameworks */,
164151
);
165152
buildRules = (
166153
);
@@ -233,22 +220,7 @@
233220
);
234221
runOnlyForDeploymentPostprocessing = 0;
235222
shellPath = /bin/sh;
236-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
237-
};
238-
739FAA0FA24243FB33B8F517 /* [CP] Embed Pods Frameworks */ = {
239-
isa = PBXShellScriptBuildPhase;
240-
buildActionMask = 2147483647;
241-
files = (
242-
);
243-
inputPaths = (
244-
);
245-
name = "[CP] Embed Pods Frameworks";
246-
outputPaths = (
247-
);
248-
runOnlyForDeploymentPostprocessing = 0;
249-
shellPath = /bin/sh;
250-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
251-
showEnvVarsInLog = 0;
223+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
252224
};
253225
9740EEB61CF901F6004384FC /* Run Script */ = {
254226
isa = PBXShellScriptBuildPhase;
@@ -319,7 +291,6 @@
319291
/* Begin XCBuildConfiguration section */
320292
97C147031CF9000F007C117D /* Debug */ = {
321293
isa = XCBuildConfiguration;
322-
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
323294
buildSettings = {
324295
ALWAYS_SEARCH_USER_PATHS = NO;
325296
CLANG_ANALYZER_NONNULL = YES;
@@ -373,7 +344,6 @@
373344
};
374345
97C147041CF9000F007C117D /* Release */ = {
375346
isa = XCBuildConfiguration;
376-
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
377347
buildSettings = {
378348
ALWAYS_SEARCH_USER_PATHS = NO;
379349
CLANG_ANALYZER_NONNULL = YES;

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings renamed to example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>BuildSystemType</key>
6-
<string>Original</string>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
77
</dict>
88
</plist>

ios/Classes/TflitePlugin.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#elif defined TFLITE2
2020
#import "TensorFlowLiteC.h"
2121
#import "metal_delegate.h"
22+
#import "coreml_delegate.h"
2223
#else
2324
#include "tensorflow/lite/kernels/register.h"
2425
#include "tensorflow/lite/model.h"
@@ -162,7 +163,16 @@ static void LoadLabels(NSString* labels_path,
162163
TfLiteInterpreterOptionsSetNumThreads(options, num_threads);
163164

164165
bool useGpuDelegate = [args[@"useGpuDelegate"] boolValue];
166+
bool useCoreMLDelegate = [args[@"useCoreMLDelegate"] boolValue];
167+
if (useCoreMLDelegate) {
168+
TfLiteCoreMlDelegateOptions options = {};
169+
delegate = TfLiteCoreMlDelegateCreate(&options);
170+
if (delegate == NULL && useGpuDelegate) {
171+
goto GPUDELEGATE;
172+
}
173+
}
165174
if (useGpuDelegate) {
175+
GPUDELEGATE:
166176
delegate = TFLGpuDelegateCreate(nullptr);
167177
TfLiteInterpreterOptionsAddDelegate(options, delegate);
168178
}

ios/tflite.podspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ A Flutter plugin for accessing TensorFlow Lite. Supports both iOS and Android.
1515
s.source_files = 'Classes/**/*'
1616
s.public_header_files = 'Classes/**/*.h'
1717
s.dependency 'Flutter'
18-
s.dependency 'TensorFlowLiteC'
19-
s.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/tflite" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Flutter" "${PODS_ROOT}/Headers/Public/TensorFlowLite/tensorflow_lite" "${PODS_ROOT}/Headers/Public/tflite" "${PODS_ROOT}/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers" "${PODS_ROOT}/TensorFlowLiteC/Frameworks/TensorFlowLiteC.framework/Headers"' }
18+
s.dependency 'TensorFlowLiteC/Core'
19+
s.dependency 'TensorFlowLiteC/Metal'
20+
s.dependency 'TensorFlowLiteC/CoreML'
21+
s.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/tflite" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Flutter" "${PODS_ROOT}/Headers/Public/TensorFlowLite/tensorflow_lite" "${PODS_ROOT}/Headers/Public/tflite" "${PODS_ROOT}/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers" "${PODS_ROOT}/TensorFlowLiteC/Frameworks/TensorFlowLiteC.framework/Headers" "${PODS_ROOT}/TensorFlowLiteC/Frameworks/TensorFlowLiteCMetal.framework/Headers" "${PODS_ROOT}/TensorFlowLiteC/Frameworks/TensorFlowLiteCCoreML.framework/Headers"' }
2022

2123
s.ios.deployment_target = '9.0'
2224
s.static_framework = true

0 commit comments

Comments
 (0)