pythonmxnet

gluon Sequential model: params return empty collection


I am using the code below to create a Sequential Gluon model. For some reason the property params returns an empty collection.

def build_net():
    net = gluon.nn.Sequential()
    with net.name_scope():
        net.add(gluon.nn.Dense(32, activation='relu'))
        net.add(gluon.nn.Dense(32, activation='relu'))
        net.add(gluon.nn.Dense(1))

    net.collect_params().initialize(mx.init.Normal(sigma=.1))
    return net

net_1 = build_net() 
print(net_1.params)

Output:

sequential0_ (

)

Solution

  • use Sequential.collect_params(), which collects not only this Block parameters, but also from all children (e.g. Layers).