{"action":"opened","issue":{"url":"https://api.github.com/repos/dmlc/mxnet/issues/831","labels_url":"https://api.github.com/repos/dmlc/mxnet/issues/831/labels{/name}","comments_url":"https://api.github.com/repos/dmlc/mxnet/issues/831/comments","events_url":"https://api.github.com/repos/dmlc/mxnet/issues/831/events","html_url":"https://github.com/dmlc/mxnet/issues/831","id":120542263,"number":831,"title":"How to build an MLP by MXNet?","user":{"login":"were","id":2356965,"avatar_url":"https://avatars.githubusercontent.com/u/2356965?v=3","gravatar_id":"","url":"https://api.github.com/users/were","html_url":"https://github.com/were","followers_url":"https://api.github.com/users/were/followers","following_url":"https://api.github.com/users/were/following{/other_user}","gists_url":"https://api.github.com/users/were/gists{/gist_id}","starred_url":"https://api.github.com/users/were/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/were/subscriptions","organizations_url":"https://api.github.com/users/were/orgs","repos_url":"https://api.github.com/users/were/repos","events_url":"https://api.github.com/users/were/events{/privacy}","received_events_url":"https://api.github.com/users/were/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-05T09:15:03Z","updated_at":"2015-12-05T09:15:03Z","closed_at":null,"body":"I try to use MXNet to build an MLP for interpolation.\r\n\r\nHere is my python code, to use this code, `python build.py 5 5 8 8 8 2`.\r\n\r\nIt tries to build a 5-layer MLP, which treats a 5-d vector as input and a 2-d vector as output.\r\n\r\nThere are 3 hidden layers for this MLP, each layer has 8 neurons.\r\n\r\n`````\r\nimport mxnet as mx\r\nimport numpy\r\nimport sys\r\n\r\n#print sys.argv\r\nargs = sys.argv[1:]\r\ntry:\r\n    print args\r\n    n_layers = int(args[0])\r\nexcept:\r\n    print 'The first argument should be number of layers!'\r\n    quit()\r\n\r\nnn = None\r\ntry:\r\n    nn = mx.symbol.Variable('data')\r\n    print 'shape is', nn.infer_shape\r\nexcept:\r\n    print 'Failed to initialize input layer!'\r\n    quit()\r\n\r\ntry:\r\n    for i in range(2, n_layers):\r\n        nn = mx.symbol.FullyConnected(data = nn, name = 'hidden-recept-' + str(i), num_hidden = int(args[i]))\r\n        nn = mx.symbol.Activation(data = nn, name = 'hidden-act-' + str(i), act_type = 'relu')\r\nexcept:\r\n    print 'Failed to initailize hidden layer!'\r\n    quit()\r\n\r\ntry:\r\n    nn = mx.symbol.FullyConnected(data = nn, name = 'hidden-recept-' + str(n_layers), num_hidden = int(args[n_layers]))\r\n    nn = mx.symbol.LinearRegressionOutput(data = nn, name = 'softmax')\r\nexcept:\r\n    print 'Failed to build output layer!'\r\n    quit()\r\n\r\ndata = open('data').readlines()\r\nx,y = [],[]\r\nfor i in xrange(len(data)):\r\n    if i % 2 == 0:\r\n        x.append(map(float, data[i].split()))\r\n    else:\r\n        y.append(map(float, data[i].split()))\r\nx = mx.ndarray.array(x).asnumpy()\r\ny = mx.ndarray.array(y).asnumpy()\r\niterator = mx.io.NDArrayIter(data = x, label = y, batch_size = 128)\r\n#print iterator.provide_data, iterator.provide_label\r\n\r\ndata = open('test').readlines()\r\nx,y = [],[]\r\nfor i in xrange(len(data)):\r\n    if i % 2 == 0:\r\n        x.append(map(float, data[i].split()))\r\n    else:\r\n        y.append(map(float, data[i].split()))\r\nx = mx.ndarray.array(x).asnumpy()\r\ny = mx.ndarray.array(y).asnumpy()\r\ntester = mx.io.NDArrayIter(data = x, label = y, batch_size = 128)\r\n#print provide_data, provide_label\r\n\r\nmodel = mx.model.FeedForward(\r\n        symbol = nn,\r\n        ctx = mx.gpu(0),\r\n        num_epoch = 1000,\r\n        learning_rate = .1,\r\n        momentum = .9,\r\n        wd = 1e-5,\r\n        initializer = mx.init.Xavier(factor_type = 'in', magnitude = 2.34)\r\n)\r\n\r\nprint iterator.provide_data, iterator.provide_label\r\nmodel.fit(\r\n        X = iterator,\r\n        eval_data = tester,\r\n        batch_end_callback = mx.callback.Speedometer(128, 50)\r\n)\r\n\r\nmodel.save(\"res\")\r\ntester.next()\r\nprint model.predict(tester)\r\n`````\r\n\r\nIf I use `eval_data`, it gives me the following error log:\r\n\r\n`````\r\nTraceback (most recent call last):\r\n  File \"builder.py\", line 79, in <module>\r\n    tester.next()\r\n  File \"/Users/were/Lab/nnbuilder/mxnet/io.py\", line 213, in next\r\n    raise StopIteration\r\nStopIteration\r\n`````"}}