1

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_ (

)
José Pereda
  • 44,311
  • 7
  • 104
  • 132
ikamen
  • 3,175
  • 1
  • 25
  • 47

2 Answers2

1

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

ikamen
  • 3,175
  • 1
  • 25
  • 47
1

Use collect_params() to returns a ParameterDict containing this Block and all of its children’s Parameters

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.initialize(mx.init.Normal(sigma=.1))
    return net

net_1 = build_net() 
print(net_1.collect_params())
Mohsenme
  • 1,012
  • 10
  • 20