Tag Archives: Hello.

Mxnet general optimizer usage

 
Adam optimizer:

weight_decay=5e-4

adam_lr=0.01
optimizer = mx.optimizer.Adam(learning_rate=adam_lr, wd=weight_decay)

 
 

wd = 0.0005

   opt = optimizer.SGD(learning_rate=lr,
                        momentum=0.9,
                        wd=wd,
                        rescale_grad=1.0/len(ctx),
                        clip_gradient=None)

 

assert self.binded

 
assert self.binded
Error code:

mod_new.bind(for_training=False,data_shapes=[('data',(1,3,data_shape_w,data_shape_w))],label_shapes=mod_new.label_shapes)
  File "D:\Anaconda3\lib\site-packages\mxnet\module\module.py", line 231, in label_shapes
    assert self.binded

 

resolvent:

Remove parameter: Label_ shapes

mod_new.bind(for_training=False,data_shapes=[('data',(1,3,data_shape_w,data_shape_w))])

 

onnx.onnx_cpp2py_export.checker.ValidationError

onnx.onnx cpp2py export Yeah. checker.ValidationError

“25253rd;”381693rd;”

    import mxnet as mx
    import numpy as np
    from mxnet.contrib import onnx as onnx_mxnet
    import logging

    logging.basicConfig(level=logging.INFO)
    from onnx import checker
    import onnx

    syms = './mxnet/new_model-symbol.json'
    params = './mxnet/new_model-0000.params'

    input_shape = (1, 3, 112, 112)

    onnx_file = './mnist.onnx'

    # Invoke export model API. It returns path of the converted onnx model
    converted_model_path = onnx_mxnet.export_model(syms, params, [input_shape], np.float32, onnx_file)

    # Load onnx model
    model_proto = onnx.load_model(converted_model_path)

Online solution: pip install onnx==1.5.0
After the change, more errors are reported.
onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: spatial for operator BatchNormalization
==> Context: Bad node spec: input: “conv_1_conv2d” input: “conv_1_batchnorm_gamma” input: “conv_1_batchnorm_beta” input: “conv_1_batchnorm_moving_mean” input: “conv_1_batchnorm_moving_var” output: “conv_1_batchnorm” name: “conv_1_batchnorm” op_type: “BatchNormalization” attribute { name: “epsilon” f: 0.001 type: FLOAT } attribute { name: “momentum” f: 0.9 type: FLOAT } attribute { name: “spatial” i: 0 type: INT }