2

For example

Assume the Variables are:

  • inputs_a = mx.sym.Variable('inputs_a')
  • inputs_b = mx.sym.Variable('inputs_b')

Assume the network is:

  1. inputs_a[batch_size], 100]-->FullyConnected(10)-->outputs_a[batch, 10]
  2. inputs_b[batch_size], 50]-->FullyConnected(10)-->outputs_b[batch, 10]
  3. prediction = outputs_a + outputs_b

Assume the datas(numpy) are:

  • data_a which size is [batch_size, 100]
  • data_b which size is [batch_size, 50]
  • data_label which size is [batch_size, 10]

I want to know how to build the model?

mod = mx.mod.Module(context=mx.gpu(), symbol=prediction,
                    data_names=['inputs_a', 'inputs_b'], label_names=['label'])

And I want to know how to build the data iter?

train_iter = mx.io.NDArrayIter(data=[data_a, data_b], label=data_label,batch_size=3,data_name=['inputs_a', 'inputs_b'],label_name='label')

But this format is wrong.And I can not find this kind of multi inputdata demo in MXNet's tutorial and API documents.What's more, there are few blog of MXNet demo. So can you show me the right way to do it? Or show me your demo. Thanks!

Alex Hex
  • 51
  • 2
  • check multiIter described in mxnet documentation http://mxnet.io/api/python/io.html#mxnet.recordio.IRHeader – MAS Jul 13 '17 at 11:30
  • What are you getting from such a model, compared to building two different models or merging the input vectors? – Guy Jul 15 '17 at 23:19

1 Answers1

1

NDArrayIter has support for multiple inputs. The following code snippet hopefully captures what you want to do:

    import mxnet as mx

    X1 = mx.sym.Variable('X1')
    X2 = mx.sym.Variable('X2')
    Y = mx.sym.Variable('Y')

    fcX1 = mx.sym.FullyConnected(data=X1, num_hidden=10, name='fcX1')
    fcX2 = mx.sym.FullyConnected(data=X2, num_hidden=10, name='fcX2')

    prediction = fcX1 + fcX2

    graph = mx.sym.LinearRegressionOutput(data=prediction, label=Y, name='lro')

    model = mx.mod.Module(symbol=prediction, data_names=['X2', 'X1'], label_names=['Y'])

    # set x1, x2 and y to the training inputs corresponding to X1, X2 and Y
    data = {'X1' : x1, 'X2' : x2}
    label = {'Y' : y}
    data_iter = mx.io.NDArrayIter(data, label, batch_size)

    model.fit(data_iter, ...)