【问题标题】:Swift TensorFlowLite Interpreter Error : Type 'Interpreter' has no member 'Options'Swift TensorFlowLite 解释器错误:类型“解释器”没有成员“选项”
【发布时间】:2019-08-26 07:16:55
【问题描述】:

我从以下存储库克隆了适用于 iOS 的 TensorFlowLite 示例应用 https://github.com/tensorflow/examples/tree/master/lite/examples/image_classification/ios

安装的 pod 文件包含 pod 'TensorFlowLiteSwift'

当我打开ImageClassification.xcworkspace 时,Xcode 直接显示以下错误。

类型“解释器”没有成员“选项”

我没有更改示例应用程序中的任何代码。

调用解释器的Options()时出现此错误

var options = Interpreter.Options()

我尝试使用 Interpreter 的其他方法获取 Option 属性,但无法获取。

init?(modelFileInfo: FileInfo, labelsFileInfo: FileInfo, threadCount: Int = 1) {
    let modelFilename = modelFileInfo.name

    // Construct the path to the model file.
    guard let modelPath = Bundle.main.path(
      forResource: modelFilename,
      ofType: modelFileInfo.extension
    ) else {
      print("Failed to load the model file with name: \(modelFilename).")
      return nil
    }

    // Specify the options for the `Interpreter`.
    self.threadCount = threadCount
    var options = Interpreter.Options() // Here the issue is *Type 'Interpreter' has no member 'Options*
    options.threadCount = threadCount
    do {
      // Create the `Interpreter`.
      interpreter = try Interpreter(modelPath: modelPath, options: options)
      // Allocate memory for the model's input `Tensor`s.
      try interpreter.allocateTensors()
    } catch let error {
      print("Failed to create the interpreter with error: \(error.localizedDescription)")
      return nil
    }
    // Load the classes listed in the labels file.
    loadLabels(fileInfo: labelsFileInfo)
  }

这个init() 预计会初始化并提供 ModelDataHandler 对象。

【问题讨论】:

    标签: swift deep-learning tensorflow-lite


    【解决方案1】:

    Interpreter.Options() 应改回 InterpreterOptions() 在所有 TensorFlow Lite 示例中的原始状态。

    最近的一个提交破坏了构建: https://github.com/tensorflow/examples/commit/751f4648e3917178b0e67454422477fe5d81d611

    【讨论】:

      【解决方案2】:

      我将本地代码更改为使用 InterpreterOptions 类。

          // Specify the options for the `Interpreter`.
          self.threadCount = threadCount
          var options = InterpreterOptions()
          options.threadCount = threadCount
          do {
            // Create the `Interpreter`.
            interpreter = try Interpreter(modelPath: modelPath, options: options)
            // Allocate memory for the model's input `Tensor`s.
            try interpreter.allocateTensors()
          } catch let error {
            print("Failed to create the interpreter with error: \(error.localizedDescription)")
            return nil
          }
          // Load the classes listed in the labels file.
          loadLabels(fileInfo: labelsFileInfo)
        }
      

      【讨论】:

      • 嗨 Rick,你能不能给模型提供输入并得到输出?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2021-12-12
      • 2016-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多