try self.interpreter!.invoke() App got crashed on this line 
            try self.interpreter!.copy(inputData, toInputAt: 0)
            try self.interpreter!.invoke() // App got crashed on this line without any log(Thread 1: EXC_BAD_ACCESS (code=1, address=0x32e110180))
 Even Tensor were allocated still getting crash. @ShiviAGL,
Could you please provide the complete standalone code & the tensorflow version you are using and helps us to analyse the issue in an effective way. Thank you! Hi TilakRayl 
Thanks for reply :
Version is not mention only used  pod 'TensorFlowLiteSwift'

    //TFLITE Model parameter example
    let batchSize = 1
    let inputChannels = 3
    let inputWidth = 640 
    let inputHeight = 640
    
    private var inputTensor: Tensor?
    private var outputTensor: Tensor?

    func checkTfliteImage (imageTocheck : UIImage) -> (Bool){
        
        let myimage: UIImage = imageTocheck.resized(to: CGSizeMake(CGFloat(inputWidth), CGFloat(inputHeight)))
        
        let image : CGImage = myimage.cgImage!

        guard let context = CGContext(
          data: nil,
          width: image.width, height: image.height,
          bitsPerComponent: 8, bytesPerRow: image.width * 4,
          space: CGColorSpaceCreateDeviceRGB(),
          bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue
        ) else {
          return false
        }

        context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
        guard let imageData = context.data else { return false }

        var inputData = Data()
        for row in 0 ..< inputWidth {    
          for col in 0 ..< inputHeight {
            let offset = 4 * (col * context.width + row)
            // (Ignore offset 0, the unused alpha channel)
            var red = imageData.load(fromByteOffset: offset+1, as: UInt8.self)
            var green = imageData.load(fromByteOffset: offset+2, as: UInt8.self)
            var blue = imageData.load(fromByteOffset: offset+3, as: UInt8.self)

            inputData.append(&red, count: 1)
            inputData.append(&green, count: 1)
            inputData.append(&blue, count: 1)
          }
        }
        do {
            try self.interpreter!.copy(inputData, toInputAt: 0)
            try self.interpreter!.invoke()
            var output = try interpreter!.output(at: 0)
            let boundingBoxes =
                UnsafeMutableBufferPointer<Float32>.allocate(capacity: 4 * 40)
            output.data.copyBytes(to: boundingBoxes)

            output = try interpreter!.output(at: 1)
            let labels =
                UnsafeMutableBufferPointer<Float32>.allocate(capacity: 40)
            output.data.copyBytes(to: labels)

            output = try interpreter!.output(at: 2)
            let probabilities =
                UnsafeMutableBufferPointer<Float32>.allocate(capacity: 40)
            output.data.copyBytes(to: probabilities)

            guard let labelPath = Bundle.main.path(
                forResource: "labels",
                ofType: "txt"
            ) else { return true }
            let fileContents = try? String(contentsOfFile: labelPath)
            guard let labelText = fileContents?.components(separatedBy: "\n") else { return true }

            for i in 0 ..< 40 {
                let top = boundingBoxes[0 * i]
                let left = boundingBoxes[1 * i]
                let bottom = boundingBoxes[2 * i]
                let right = boundingBoxes[3 * i]

                let labelIdx = Int(labels[i])
                let label = labelText[labelIdx]
                let confidence = probabilities[i]

                if confidence > 0.66 {
                    print("Object found: \(label) (confidence: \(confidence))")
                    print("  Top-left: (\(left),\(top))")
                    print("  Bottom-right: (\(right),\(bottom))")
                }
            }

            try self.interpreter!.allocateTensors()
        } catch {
            print("error in recognition \(error.localizedDescription)")
            //error in recognition Provided data count 150528 must match the required count 1228800.

        }
        return false
    }
 Hi @ShiviAGL 

Could you please share TFLite model if possible to analyse and better understand the issue? 

Thanks. hi pjpratik ,
can you plz chk .tflite file with attached url below :


please let us know how to preprocess the input image for this file as tensor input. and what will be the values of:

1. tflite_metadata.json
2. The model's input dimensions 
3. The model's maximum detections 
4. dict.txt or labels.txt file to get the name of detected object 
 Hi @ShiviAGL 

>tflite_metadata.json

We can use [MetaDatadisplayer](https://www.tensorflow.org/lite/api_docs/python/tflite_support/metadata/MetadataDisplayer) which is available through `tflite_support` library. 

`get_metadata_json()` can be used which converts the metadata into a json string.

>The model's input dimensions

I did observe that model's input dimensions are `[1,320,320,3]`.

>The model's maximum detections

And the model has maximum detections of 10.

>dict.txt or labels.txt file to get the name of detected object

We can get the label map from the tflite model with metadata by unzipping it.

Please find this [gist](https://colab.research.google.com/gist/pjpratik/40842c05fae056d6009f15edd67a123b/61441.ipynb) for the same.

Thanks.


 hi pjpratik ,
Thanks for your reply ,
can you please help us to understand how an image can be passed as tensor input with dimensions [1,320,320,3],  for this model.
 Hi @ShiviAGL ,

Since you have a model with metadata, you can use [TensorFlow Lite Task Library](https://www.tensorflow.org/lite/inference_with_metadata/task_library/object_detector#step_2_using_the_model_2) with the same `tflite_support` library which provides easy to use interfaces for TFLite.

Incase if you are interested in Swift based implementation, please check this [model data handler](https://github.com/tensorflow/examples/blob/630bd990cc909cee217a805e4b4ce258721f3432/lite/examples/object_detection/ios/ObjectDetection/ModelDataHandler/ModelDataHandler.swift) in object detection example.

Please let us know if it helps.

Thanks. ok , thanks .
will check and let you know. hi @pjpratik ,

I have used TensorFlowLiteTaskVision and followed the steps using https://www.tensorflow.org/lite/inference_with_metadata/task_library/object_detector#swift

        guard let modelPath = Bundle.main.path(forResource: "ssd_320_fpnlite_rtpd_exterior_fp32_metadata",
                                                    ofType: "tflite") else { return }

        let options = ObjectDetectorOptions(modelPath: modelPath)

        // options.classificationOptions.maxResults = 3

        do {
            let detector = try ObjectDetector.detector(options: options)
            
            guard let image = UIImage (named: "carimage.jpeg"), let mlImage = MLImage(image: image) else { return }

            do{ let detectionResult = try detector.detect(mlImage: mlImage)}
            catch {throw error}

        }
        catch{
            throw error
        }

        




then I am getting this errors in log:

2023-08-10 17:26:39.458625+0530 Nexa[5290:4005447] [tcp] tcp_input [C16.1.1.1:3] flags=[R.] seq=3641772054, ack=340852762, win=0 state=CLOSED rcv_nxt=3641772007, snd_una=340852685
2023-08-10 17:26:39.473151+0530 Nexa[5290:4003754] Initialized TensorFlow Lite runtime.
INFO: Initialized TensorFlow Lite runtime.
2023-08-10 17:26:39.477445+0530 Nexa[5290:4003754] Created TensorFlow Lite XNNPACK delegate for CPU.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
2023-08-10 17:26:39.481691+0530 Nexa[5290:4003754] failed to create XNNPACK runtime
ERROR: failed to create XNNPACK runtime
2023-08-10 17:26:39.482903+0530 Nexa[5290:4003754] failed to create XNNPACK runtime
ERROR: failed to create XNNPACK runtime
2023-08-10 17:26:39.483089+0530 Nexa[5290:4003754] failed to create XNNPACK runtime
ERROR: failed to create XNNPACK runtime
2023-08-10 17:26:39.483877+0530 Nexa[5290:4003754] Node number 157 (TfLiteXNNPackDelegate) failed to prepare.
ERROR: Node number 157 (TfLiteXNNPackDelegate) failed to prepare.
2023-08-10 17:26:39.484266+0530 Nexa[5290:4003754] Restored original execution plan after delegate application failure.
ERROR: Restored original execution plan after delegate application failure.
2023-08-10 17:26:59.219212+0530 Nexa[5290:4005310] [tcp] tcp_input [C15.1.1.1:3] flags=[R.] seq=51485920, ack=3936341466, win=0 state=LAST_ACK rcv_nxt=51485920, snd_una=3936341420
2023-08-10 17:26:59.219761+0530 Nexa[5290:4005310] [tcp] tcp_input [C17.1.1.1:3] flags=[R.] seq=3431658725, ack=3245991258, win=0 state=LAST_ACK rcv_nxt=3431658725, snd_una=3245991212
2023-08-10 17:26:59.224111+0530 Nexa[5290:4005310] [tcp] tcp_input [C15.1.1.1:3] flags=[R.] seq=51485920, ack=3936341498, win=0 state=CLOSED rcv_nxt=51485920, snd_una=3936341420

Please have a look and help me to understand what can we do to get result by passing image for this model? Hi @ShiviAGL 

I have tried your model with Python API with random data and was able to get results. Please find this [gist](https://colab.research.google.com/gist/pjpratik/8975520e37604b1bad398c7dec02b518/61441.ipynb).

There seems to be no issue model. Could you check this ios [object detector](https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/ios/ObjectDetection/TFLite/ObjectDetectionHelper.swift) example which uses the TFLiteTaskLibrary and let us know if it helps?

Thanks. Hi @pjpratik 
Thanks for your reply .
We have tried the same model with Android studio as well and its working fine but for iOS Xcode with swift 5 we are unable to get results from this model so we are just looking for the help to integrate this model in our iOS project. 

I have tried with    
pod 'TensorFlowLiteSwift'
and
pod 'TensorFlowLiteTaskVision'

 with different ways with frames and images as well as an tensor input but with all the different ways i got errors :
 **error in recognition Provided data count 150528 must match the required count 1228800**
 and then after checking the input interpreter.invoke() failed and then followed the TensorFlowLiteTaskVision and then again for the simple image getting error : failed to create XNNPACK runtime

also tried with  Firebase as well (https://firebase.google.com/docs/ml-kit/ios/use-custom-models) 

So the requirement is to detect the image(not frame) with this model in ios swift 5 
and for that what will be the correct approach as I have checked TFLiteTaskLibrary too and here we can use TensorFlowLiteTaskVision and then I have implemented the same but again failed with XNNPACK runtime issue.
so can you please help us to understand what are the reasons to got these errors. 


Is there any complete guide to understand how an image can be used for object detection using Tflite models with detailed description for the tensor input dimensions and how can we use the values like maximum number of detections and image with dimension [1,320,320,3] and the  input preprocessing mean , input preprocessing standard deviation with datatype float32.
 Hi @ShiviAGL 

Thanks for the information. Seems like the issue is with iOS only, as per understanding. 

@pkgoogle Could you please look into this issue?

Thanks. Hi @ShiviAGL, I was able to get a result from your model with my toy project that's basically just this:

_1441_toyApp:
```swift
//
//  _1441_toyApp.swift
//  61441_toy
//
//

import SwiftUI
import TensorFlowLiteTaskVision

@main
struct _1441_toyApp: App {
  init() {
    // Initialization
    do {
      guard let modelPath = Bundle.main.path(forResource: "ssd_320_fpnlite_rtpd_exterior_fp32_metadata",
                                             ofType: "tflite") else { return }

      let options = ObjectDetectorOptions(modelPath: modelPath)

      // Configure any additional options:
      // options.classificationOptions.maxResults = 3

      let detector = try ObjectDetector.detector(options: options)

      // Convert the input image to MLImage.
      // There are other sources for MLImage. For more details, please see:
      // https://developers.google.com/ml-kit/reference/ios/mlimage/api/reference/Classes/GMLImage
      guard let image = UIImage (named: "istockphoto-925066016-612x612.jpg"), let mlImage = MLImage(image: image) else { return }

      // Run inference
      let detectionResult = try detector.detect(mlImage: mlImage)
      print(detectionResult)
    } catch {
      print(error)
    }
  }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
```

ContentView (Default app one):
```swift
//
//  ContentView.swift
//  61441_toy
//
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
```

my PodFile:
```sh
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target '61441_toy' do
  # Comment the next line if you don't want to use dynamic frameworks
  # use_frameworks!

  # Pods for 61441_toy
  pod 'TensorFlowLiteTaskVision'

end
```

My image is different, but I didn't try anything special with it. My swift version is also 5. Can you try with a very simple project like the above and see if you can get a result? Thanks for your help. @pkgoogle 
Thanks for your reply, will check this approach too and let you know about the results.  This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61441">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61441">No</a>

Swift 5 