Removes the isErrorLoggingEnabled property from the InterpreterOptions struct. Error logging is enabled by default to match ObjC behavior.

PiperOrigin-RevId: 248392591
This commit is contained in:
A. Unique TensorFlower 2019-05-15 13:23:05 -07:00 committed by TensorFlower Gardener
parent 45d1a97841
commit 18ff53fed4
5 changed files with 19 additions and 37 deletions

View File

@ -39,7 +39,7 @@ public final class Interpreter {
/// - Parameters:
/// - modelPath: Local file path to a TensorFlow Lite model.
/// - options: Custom configurations for the interpreter. The default is `nil` indicating that
/// interpreter will determine the configuration options.
/// the interpreter will determine the configuration options.
/// - Throws: An error if the model could not be loaded or the interpreter could not be created.
public init(modelPath: String, options: InterpreterOptions? = nil) throws {
guard let model = Model(filePath: modelPath) else { throw InterpreterError.failedToLoadModel }
@ -51,7 +51,6 @@ public final class Interpreter {
if let threadCount = options.threadCount, threadCount > 0 {
TFL_InterpreterOptionsSetNumThreads(cOptions, Int32(threadCount))
}
if options.isErrorLoggingEnabled {
TFL_InterpreterOptionsSetErrorReporter(
cOptions,
{ (_, format, args) -> Void in
@ -67,7 +66,6 @@ public final class Interpreter {
},
nil
)
}
return cOptions
}
defer { TFL_DeleteInterpreterOptions(cInterpreterOptions) }

View File

@ -40,7 +40,7 @@ extension InterpreterError: LocalizedError {
case .invalidTensorDataCount(let providedCount, let requiredCount):
return "Provided data count \(providedCount) must match the required count \(requiredCount)."
case .invalidTensorDataType:
return "Tensor data type is unsupported or could not be determined because of a model error."
return "Tensor data type is unsupported or could not be determined due to a model error."
case .failedToLoadModel:
return "Failed to load the given model."
case .failedToCreateInterpreter:

View File

@ -12,16 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
/// Custom configuration options for a TensorFlow Lite interpreter.
/// Custom configuration options for a TensorFlow Lite `Interpreter`.
public struct InterpreterOptions: Equatable {
/// Maximum number of CPU threads that the interpreter should run on. Default is `nil` which
/// indicates that the `Interpreter` will decide the number of threads to use.
public var threadCount: Int? = nil
/// Whether error logging to the console is enabled. The default is `false`.
public var isErrorLoggingEnabled = false
/// Creates a new instance of interpreter options.
public init() {}
}

View File

@ -103,9 +103,7 @@ class ViewController: UIViewController {
private func setUpInterpreter(withModelPath modelPath: String) {
interpreterQueue.async {
do {
var options = InterpreterOptions()
options.isErrorLoggingEnabled = true
self.interpreter = try Interpreter(modelPath: modelPath, options: options)
self.interpreter = try Interpreter(modelPath: modelPath)
} catch let error {
self.updateResultsText(
"Failed to create the interpreter with error: \(error.localizedDescription)"

View File

@ -20,15 +20,12 @@ class InterpreterOptionsTests: XCTestCase {
func testInterpreterOptions_InitWithDefaultValues() {
let options = InterpreterOptions()
XCTAssertNil(options.threadCount)
XCTAssertFalse(options.isErrorLoggingEnabled)
}
func testInterpreterOptions_InitWithCustomValues() {
var options = InterpreterOptions()
options.threadCount = 2
XCTAssertEqual(options.threadCount, 2)
options.isErrorLoggingEnabled = true
XCTAssertTrue(options.isErrorLoggingEnabled)
}
func testInterpreterOptions_Equatable() {
@ -42,13 +39,5 @@ class InterpreterOptionsTests: XCTestCase {
options2.threadCount = 3
XCTAssertNotEqual(options1, options2)
options2.threadCount = 2
options1.isErrorLoggingEnabled = true
options2.isErrorLoggingEnabled = true
XCTAssertEqual(options1, options2)
options2.isErrorLoggingEnabled = false
XCTAssertNotEqual(options1, options2)
}
}