SHARE
TWEET

Untitled

a guest Jun 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. do{
  2.     var options = InterpreterOptions()
  3.     options.isErrorLoggingEnabled = true
  4.     try self.interpreter = Interpreter(modelPath: Bundle.main.path(forResource: modelFileName, ofType: "tflite")!, options: options)
  5.     // allocate input tensors at the given shapes
  6.     try self.interpreter.allocateTensors()
  7. }catch {
  8.     print("initialize TF interpreter failed: (error)")
  9.     return nil
  10. }
  11.  
  12. let data = Data(copyingBufferOf: Array<Float>(repeating: 1, count: 128*10))
  13. try interpreter.copy(data, toInputAt: 0)
  14. try interpreter.invoke()
  15. let outputTensor = try interpreter.output(at: 0)
  16. let outputResult = [Float](unsafeData: outputTensor.data)!
  17. print("interpreter result on test data", outputResult)
  18. precondition(outputResult == [0.2032134])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top