Created
November 8, 2017 11:37
-
-
Save akirasosa/0fe78b4c173aeb49d96076db20aa9dd2 to your computer and use it in GitHub Desktop.
Benchmark Core ML model in iOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreML | |
import XCTest | |
@testable import mlsample | |
class mlsampleTests: XCTestCase { | |
override func setUp() { | |
super.setUp() | |
} | |
override func tearDown() { | |
super.tearDown() | |
} | |
func testSpeed() { | |
guard let input_data = try? MLMultiArray(shape:[3, 160, 160], dataType:MLMultiArrayDataType.double) else { | |
fatalError("Unexpected runtime error. MLMultiArray") | |
} | |
let model = mobile_unet_160_100_100() | |
// It's for excluding 1st measurement. | |
do { | |
try model.prediction(data: input_data) | |
print("predicted------------") | |
} catch { | |
print("error------------") | |
} | |
print("--------started------------") | |
self.measure() { | |
try! model.prediction(data: input_data) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment