Export slice_like operation to onnx


#1

Hi guys.
i have troubles to export ssd_512_mobilenet1.0_voc model into onnx format
it says:
No conversion function registered for op type slice_like yet.

how can i probably fix that.

tnx for any hints


#2

Hi @zavalit,

I had a similar issue with broadcast_like because it’s not in the ONNX specification. My work around was to use operators that are supported instead such as broadcast_mul.

So converted…

mx.nd.broadcast_like(x, y)

to…

mx.nd.broadcast_mul(x, (y * 0) + 1)

You could do the broadcasting before the slice with the above methods, and that should be convertable to ONNX format. All of this needs to be changed inside the network though, but it won’t change the parameters so you can still used the pre-trained networks. Might be worth raising an issue on the GluonCV GitHub about this, so other uses don’t have this issue in the future.


#3

hi @thomelane

tnx for an advice. my be i’m missing smth. but accroding to slice_like spec, it has to bring x to the shape of y, and i can barely imagine that

does it anyhow. i definitely missing smth there.


#4

Maybe an example will help you see how x is broadcast to the shape of y:

import mxnet as mx

x = mx.nd.array([[1,2,3]])
print(x)

y = mx.nd.array([[4,5,6], [7,8,9]])
print(y)

y_ones = (y * 0) + 1
print(y_ones)

x_broadcast = mx.nd.broadcast_mul(x, (y * 0) + 1)
print(x_broadcast)

Giving the following outputs:

[[1. 2. 3.]]
<NDArray 1x3 @cpu(0)>

[[4. 5. 6.]
 [7. 8. 9.]]
<NDArray 2x3 @cpu(0)>

[[1. 1. 1.]
 [1. 1. 1.]]
<NDArray 2x3 @cpu(0)>

[[1. 2. 3.]
 [1. 2. 3.]]
<NDArray 2x3 @cpu(0)>