Multiple outputs .tojson()

Hello!
I have a hybrid model with multiple outputs that i want to export as a JSON (with Symbol .tojson() method). So, what’s the best way to do that?

x = [mx.sym.var('__input__' + str(i)) for i in range(len(args))]
sym = net(*x)

In the snippet above the sym is a tuple, therefore i can’t call .tojson() to get a whole graph.

I am not sure if I fully understand your question. Assuming you have a model like the following:

net = mx.sym.Variable('data')
fc1 = mx.sym.FullyConnected(data=net, name='fc1', num_hidden=128)
net = mx.sym.Activation(data=fc1, name='relu1', act_type="relu")
out1 = mx.sym.SoftmaxOutput(data=net, name='softmax')
out2 = mx.sym.LinearRegressionOutput(data=net, name='regression')

which has two outputs, you could then use mx.sym.Group():

group = mx.sym.Group([out1, out2])
print group.tojson()
1 Like

Yes, it’s exactly what I was looking for. Thank you!