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类里面添加一个初始化的过程(没太看懂这个)。

猜你喜欢

转载自blog.csdn.net/weixin_39354819/article/details/84951292