Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile] iOS - ZipMap output cannot be read #22505

Open
sanjaymk908 opened this issue Oct 18, 2024 · 4 comments
Open

[Mobile] iOS - ZipMap output cannot be read #22505

sanjaymk908 opened this issue Oct 18, 2024 · 4 comments
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@sanjaymk908
Copy link

Describe the issue

I use the objc bindings for onnxruntime in my iOS app. I load my ML classifier (onnx model), supply it inputs & get valid responses
Image

The code looks like this:
// Create ORTValue for input data
let inputTensor = try createORTValueFromEmbeddings(inputData)

        // Step 2: Prepare input and run session
        let inputs: [String: ORTValue] = [
            "float_input": inputTensor,
        ]
        let outputs = try ortSession.run(
            withInputs: inputs,
            outputNames: ["output_probability", "output_label"],
            runOptions: nil
        )

        let endTime = DispatchTime.now()
        print("ORT session run time: \(Float(endTime.uptimeNanoseconds - startTime.uptimeNanoseconds) / 1.0e6) ms")

        guard let _ = outputs["output_probability"], let labels = outputs["output_label"] else {
            throw CloneInferenceError.Error("Failed to get model output.")
        }
        
        let labelsData = try labels.tensorData() as Data
        let labelValue = labelsData.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) -> Int64 in
            let int64Buffer = buffer.bindMemory(to: Int64.self)
            return int64Buffer[0]
        }

        if labelValue == 0 {
            return "Audio is real"
        } else {
            return "Audio is cloned"
        }

I am able to process/read "output_label" (0 or 1 value) just fine as an Int64. However, "output_probability" which is a float - I just cannot read it using similar steps. Note that it is produced by a ZipMap but "output_label" isn't.
Any suggestions?

To reproduce

You cna use this onnx model:
https://yella.co.in/cvd-samples/classifier.onnx

And use the objC onnxruntime sample to load it & evaluate it to get the outputs (like above).

Urgency

Its a showstopper for me because w/o output probabilities, the model is kindof useless actually.

Platform

iOS

OS Version

17.6.1

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

onnxruntime-mobile

ONNX Runtime Version or Commit ID

1.19.0

ONNX Runtime API

Objective-C/Swift

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@sanjaymk908 sanjaymk908 added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Oct 18, 2024
@vraspar
Copy link
Contributor

vraspar commented Oct 18, 2024

I was not able to access the model from provided link. I believe that zipmap op outputs map/dictionary not float

@skottmckay
Copy link
Contributor

Do you need the ZipMap operator in the model? May be simpler to return the output from the LinearClassifier directly.

@sanjaymk908
Copy link
Author

I was not able to access the model from provided link. I believe that zipmap op outputs map/dictionary not float

You can try "wget https://yella.co.in/cvd-samples/classifier.onnx" - worked for me.

@edgchen1
Copy link
Contributor

I believe that zipmap op outputs map/dictionary not float

The Objective-C API doesn't support non-tensor ORTValue types at the moment and ZipMap does not output a tensor. A workaround for now is to avoid using non-tensor types in your model or to use the C/C++ API. For the former, directly using the tensor output of LinearClassifier should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

4 participants