-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Bug of Softmax op with different axis #17833
Comments
The operation you are getting the "right" result with and the Softmax in the model are not exactly the same operation. You have an opset 11 model (side question - can this be updated ?), and the spec for opset-11 Softmax can be found here - https://onnx.ai/onnx/operators/onnx__Softmax.html#l-onnx-op-softmax-11. Illustration (based on the spec): Softmax-11 with axis=1 with 4-D data means that the input will be "coerced" into [d0, d1 * d2 * d3] and softmax will be computed on this "coerced" tensor. Your "right result Python" implementation (based on numpy) is actually flattening the 4-D data into [d0 * d1 * d2 * d3] and softmax is performed on this "flat" list of data. As you can see, they are not the same semantically. In fact, no value of axis for Softmax-11 will align with your "Python" implementation as no value of axis can make the data into Softmax-11 into [1, x] shape (that is why your previous steps failed too). You have actually found what your model is missing through your experimentation. I am guessing the exporter/converter is missing a Flatten operator (https://onnx.ai/onnx/operators/onnx__Flatten.html) with axis=0 leading into the Softmax with axis=1. This should align the data operation with your "right result Python" implementation. |
thanks. i know your means. i misunderstand the axis definition with opset-11. the source onnx model is right, the total subgraph is: [tranpose(nchw->nhwc), softmax(axis=3), transpose(nhwc->nchw)], this can implement softmax(axis=1). i tried to optimze the graph, And replace the [tranpose(nchw->nhwc), softmax(axis=3), transpose(nhwc->nchw)] to softmax(axis=1), and than counting this problem. |
Then in that case, using Softmax with axis=1 should work from opset-13 because the opset-13 changed what "axis" means semantically in the |
Still, with opset=16,
|
Describe the issue
we hava a seg model here https://github.com/Tunaaaaa/softmax_bug/blob/main/face_seg.onnx
we generate random input here https://github.com/Tunaaaaa/softmax_bug/blob/main/x.txt
the last op is Softmax with axis=1
when run this onnx model as follow, we got wrong result
To reproduce
use face_seg.onnx model and input txt with below script. more infomation see: onnx/onnx#5655
Urgency
No response
Platform
Mac
OS Version
13.4.1 (c) (22F770820d)
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.15.1
ONNX Runtime API
Python
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response
The text was updated successfully, but these errors were encountered: