1. 程式人生 > >mxnet踩坑記

mxnet踩坑記

mxnet/gluon延遲初始化特性

mxnet.gluon.parameter.DeferredInitializationError: Parameter fixedgcforest0_cascadelayer1_randomforest0_fcmodel0_sequential0_dense0_weight has not been initialized yet because initialization was deferred. Actual initialization happens during the first forward pass. Please pass one batch of data through the network before accessing Parameters. You can also avoid deferred initialization by specifying in_units, num_features, etc., for network layers.

這個錯誤是因為引數在使用之前是不會被初始化的。trainer.step()去update的時候如果有的層,一開始就沒參與計算,update()時候就會報錯。不過不是很明白,沒參與計算的層也不應該有梯度啊,那為什麼還需要update呢?

解決方法:
1.不要在hybridblock類的init函式裡定義不被使用的類;
2.重寫一下trainer的step函式;或者在繼承於hybridblock類裡面新增一個初始化的過程(沒太看懂這個)。