-
Couldn't load subscription status.
- Fork 3.5k
Open
Labels
api:Javaissues related to the Java APIissues related to the Java APIplatform:mobileissues related to ONNX Runtime mobile; typically submitted using templateissues related to ONNX Runtime mobile; typically submitted using template
Description
Describe the issue
The obvious way to build an input tensor can lead to unexpected results. onnxruntime should document that it requires native byte order in FloatBuffers, and (optionally) throw an IllegalArgumentException when provided with a buffer in non-native byte order.
To reproduce
val input = ByteBuffer.allocateDirect(tensorSize * 4).asFloatBuffer()
// Fill input using input.put
OnnxTensor.createTensor(env, input, longArrayOf(tensorSize))This code snippet will result in lots of NaNs downstream because ByteBuffer defaults to enforced-BigEndian mode. Instead, you need to call .order(ByteOrder.nativeOrder()) to ensure floats are stored in native byte order.
Urgency
Trivial to work around, but very annoying to debug.
Platform
Android
OS Version
n/a
ONNX Runtime Installation
Released Package
Compiler Version (if 'Built from Source')
No response
Package Name (if 'Released Package')
onnxruntime-android
ONNX Runtime Version or Commit ID
1.23.1
ONNX Runtime API
Java/Kotlin
Architecture
ARM64
Execution Provider
Default CPU
Execution Provider Library Version
No response
Metadata
Metadata
Assignees
Labels
api:Javaissues related to the Java APIissues related to the Java APIplatform:mobileissues related to ONNX Runtime mobile; typically submitted using templateissues related to ONNX Runtime mobile; typically submitted using template