0

I'm trying to use Python to parse mxnet params into plain text. The code looks like the below. But the parsing result is not plain string, but some encoded text looks like this, "... \xaa>\x0f\xed\x8e>\xaf!\x8f>g ..." Could anybody give me some tips on it? Thanks a lot!

...

param_file = 'resnet-50-0000.params'
with open(param_file, 'rb') as f:
    net_params = f.read()

...

apepkuss
  • 13
  • 3

1 Answers1

2

The parameters are binary files. If you want to read them as plain text you need to decode them first as a dictionary of parameter_name->NDArray, that you can convert them to numpy. From numpy you can convert it to a list and then process it as a list (of lists) of scalar.

import mxnet as mx

params = mx.nd.load('resnet-50-0000.params')
for k, param in params.items():
    print(k)
    print(param.asnumpy().tolist())
Thomas
  • 676
  • 3
  • 18