unknown output shape before inference
I want to write a custom operation in python, the output shape is unknown before running 'forward()'. So how to write the 'infer_shape()' function? It seems I must infer the output shape from the input shape, but without the input data.
Yes, during the phase of infer_shape we cannot access the input data. After infer_shape we can run the computation graph with input data.
If your operator's output has a maximum shape, I think there is a work around with gluon. infer_shape of your operator can return two shapes, the predefined maximum shape and a one dimension shape holding the actual size of your output,
output, size = custom_op(...)
actual_size = size.asscalar()
output = output.reshape(-1)[ : actual_size]
Here is a relevant issue with dynamic shape, https://github.com/apache/incubator-mxnet/issues/8822.
@ZiyueHuang Thank you for your response.
There is a maximum shape of my operator's output. Did you mean the output and actual size output, size are two output symbols of my operator? If it is, I got an error from asscalar():
NotImplementedForSymbol: Function asscalar is not implemented for Symbol and only available in NDArray.
So is there any way to deal with the symbolic operator?
@cccorn - Asking usability questions at discuss - https://discuss.mxnet.io/ will yield faster response.
@sandeep-krishnamurthy : Tag it to label "question" and can be closed.