How to initialize parameters when putting the convolutional layer into the list?

When putting multiple conv2d into a list when defining the model, will it cause the conv2d parameters in the list not to be initialized?

model.collect_params().initialize(mx.init.Xavier(), ctx=ctx)

optimizer = gluon.Trainer(model.collect_params(), ‘adam’,
{‘learning_rate’: learning_rate})
I have instantiated a model object.
RuntimeError: Parameter cnn_model9_conv0_weight has not been initialized. Note that you should initialize parameters and create Trainer with Block.collect_params() instead of Block.params because the later does not include Parameters of nested child Blocks

please help me

See this topic, you need to use (Hybrid)Sequential, then you access layers just like a list.

You are right. I solved this problem by your method. Thank you very much.

1 Like