How can i derive weights from a model?
this is my code:
param = mymodel.get_params()
print param
print type(param["fc1_weight"].asnumpy())
but:
Traceback (most recent call last):
File "dunet_debug.py", line 58, in <module>
print type(param["fc1_weight"].asnumpy())
KeyError: 'fc1_weight'
what's the results from print param?
{'optimizer': 'sgd', 'initializer': <mxnet.initializer.Uniform object at 0x7f7d2bbb5310>, 'aux_params': {}, 'symbol': <mxnet.symbol.Symbol object at 0x7f7d2bbd92d0>, 'ctx': [cpu(0)], 'epoch_size': None, 'numpy_batch_size': 128, 'num_epoch': 200, 'begin_epoch': 0, 'allow_extra_params': False, 'arg_params': {'fc2_weight': <mxnet.ndarray.NDArray object at 0x7f7d2bbd9610>, 'fc1_weight': <mxnet.ndarray.NDArray object at 0x7f7d2bbd9490>, 'fc3_bias': <mxnet.ndarray.NDArray object at 0x7f7d2bbd96d0>, 'fc3_weight': <mxnet.ndarray.NDArray object at 0x7f7d2bbd9710>, 'fc2_bias': <mxnet.ndarray.NDArray object at 0x7f7d2bbd9750>, 'fc1_bias': <mxnet.ndarray.NDArray object at 0x7f7d2bbd95d0>}}
@piiswrong
Thanks
@diggerdu you can try mymodel.get_params()['arg_params']['fc1_weight'].asnumpy()
@Orange15 as before
@diggerdu The inner dictionary has the key fc1_weight and you should be able to access it via param["arg_params"]["fc1_weight"].
@sxjscience 谢谢你,终于好了。 我也叫Xing Jian(行健)
In the latest version 0.10.0, params = model.get_params() weights = model.get_params()[0]['name of the layer'].asnumpy()