title: How to make a prediction with model that returns MultiArray(Double) in Swift
body: <p>I trained a model with Keras and converted it to CoreML using CoreMLTools. You can see details about the model here:</p>
  
  <p><a href="https://i.stack.imgur.com/Mgksm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mgksm.png" alt="enter image description here"></a></p>
  
  <p>How can I make predictions with this model? When i try I get this error:</p>
  
  <pre><code>2019-12-30 13:07:01.564792-0800 agricultural-helper[16042:6014777] [espresso] [Espresso::handle_ex_plan] exception=Espresso exception: "Invalid argument": generic_reshape_kernel: Invalid bottom shape (512 28 -3 1 1) for reshape to (512 -1 1 1 1) status=-6
  2019-12-30 13:07:01.565447-0800 agricultural-helper[16042:6014777] [coreml] Error computing NN outputs -6
  Error Domain=com.apple.CoreML Code=0 "Error computing NN outputs." UserInfo={NSLocalizedDescription=Error computing NN outputs.}
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>override init() {
      super.init()
      let options = MLPredictionOptions()
      options.usesCPUOnly = true
      let model = CropDisease()
      let uiImage = UIImage(named: "test.png")!
      let pixelBuffer = buffer(from: uiImage)!
      let modelInput = CropDiseaseInput(conv2d_input: pixelBuffer)
  
      do {
          let output = try model.prediction(input: modelInput, options: options)
          print(output)
      } catch {
          print(error)
      }
  }
  
  func buffer(from image: UIImage) -&gt; CVPixelBuffer? {
    let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
    var pixelBuffer : CVPixelBuffer?
    let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(image.size.width), Int(image.size.height), kCVPixelFormatType_32ARGB, attrs, &amp;pixelBuffer)
    guard (status == kCVReturnSuccess) else {
      return nil
    }
  
    CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
    let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!)
  
    let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
    let context = CGContext(data: pixelData, width: Int(image.size.width), height: Int(image.size.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue)
  
    context?.translateBy(x: 0, y: image.size.height)
    context?.scaleBy(x: 1.0, y: -1.0)
  
    UIGraphicsPushContext(context!)
    image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
    UIGraphicsPopContext()
    CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
  
    return pixelBuffer
  }
  </code></pre>
  
  <p>Anything helps. Thank you!</p>