How to initialize weights of Conv2D layer given an NDarray?

let’s say I have the following code:

from mxnet import gluon
from mxnet import nd

weights = ... # NDArray of shape (32, 7, 7)
myLayer = gluon.nn.Conv2D(32, (7,7))

What’s the easiest way to initialize the weights of myLayer using weights?

Hi,

you can do myLayer.collect_params.initialize as usual with the Constant Initializer. See https://mxnet.incubator.apache.org/api/python/optimization/optimization.html#mxnet.initializer.Constant

For example:

myLayer.collect_params.initialize(mx.initializerConstant(weights))