Symbolic API layer's weights

Hello everyone.

I’m building a new custom layer in MXNet, it has to work both with gluon and symbolic API.
Custom layer needs to access to weights of the previous layer. In custom layer I have an instance reference of the previous layer as I pass the reference in the class constructor.

I can obtain weights as follows:

kernel = self.layer.collect_params().get('weight')

but I got the following error:

AssertionError: Argument data must be Symbol instances, but got Parameter dense0_weight (shape=(256, 61), dtype=float32)

It works fine with the gluon api kernel = but I need it to make it works in the symbolic api as well. Please be aware that self.layer does not refer to the current custom layer but it’s a reference for the previous layer in a HybridSequential.

Do you guys have any hints?

Hi @vitob,

When using the Symbolic API, the symbol itself doesn’t contain the parameters, but you have to bind the symbol with the parameters to get an Executor.

You can access the parameters through the arg_dict and aux_dict methods.

I hope that this is helpful.