From 365468d98c7af3788847731b8f3c9ba9ccb17824 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 17 May 2019 11:20:15 -0700 Subject: [PATCH] Adds the TFLite version string to the Swift library. PiperOrigin-RevId: 248755089 --- .../lite/experimental/swift/BUILD.apple | 65 ++++++++----------- tensorflow/lite/experimental/swift/README.md | 4 +- .../swift/Sources/TensorFlowLite.swift | 22 +++++++ .../Configs/TensorFlowLite.tulsigen | 8 +-- .../TensorFlowLiteApp => TestApp}/Podfile | 2 +- .../TestApp.xcodeproj}/project.pbxproj | 42 ++++++------ .../TestApp}/AppDelegate.swift | 0 .../TestApp}/Array+TensorFlowLite.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../TestApp}/Assets.xcassets/Contents.json | 0 .../Base.lproj/LaunchScreen.storyboard | 11 ++-- .../TestApp}/Base.lproj/Main.storyboard | 2 +- .../TestApp}/Data+TensorFlowLite.swift | 0 .../TestApp}/Info.plist | 0 .../TestApp}/ViewController.swift | 11 +++- .../swift/Tests/TensorFlowLiteTests.swift | 28 ++++++++ 16 files changed, 120 insertions(+), 75 deletions(-) create mode 100644 tensorflow/lite/experimental/swift/Sources/TensorFlowLite.swift rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp => TestApp}/Podfile (70%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp.xcodeproj => TestApp/TestApp.xcodeproj}/project.pbxproj (91%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/AppDelegate.swift (100%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Array+TensorFlowLite.swift (100%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Assets.xcassets/Contents.json (100%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Base.lproj/LaunchScreen.storyboard (77%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Base.lproj/Main.storyboard (98%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Data+TensorFlowLite.swift (100%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/Info.plist (100%) rename tensorflow/lite/experimental/swift/{TestApps/TensorFlowLiteApp/TensorFlowLiteApp => TestApp/TestApp}/ViewController.swift (95%) create mode 100644 tensorflow/lite/experimental/swift/Tests/TensorFlowLiteTests.swift diff --git a/tensorflow/lite/experimental/swift/BUILD.apple b/tensorflow/lite/experimental/swift/BUILD.apple index a5a0c94e5b4..f57df7cc34e 100644 --- a/tensorflow/lite/experimental/swift/BUILD.apple +++ b/tensorflow/lite/experimental/swift/BUILD.apple @@ -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", - ], -) diff --git a/tensorflow/lite/experimental/swift/README.md b/tensorflow/lite/experimental/swift/README.md index 3e5badf448a..786efbcf366 100644 --- a/tensorflow/lite/experimental/swift/README.md +++ b/tensorflow/lite/experimental/swift/README.md @@ -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`). diff --git a/tensorflow/lite/experimental/swift/Sources/TensorFlowLite.swift b/tensorflow/lite/experimental/swift/Sources/TensorFlowLite.swift new file mode 100644 index 00000000000..edc30cfca9c --- /dev/null +++ b/tensorflow/lite/experimental/swift/Sources/TensorFlowLite.swift @@ -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) } ?? "" } +} diff --git a/tensorflow/lite/experimental/swift/TensorFlowLite.tulsiproj/Configs/TensorFlowLite.tulsigen b/tensorflow/lite/experimental/swift/TensorFlowLite.tulsiproj/Configs/TensorFlowLite.tulsigen index 16bc6cbfe8f..7ad7e33cf09 100644 --- a/tensorflow/lite/experimental/swift/TensorFlowLite.tulsiproj/Configs/TensorFlowLite.tulsigen +++ b/tensorflow/lite/experimental/swift/TensorFlowLite.tulsiproj/Configs/TensorFlowLite.tulsigen @@ -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" : { diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/Podfile b/tensorflow/lite/experimental/swift/TestApp/Podfile similarity index 70% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/Podfile rename to tensorflow/lite/experimental/swift/TestApp/Podfile index 9c9fe28ab08..2cd46d56689 100644 --- a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/Podfile +++ b/tensorflow/lite/experimental/swift/TestApp/Podfile @@ -1,6 +1,6 @@ platform :ios, '9.0' -target 'TensorFlowLiteApp' do +target 'TestApp' do use_frameworks! pod 'TensorFlowLiteSwift' end diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp.xcodeproj/project.pbxproj b/tensorflow/lite/experimental/swift/TestApp/TestApp.xcodeproj/project.pbxproj similarity index 91% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp.xcodeproj/project.pbxproj rename to tensorflow/lite/experimental/swift/TestApp/TestApp.xcodeproj/project.pbxproj index eb5d65a1f87..e6723e5a9a2 100644 --- a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp.xcodeproj/project.pbxproj +++ b/tensorflow/lite/experimental/swift/TestApp/TestApp.xcodeproj/project.pbxproj @@ -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 = ""; }; - 4A1E2B9E227C8B52006C23E2 /* add_quantized.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add_quantized.bin; path = ../../../../../testdata/add_quantized.bin; sourceTree = ""; }; - 4A1E2B9F227C8B52006C23E2 /* add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add.bin; path = ../../../../../testdata/add.bin; sourceTree = ""; }; + 4A1E2B9D227C8B51006C23E2 /* multi_add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = multi_add.bin; path = ../../../../testdata/multi_add.bin; sourceTree = ""; }; + 4A1E2B9E227C8B52006C23E2 /* add_quantized.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add_quantized.bin; path = ../../../../testdata/add_quantized.bin; sourceTree = ""; }; + 4A1E2B9F227C8B52006C23E2 /* add.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = add.bin; path = ../../../../testdata/add.bin; sourceTree = ""; }; 4A7304B321500B8300C90B21 /* Data+TensorFlowLite.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+TensorFlowLite.swift"; sourceTree = ""; }; - 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 = ""; }; 4AA72B742146ED64006C3AEF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 4AA72B772146ED64006C3AEF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -48,7 +48,7 @@ 4AA72B662146ED64006C3AEF = { isa = PBXGroup; children = ( - 4AA72B712146ED64006C3AEF /* TensorFlowLiteApp */, + 4AA72B712146ED64006C3AEF /* TestApp */, 4AA72B702146ED64006C3AEF /* Products */, ); sourceTree = ""; @@ -56,12 +56,12 @@ 4AA72B702146ED64006C3AEF /* Products */ = { isa = PBXGroup; children = ( - 4AA72B6F2146ED64006C3AEF /* TensorFlowLiteApp.app */, + 4AA72B6F2146ED64006C3AEF /* TestApp.app */, ); name = Products; sourceTree = ""; }; - 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 = ""; }; /* 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 */, diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/AppDelegate.swift b/tensorflow/lite/experimental/swift/TestApp/TestApp/AppDelegate.swift similarity index 100% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/AppDelegate.swift rename to tensorflow/lite/experimental/swift/TestApp/TestApp/AppDelegate.swift diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Array+TensorFlowLite.swift b/tensorflow/lite/experimental/swift/TestApp/TestApp/Array+TensorFlowLite.swift similarity index 100% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Array+TensorFlowLite.swift rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Array+TensorFlowLite.swift diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/tensorflow/lite/experimental/swift/TestApp/TestApp/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Assets.xcassets/AppIcon.appiconset/Contents.json rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Assets.xcassets/Contents.json b/tensorflow/lite/experimental/swift/TestApp/TestApp/Assets.xcassets/Contents.json similarity index 100% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Assets.xcassets/Contents.json rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Assets.xcassets/Contents.json diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/LaunchScreen.storyboard b/tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj/LaunchScreen.storyboard similarity index 77% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/LaunchScreen.storyboard rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj/LaunchScreen.storyboard index a07a1321be2..83d172a2309 100644 --- a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/LaunchScreen.storyboard +++ b/tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj/LaunchScreen.storyboard @@ -1,11 +1,10 @@ - + - - + @@ -21,10 +20,10 @@ - diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/Main.storyboard b/tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj/Main.storyboard similarity index 98% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/Main.storyboard rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj/Main.storyboard index 5eab6d71a0b..a93a4f0272e 100644 --- a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Base.lproj/Main.storyboard +++ b/tensorflow/lite/experimental/swift/TestApp/TestApp/Base.lproj/Main.storyboard @@ -12,7 +12,7 @@ - + diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Data+TensorFlowLite.swift b/tensorflow/lite/experimental/swift/TestApp/TestApp/Data+TensorFlowLite.swift similarity index 100% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Data+TensorFlowLite.swift rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Data+TensorFlowLite.swift diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Info.plist b/tensorflow/lite/experimental/swift/TestApp/TestApp/Info.plist similarity index 100% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/Info.plist rename to tensorflow/lite/experimental/swift/TestApp/TestApp/Info.plist diff --git a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/ViewController.swift b/tensorflow/lite/experimental/swift/TestApp/TestApp/ViewController.swift similarity index 95% rename from tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/ViewController.swift rename to tensorflow/lite/experimental/swift/TestApp/TestApp/ViewController.swift index b7641744a31..33a53ca3a08 100644 --- a/tensorflow/lite/experimental/swift/TestApps/TensorFlowLiteApp/TensorFlowLiteApp/ViewController.swift +++ b/tensorflow/lite/experimental/swift/TestApp/TestApp/ViewController.swift @@ -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)" diff --git a/tensorflow/lite/experimental/swift/Tests/TensorFlowLiteTests.swift b/tensorflow/lite/experimental/swift/Tests/TensorFlowLiteTests.swift new file mode 100644 index 00000000000..191f802dcc4 --- /dev/null +++ b/tensorflow/lite/experimental/swift/Tests/TensorFlowLiteTests.swift @@ -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)) + } +}