mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Potential solution for KeyError problems

Open gospodima opened this issue 2 years ago • 1 comments

Description

I had the same error as described in several issues here: #18923, #16590, #20317 and here By investigating the code, I came up with an idea that the probable problem of the KeyError issues is that during inputs initialization only self._nodes are considered (where graph inputs and node outputs are stored), however, some inputs can be also stored in initializer according to onnx documentation:

Names of the values used by the node to propagate input values to the node operator. It must refer to either a graph input, a graph initializer or a node output.

I tried to replace inputs = [self._nodes[i] for i in node.input] with:

inputs = []
for i in node.input:
    try:
        inputs.append(self._nodes[i])
    except KeyError:
        inputs.append(symbol.Variable(name=i, shape=self._params[i].shape))

And it looks like import is successfull then (i.e. all not found keys are actually found in params). But of course I don't initialize variable weights here. Unfortunately, I am not really advanced with mxnet and couldn't find a working way to initialize symbol.Variable with NDArray.

If it is possible to initialize variable with an array, it might be a working solution for this issue.

gospodima avatar Dec 29 '21 18:12 gospodima

Any update on this?

gcunhase avatar Jul 25 '22 22:07 gcunhase