I don't understand the “Shape inconsistent” error using mxnet









up vote
0
down vote

favorite












Coming from Keras, I try to reproduce my simple model with MXNet to make prediction using Module.



I'm using that simple dataset: https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data



I've got 13 inputs (from alcohol to Proline) that I want to send to the model, and I need to classify the first column that is "wine type", so I create a nd.array that have 3 entries.




x = data.values[: , 1:14]
y = data.values[:, 0]

X = mx.nd.array(x)
Y =
for i, v in enumerate(y):
d = [0,0,0]
d[int(v)-1] = 1
Y.append(d)
Y = mx.nd.array(Y)
Y.shape, X.shape
# ((178, 3), (178, 13))


Then I create the model and a NDIterator:




net = mx.symbol.Variable('winechemical')
net = mx.symbol.FullyConnected(net, num_hidden=64)
net = mx.symbol.Activation(net, act_type='relu')
net = mx.symbol.FullyConnected(net, num_hidden=32)
net = mx.symbol.Activation(net, act_type='relu')
net = mx.symbol.FullyConnected(net, num_hidden=16)
net = mx.symbol.SoftmaxOutput(net, name='wineclass')

model = Module(symbol=net, context=mx.cpu(),
data_names=['winechemical'],
label_names=['wineclass_label'])

gen = mx.io.NDArrayIter(X, label=Y,
batch_size=10,
shuffle=True, data_name='winechemical',
label_name='wineclass_label')


But when I try to "train" the model using the "fit" method, I got this error:




model.fit(gen, num_epoch=5)

[...]
Error in operator wineclass: Shape inconsistent, Provided = [10,3], inferred shape=[10]


I'm pretty sure that I don't understand the shape to uses as I'm coming from Keras that use different shape... But where am I wrong ?



Thanks for your help.










share|improve this question

























    up vote
    0
    down vote

    favorite












    Coming from Keras, I try to reproduce my simple model with MXNet to make prediction using Module.



    I'm using that simple dataset: https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data



    I've got 13 inputs (from alcohol to Proline) that I want to send to the model, and I need to classify the first column that is "wine type", so I create a nd.array that have 3 entries.




    x = data.values[: , 1:14]
    y = data.values[:, 0]

    X = mx.nd.array(x)
    Y =
    for i, v in enumerate(y):
    d = [0,0,0]
    d[int(v)-1] = 1
    Y.append(d)
    Y = mx.nd.array(Y)
    Y.shape, X.shape
    # ((178, 3), (178, 13))


    Then I create the model and a NDIterator:




    net = mx.symbol.Variable('winechemical')
    net = mx.symbol.FullyConnected(net, num_hidden=64)
    net = mx.symbol.Activation(net, act_type='relu')
    net = mx.symbol.FullyConnected(net, num_hidden=32)
    net = mx.symbol.Activation(net, act_type='relu')
    net = mx.symbol.FullyConnected(net, num_hidden=16)
    net = mx.symbol.SoftmaxOutput(net, name='wineclass')

    model = Module(symbol=net, context=mx.cpu(),
    data_names=['winechemical'],
    label_names=['wineclass_label'])

    gen = mx.io.NDArrayIter(X, label=Y,
    batch_size=10,
    shuffle=True, data_name='winechemical',
    label_name='wineclass_label')


    But when I try to "train" the model using the "fit" method, I got this error:




    model.fit(gen, num_epoch=5)

    [...]
    Error in operator wineclass: Shape inconsistent, Provided = [10,3], inferred shape=[10]


    I'm pretty sure that I don't understand the shape to uses as I'm coming from Keras that use different shape... But where am I wrong ?



    Thanks for your help.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Coming from Keras, I try to reproduce my simple model with MXNet to make prediction using Module.



      I'm using that simple dataset: https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data



      I've got 13 inputs (from alcohol to Proline) that I want to send to the model, and I need to classify the first column that is "wine type", so I create a nd.array that have 3 entries.




      x = data.values[: , 1:14]
      y = data.values[:, 0]

      X = mx.nd.array(x)
      Y =
      for i, v in enumerate(y):
      d = [0,0,0]
      d[int(v)-1] = 1
      Y.append(d)
      Y = mx.nd.array(Y)
      Y.shape, X.shape
      # ((178, 3), (178, 13))


      Then I create the model and a NDIterator:




      net = mx.symbol.Variable('winechemical')
      net = mx.symbol.FullyConnected(net, num_hidden=64)
      net = mx.symbol.Activation(net, act_type='relu')
      net = mx.symbol.FullyConnected(net, num_hidden=32)
      net = mx.symbol.Activation(net, act_type='relu')
      net = mx.symbol.FullyConnected(net, num_hidden=16)
      net = mx.symbol.SoftmaxOutput(net, name='wineclass')

      model = Module(symbol=net, context=mx.cpu(),
      data_names=['winechemical'],
      label_names=['wineclass_label'])

      gen = mx.io.NDArrayIter(X, label=Y,
      batch_size=10,
      shuffle=True, data_name='winechemical',
      label_name='wineclass_label')


      But when I try to "train" the model using the "fit" method, I got this error:




      model.fit(gen, num_epoch=5)

      [...]
      Error in operator wineclass: Shape inconsistent, Provided = [10,3], inferred shape=[10]


      I'm pretty sure that I don't understand the shape to uses as I'm coming from Keras that use different shape... But where am I wrong ?



      Thanks for your help.










      share|improve this question













      Coming from Keras, I try to reproduce my simple model with MXNet to make prediction using Module.



      I'm using that simple dataset: https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data



      I've got 13 inputs (from alcohol to Proline) that I want to send to the model, and I need to classify the first column that is "wine type", so I create a nd.array that have 3 entries.




      x = data.values[: , 1:14]
      y = data.values[:, 0]

      X = mx.nd.array(x)
      Y =
      for i, v in enumerate(y):
      d = [0,0,0]
      d[int(v)-1] = 1
      Y.append(d)
      Y = mx.nd.array(Y)
      Y.shape, X.shape
      # ((178, 3), (178, 13))


      Then I create the model and a NDIterator:




      net = mx.symbol.Variable('winechemical')
      net = mx.symbol.FullyConnected(net, num_hidden=64)
      net = mx.symbol.Activation(net, act_type='relu')
      net = mx.symbol.FullyConnected(net, num_hidden=32)
      net = mx.symbol.Activation(net, act_type='relu')
      net = mx.symbol.FullyConnected(net, num_hidden=16)
      net = mx.symbol.SoftmaxOutput(net, name='wineclass')

      model = Module(symbol=net, context=mx.cpu(),
      data_names=['winechemical'],
      label_names=['wineclass_label'])

      gen = mx.io.NDArrayIter(X, label=Y,
      batch_size=10,
      shuffle=True, data_name='winechemical',
      label_name='wineclass_label')


      But when I try to "train" the model using the "fit" method, I got this error:




      model.fit(gen, num_epoch=5)

      [...]
      Error in operator wineclass: Shape inconsistent, Provided = [10,3], inferred shape=[10]


      I'm pretty sure that I don't understand the shape to uses as I'm coming from Keras that use different shape... But where am I wrong ?



      Thanks for your help.







      python mxnet






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 11:00









      Metal3d

      2,0031520




      2,0031520






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          My god, sorry... I didn't see that I let 16 outputs instead of 3...






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238271%2fi-dont-understand-the-shape-inconsistent-error-using-mxnet%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            My god, sorry... I didn't see that I let 16 outputs instead of 3...






            share|improve this answer
























              up vote
              0
              down vote













              My god, sorry... I didn't see that I let 16 outputs instead of 3...






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                My god, sorry... I didn't see that I let 16 outputs instead of 3...






                share|improve this answer












                My god, sorry... I didn't see that I let 16 outputs instead of 3...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 11:09









                Metal3d

                2,0031520




                2,0031520



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238271%2fi-dont-understand-the-shape-inconsistent-error-using-mxnet%23new-answer', 'question_page');

                    );

                    Post as a guest














































































                    這個網誌中的熱門文章

                    What does pagestruct do in Eviews?

                    Dutch intervention in Lombok and Karangasem

                    Channel Islands