This is a simple DNN from Fast, portable neural networks with Gluon HybridBlocks:

This is json file and params file of Gluon(MXNet)

import mxnet as mx
from mxnet.gluon import nn
print("mxnet version: "+mx.__version__)

mx.random.seed(1234)  #Getting the same result everytime
def get_net():
    # construct a MLP
    net = nn.HybridSequential()
    with net.name_scope():
        net.add(nn.Dense(256, activation="relu"))
        net.add(nn.Dense(128, activation="relu"))
    # initialize the parameters
    return net

# forward
x = mx.nd.array([[0.1,0.2,0.3]])
net = get_net()
print('=== net(x) ==={}'.format(net(x)))

from mxnet import sym
x = sym.var('data')

##############   Re-importing the net  ##############
sym = mx.symbol.load('model.json') 
nd = mx.nd.load('model.params')
inputND = mx.nd.array([[0.1,0.2,0.3]])
nd["data"] = inputND
e = sym.bind(mx.cpu(), nd)
out = e.forward()

mxnet version: 0.11.1

=== net(x) ===

[[ 0.00051653 -0.00040585]]

[[ 0.00051653 -0.00040585]]

In Mathematica11.2,this code will crash the kernel,I think because mma use old version of MXNet.At that time,there isn't gluon actually, a new interface of MXNet.


And this code also can't work

<< NeuralNetworks`;
net = ImportMXNetModel["model.json", "model.params"];
  • $\begingroup$ Links do not work. $\endgroup$ Oct 10, 2017 at 6:47
  • $\begingroup$ @b.gatessucks fixed. $\endgroup$
    – partida
    Oct 10, 2017 at 6:59

2 Answers 2


In Mathematica 11.2, this code will crash the kernel, I think because mma use old version of MXNet

This hypothesis is correct. I have verified that this works for internal 11.3 builds which use the latest version of MXNet, so it will automatically be fixed when 11.3 is released. It is a bug though that it crashes the kernel. Have reported this.

  • $\begingroup$ Yes,MMA use version 0.9.5.But MXNet has released the 0.12.0 $\endgroup$
    – partida
    Oct 30, 2017 at 1:52
  • $\begingroup$ MXNet support the new functionexport to export the net that make it easy using MXNet in C++ $\endgroup$
    – partida
    Oct 30, 2017 at 1:54

Bug fixed in 11.3.0

net = Import[
net[{0.1, 0.2, 0.3}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.