Adds the TFLite version string to the Swift library.
PiperOrigin-RevId: 248755089
This commit is contained in:
parent
1d0dea1376
commit
365468d98c
@ -19,37 +19,17 @@ swift_library(
|
||||
)
|
||||
|
||||
ios_unit_test(
|
||||
name = "TensorFlowLiteTests",
|
||||
name = "Tests",
|
||||
size = "small",
|
||||
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
||||
tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS,
|
||||
deps = [
|
||||
":TestsLib",
|
||||
],
|
||||
)
|
||||
|
||||
ios_application(
|
||||
name = "TensorFlowLiteApp",
|
||||
app_icons = glob(["TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Assets.xcassets/AppIcon.appiconset/**"]),
|
||||
bundle_id = "com.tensorflow.lite.swift.TensorFlowLite",
|
||||
families = [
|
||||
"ipad",
|
||||
"iphone",
|
||||
],
|
||||
infoplists = ["TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Info.plist"],
|
||||
launch_storyboard = "TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/LaunchScreen.storyboard",
|
||||
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
||||
sdk_frameworks = [
|
||||
"CoreGraphics",
|
||||
],
|
||||
tags = TFL_DEFAULT_TAGS,
|
||||
deps = [
|
||||
":AppLib",
|
||||
":TestsLibrary",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "TestsLib",
|
||||
name = "TestsLibrary",
|
||||
testonly = 1,
|
||||
srcs = glob(["Tests/*.swift"]),
|
||||
tags = TFL_DEFAULT_TAGS,
|
||||
@ -59,13 +39,33 @@ swift_library(
|
||||
],
|
||||
)
|
||||
|
||||
ios_application(
|
||||
name = "TestApp",
|
||||
app_icons = glob(["TestApp/TestApp/Assets.xcassets/AppIcon.appiconset/**"]),
|
||||
bundle_id = "com.tensorflow.lite.swift.TestApp",
|
||||
families = [
|
||||
"ipad",
|
||||
"iphone",
|
||||
],
|
||||
infoplists = ["TestApp/TestApp/Info.plist"],
|
||||
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
||||
sdk_frameworks = [
|
||||
"CoreGraphics",
|
||||
],
|
||||
tags = TFL_DEFAULT_TAGS,
|
||||
deps = [
|
||||
":TestAppLibrary",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "AppLib",
|
||||
srcs = glob(["TestApps/TensorFlowLiteApp/TensorFlowLiteApp/*.swift"]),
|
||||
module_name = "AppLib",
|
||||
name = "TestAppLibrary",
|
||||
srcs = glob(["TestApp/TestApp/*.swift"]),
|
||||
data = glob(["TestApp/TestApp/Base.lproj/*.storyboard"]),
|
||||
module_name = "TestApp",
|
||||
tags = TFL_DEFAULT_TAGS + ["manual"],
|
||||
deps = [
|
||||
":AppResources",
|
||||
":Resources",
|
||||
":TensorFlowLite",
|
||||
],
|
||||
)
|
||||
@ -79,14 +79,3 @@ objc_library(
|
||||
],
|
||||
tags = TFL_DEFAULT_TAGS,
|
||||
)
|
||||
|
||||
objc_library(
|
||||
name = "AppResources",
|
||||
data = glob([
|
||||
"TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/*.storyboard",
|
||||
]),
|
||||
tags = TFL_DEFAULT_TAGS + ["manual"],
|
||||
deps = [
|
||||
":Resources",
|
||||
],
|
||||
)
|
||||
|
@ -59,10 +59,10 @@ Build the `TensorFlowLite` Swift library target:
|
||||
bazel build tensorflow/lite/experimental/swift:TensorFlowLite
|
||||
```
|
||||
|
||||
Build the `TensorFlowLiteTests` target:
|
||||
Build the `Tests` target:
|
||||
|
||||
```shell
|
||||
bazel test tensorflow/lite/experimental/swift:TensorFlowLiteTests --swiftcopt=-enable-testing
|
||||
bazel test tensorflow/lite/experimental/swift:Tests --swiftcopt=-enable-testing
|
||||
```
|
||||
|
||||
Note: `--swiftcopt=-enable-testing` is required for optimized builds (`-c opt`).
|
||||
|
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 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 TensorFlowLiteC
|
||||
|
||||
/// TensorFlow Lite runtime values.
|
||||
public enum Runtime {
|
||||
/// A string describing the semantic versioning information for the runtime. Is an empty string if
|
||||
/// the version could not be determined.
|
||||
public static var version: String { return TFL_Version().map { String(cString: $0) } ?? "" }
|
||||
}
|
@ -3,14 +3,14 @@
|
||||
"tensorflow/lite/experimental/c",
|
||||
"tensorflow/lite/experimental/swift",
|
||||
"tensorflow/lite/experimental/swift/Sources",
|
||||
"tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp",
|
||||
"tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj",
|
||||
"tensorflow/lite/experimental/swift/TestApp/TestApp",
|
||||
"tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj",
|
||||
"tensorflow/lite/experimental/swift/Tests",
|
||||
],
|
||||
"buildTargets" : [
|
||||
"//tensorflow/lite/experimental/swift:TensorFlowLite",
|
||||
"//tensorflow/lite/experimental/swift:TensorFlowLiteApp",
|
||||
"//tensorflow/lite/experimental/swift:TensorFlowLiteTests",
|
||||
"//tensorflow/lite/experimental/swift:TestApp",
|
||||
"//tensorflow/lite/experimental/swift:Tests",
|
||||
],
|
||||
"projectName" : "TensorFlowLite",
|
||||
"optionSet" : {
|
||||
|
@ -1,6 +1,6 @@
|
||||
platform :ios, '9.0'
|
||||
|
||||
target 'TensorFlowLiteApp' do
|
||||
target 'TestApp' do
|
||||
use_frameworks!
|
||||
pod 'TensorFlowLiteSwift'
|
||||
end
|
@ -20,11 +20,11 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
4A1E2B9D227C8B51006C23E2 /* multi_add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = multi_add.bin; path = ../../../../../testdata/multi_add.bin; sourceTree = "<group>"; };
|
||||
4A1E2B9E227C8B52006C23E2 /* add_quantized.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add_quantized.bin; path = ../../../../../testdata/add_quantized.bin; sourceTree = "<group>"; };
|
||||
4A1E2B9F227C8B52006C23E2 /* add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add.bin; path = ../../../../../testdata/add.bin; sourceTree = "<group>"; };
|
||||
4A1E2B9D227C8B51006C23E2 /* multi_add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = multi_add.bin; path = ../../../../testdata/multi_add.bin; sourceTree = "<group>"; };
|
||||
4A1E2B9E227C8B52006C23E2 /* add_quantized.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add_quantized.bin; path = ../../../../testdata/add_quantized.bin; sourceTree = "<group>"; };
|
||||
4A1E2B9F227C8B52006C23E2 /* add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add.bin; path = ../../../../testdata/add.bin; sourceTree = "<group>"; };
|
||||
4A7304B321500B8300C90B21 /* Data+TensorFlowLite.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+TensorFlowLite.swift"; sourceTree = "<group>"; };
|
||||
4AA72B6F2146ED64006C3AEF /* TensorFlowLiteApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TensorFlowLiteApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4AA72B6F2146ED64006C3AEF /* TestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4AA72B722146ED64006C3AEF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
4AA72B742146ED64006C3AEF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
4AA72B772146ED64006C3AEF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
@ -48,7 +48,7 @@
|
||||
4AA72B662146ED64006C3AEF = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AA72B712146ED64006C3AEF /* TensorFlowLiteApp */,
|
||||
4AA72B712146ED64006C3AEF /* TestApp */,
|
||||
4AA72B702146ED64006C3AEF /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
@ -56,12 +56,12 @@
|
||||
4AA72B702146ED64006C3AEF /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AA72B6F2146ED64006C3AEF /* TensorFlowLiteApp.app */,
|
||||
4AA72B6F2146ED64006C3AEF /* TestApp.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4AA72B712146ED64006C3AEF /* TensorFlowLiteApp */ = {
|
||||
4AA72B712146ED64006C3AEF /* TestApp */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AA72B722146ED64006C3AEF /* AppDelegate.swift */,
|
||||
@ -76,15 +76,15 @@
|
||||
4A1E2B9F227C8B52006C23E2 /* add.bin */,
|
||||
4A1E2B9D227C8B51006C23E2 /* multi_add.bin */,
|
||||
);
|
||||
path = TensorFlowLiteApp;
|
||||
path = TestApp;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
4AA72B6E2146ED64006C3AEF /* TensorFlowLiteApp */ = {
|
||||
4AA72B6E2146ED64006C3AEF /* TestApp */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 4AA72B812146ED66006C3AEF /* Build configuration list for PBXNativeTarget "TensorFlowLiteApp" */;
|
||||
buildConfigurationList = 4AA72B812146ED66006C3AEF /* Build configuration list for PBXNativeTarget "TestApp" */;
|
||||
buildPhases = (
|
||||
4AA72B6B2146ED64006C3AEF /* Sources */,
|
||||
4AA72B6C2146ED64006C3AEF /* Frameworks */,
|
||||
@ -94,9 +94,9 @@
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = TensorFlowLiteApp;
|
||||
productName = TensorFlowLiteApp;
|
||||
productReference = 4AA72B6F2146ED64006C3AEF /* TensorFlowLiteApp.app */;
|
||||
name = TestApp;
|
||||
productName = TestApp;
|
||||
productReference = 4AA72B6F2146ED64006C3AEF /* TestApp.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
@ -115,7 +115,7 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 4AA72B6A2146ED64006C3AEF /* Build configuration list for PBXProject "TensorFlowLiteApp" */;
|
||||
buildConfigurationList = 4AA72B6A2146ED64006C3AEF /* Build configuration list for PBXProject "TestApp" */;
|
||||
compatibilityVersion = "Xcode 9.3";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
@ -128,7 +128,7 @@
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
4AA72B6E2146ED64006C3AEF /* TensorFlowLiteApp */,
|
||||
4AA72B6E2146ED64006C3AEF /* TestApp */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
@ -302,12 +302,12 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
INFOPLIST_FILE = TensorFlowLiteApp/Info.plist;
|
||||
INFOPLIST_FILE = TestApp/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.tensorflow.lite.swift.TensorFlowLite;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.tensorflow.lite.swift.TestApp;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
@ -319,12 +319,12 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
INFOPLIST_FILE = TensorFlowLiteApp/Info.plist;
|
||||
INFOPLIST_FILE = TestApp/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.tensorflow.lite.swift.TensorFlowLite;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.tensorflow.lite.swift.TestApp;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
@ -334,7 +334,7 @@
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
4AA72B6A2146ED64006C3AEF /* Build configuration list for PBXProject "TensorFlowLiteApp" */ = {
|
||||
4AA72B6A2146ED64006C3AEF /* Build configuration list for PBXProject "TestApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
4AA72B7F2146ED66006C3AEF /* Debug */,
|
||||
@ -343,7 +343,7 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
4AA72B812146ED66006C3AEF /* Build configuration list for PBXNativeTarget "TensorFlowLiteApp" */ = {
|
||||
4AA72B812146ED66006C3AEF /* Build configuration list for PBXNativeTarget "TestApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
4AA72B822146ED66006C3AEF /* Debug */,
|
@ -1,11 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
@ -21,10 +20,10 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TensorFlowLite" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Gq-PV-hia">
|
||||
<rect key="frame" x="16" y="315" width="343" height="38.5"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TensorFlow Lite" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Gq-PV-hia">
|
||||
<rect key="frame" x="16" y="314" width="343" height="39"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="32"/>
|
||||
<nil key="textColor"/>
|
||||
<color key="textColor" red="1" green="0.43529411764705883" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
@ -12,7 +12,7 @@
|
||||
<!--View Controller-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController storyboardIdentifier="viewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BYZ-38-t0r" customClass="ViewController" customModule="TensorFlowLiteApp" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController storyboardIdentifier="viewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BYZ-38-t0r" customClass="ViewController" customModule="TestApp" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
@ -1,4 +1,8 @@
|
||||
import TensorFlowLite
|
||||
import class TensorFlowLite.Interpreter
|
||||
import struct TensorFlowLite.InterpreterOptions
|
||||
import struct TensorFlowLite.Tensor
|
||||
import struct TensorFlowLite.TensorShape
|
||||
import enum TensorFlowLite.Runtime
|
||||
import UIKit
|
||||
|
||||
class ViewController: UIViewController {
|
||||
@ -66,6 +70,7 @@ class ViewController: UIViewController {
|
||||
super.viewDidLoad()
|
||||
|
||||
invokeButton.isEnabled = false
|
||||
updateResultsText("Using TensorFlow Lite runtime version \(TensorFlowLite.Runtime.version).")
|
||||
loadModel()
|
||||
}
|
||||
|
||||
@ -103,7 +108,9 @@ class ViewController: UIViewController {
|
||||
private func setUpInterpreter(withModelPath modelPath: String) {
|
||||
interpreterQueue.async {
|
||||
do {
|
||||
self.interpreter = try Interpreter(modelPath: modelPath)
|
||||
var options = InterpreterOptions()
|
||||
options.threadCount = 2
|
||||
self.interpreter = try Interpreter(modelPath: modelPath, options: options)
|
||||
} catch let error {
|
||||
self.updateResultsText(
|
||||
"Failed to create the interpreter with error: \(error.localizedDescription)"
|
@ -0,0 +1,28 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
@testable import TensorFlowLite
|
||||
import XCTest
|
||||
|
||||
class TensorFlowLiteTests: XCTestCase {
|
||||
|
||||
func testTensorFlowLite_Runtime_version() {
|
||||
#if swift(>=5.0)
|
||||
let pattern = #"^(\d+)\.(\d+)\.(\d+)([+-][-.0-9A-Za-z]+)?$"#
|
||||
#else
|
||||
let pattern = "^(\\d+)\\.(\\d+)\\.(\\d+)([+-][-.0-9A-Za-z]+)?$"
|
||||
#endif // swift(>=5.0)
|
||||
XCTAssertNotNil(TensorFlowLite.Runtime.version.range(of: pattern, options: .regularExpression))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user