MxNet: label_shapes don't match names specified by label_namesCalling a function of a module by using its name (a string)Getting the class name of an instance?What is the meaning of a single and a double underscore before an object name?What are “named tuples” in Python?How can I feed .csv training data to a convolutional neural network in mxnet?Why the cost function and the last activation function are bound in MXNet?When forward using MXNet, how to do with varying 'batch size' in data_shapes?MxNet has trouble saving all parameters of a networkMXNET softmax output: label shape confusionProblem with incompatible tensor shapes when training object detection model in Keras

Conjugate る-ending verbs into negative form

How would an order of Monks that renounce their names communicate effectively?

Most elegant way to write a one shot IF

How is this practical and very old scene shot?

Meaning of じゃないんじゃない?

How exactly is a normal force exerted, at the molecular level?

Lifting a probability measure to the power set

What was the impact of Fischer vs. Spassky 1972 on the relationship between the USA and the Soviet Union?

In native German words, is Q always followed by U, as in English?

How can my story take place on Earth without referring to our existing cities and countries?

Does a return economy-class seat between London and San Francisco release 5.28 t of CO2e?

Pshat of what did Korach take?

How did Lefschetz do mathematics without hands?

I hit a pipe with a mower and now it won't turn

cannot execute script while its permission is 'x'

Why do I need two parameters in an HTTP parameter pollution attack?

Can I travel from Germany to England alone as an unaccompanied minor?

One folder having two different locations on Ubuntu 18.04

What's the safest way to inform a new user of their password on an invite-only website?

Matrix decomposition

What does the phrase "building hopping chop" mean here?

Donkey as Democratic Party symbolic animal

Training with a subset of data: relationship between subset size and training metric?

Most important new papers in computational complexity



MxNet: label_shapes don't match names specified by label_names


Calling a function of a module by using its name (a string)Getting the class name of an instance?What is the meaning of a single and a double underscore before an object name?What are “named tuples” in Python?How can I feed .csv training data to a convolutional neural network in mxnet?Why the cost function and the last activation function are bound in MXNet?When forward using MXNet, how to do with varying 'batch size' in data_shapes?MxNet has trouble saving all parameters of a networkMXNET softmax output: label shape confusionProblem with incompatible tensor shapes when training object detection model in Keras






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I wrote a script to do the classification of a single input image using a model I trained with MxNet. To classify the incoming image I feedforward them in through network.



In short here is what I am doing:



symbol, arg_params, aux_params = mx.model.load_checkpoint('model-prefix', 42)
model = mx.mod.Module(symbol=symbol, context=mx.cpu())
model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)
model.set_params(arg_params, aux_params)

# ... loading the image & resizing ...
# img is the image to classify as numpy array of shape (3, 244, 244)

Batch = namedtuple('Batch', ['data'])
self._model.forward(Batch(data=[mx.nd.array(img)]))
probabilities = self._model.get_outputs()[0].asnumpy()

print(str(probabilities))


This works fine, except that I am getting the following warning



UserWarning: Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])


What should I change to avoid getting this warning? It is not clear to me what the label_shapes and label_names parameters are meant for, and what I am expect to fill them with.



Note: I found some thread about them, but none enabled me to solve the problem. Similarly the MxNet documentation doesn't provide much details on what those parameters are and on how they are supposed to be filled.










share|improve this question




























    1















    I wrote a script to do the classification of a single input image using a model I trained with MxNet. To classify the incoming image I feedforward them in through network.



    In short here is what I am doing:



    symbol, arg_params, aux_params = mx.model.load_checkpoint('model-prefix', 42)
    model = mx.mod.Module(symbol=symbol, context=mx.cpu())
    model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)
    model.set_params(arg_params, aux_params)

    # ... loading the image & resizing ...
    # img is the image to classify as numpy array of shape (3, 244, 244)

    Batch = namedtuple('Batch', ['data'])
    self._model.forward(Batch(data=[mx.nd.array(img)]))
    probabilities = self._model.get_outputs()[0].asnumpy()

    print(str(probabilities))


    This works fine, except that I am getting the following warning



    UserWarning: Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])


    What should I change to avoid getting this warning? It is not clear to me what the label_shapes and label_names parameters are meant for, and what I am expect to fill them with.



    Note: I found some thread about them, but none enabled me to solve the problem. Similarly the MxNet documentation doesn't provide much details on what those parameters are and on how they are supposed to be filled.










    share|improve this question
























      1












      1








      1








      I wrote a script to do the classification of a single input image using a model I trained with MxNet. To classify the incoming image I feedforward them in through network.



      In short here is what I am doing:



      symbol, arg_params, aux_params = mx.model.load_checkpoint('model-prefix', 42)
      model = mx.mod.Module(symbol=symbol, context=mx.cpu())
      model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)
      model.set_params(arg_params, aux_params)

      # ... loading the image & resizing ...
      # img is the image to classify as numpy array of shape (3, 244, 244)

      Batch = namedtuple('Batch', ['data'])
      self._model.forward(Batch(data=[mx.nd.array(img)]))
      probabilities = self._model.get_outputs()[0].asnumpy()

      print(str(probabilities))


      This works fine, except that I am getting the following warning



      UserWarning: Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])


      What should I change to avoid getting this warning? It is not clear to me what the label_shapes and label_names parameters are meant for, and what I am expect to fill them with.



      Note: I found some thread about them, but none enabled me to solve the problem. Similarly the MxNet documentation doesn't provide much details on what those parameters are and on how they are supposed to be filled.










      share|improve this question














      I wrote a script to do the classification of a single input image using a model I trained with MxNet. To classify the incoming image I feedforward them in through network.



      In short here is what I am doing:



      symbol, arg_params, aux_params = mx.model.load_checkpoint('model-prefix', 42)
      model = mx.mod.Module(symbol=symbol, context=mx.cpu())
      model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)
      model.set_params(arg_params, aux_params)

      # ... loading the image & resizing ...
      # img is the image to classify as numpy array of shape (3, 244, 244)

      Batch = namedtuple('Batch', ['data'])
      self._model.forward(Batch(data=[mx.nd.array(img)]))
      probabilities = self._model.get_outputs()[0].asnumpy()

      print(str(probabilities))


      This works fine, except that I am getting the following warning



      UserWarning: Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])


      What should I change to avoid getting this warning? It is not clear to me what the label_shapes and label_names parameters are meant for, and what I am expect to fill them with.



      Note: I found some thread about them, but none enabled me to solve the problem. Similarly the MxNet documentation doesn't provide much details on what those parameters are and on how they are supposed to be filled.







      python machine-learning computer-vision deep-learning mxnet






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 6 '17 at 11:01









      Pierre-AntoinePierre-Antoine

      5,7794 gold badges19 silver badges31 bronze badges




      5,7794 gold badges19 silver badges31 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Set label_names=None and allow_missing=True. That should get rid of the warning.



          model = mx.mod.Module(symbol=symbol, context=mx.cpu(), label_names=None)
          ...
          model.set_params(arg_params, aux_params, allow_missing=True)


          If you are curious why the warning is printed in the first place,



          Every module has associated label. When this model was trained, softmax_label was used as the label (most likely because the output layer was a softmax layer named 'softmax'). When the model was loaded from file, the module that was created had softmax_label as the module's label.



          >>>print(model.label_names)
          ['softmax_label']


          model.bind is then called without providing label_shapes.



          model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)


          MXNet sees that the module has a label in it which was not provided during bind and complains about it - which is the warning message you see.



          I think if bind is called with for_training=False, MXNet shouldn't complain about the missing label. I've created this issue: https://github.com/dmlc/mxnet/issues/6958



          However, for this particular case where we load a model from disk, we can load it with None as the label so that MXNet doesn't later complain when bind doesn't provide label - which is what the suggested fix does.






          share|improve this answer

























          • Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

            – Pierre-Antoine
            Jul 7 '17 at 10:26












          • Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

            – Indhu Bharathi
            Jul 7 '17 at 18:31











          • Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

            – Pierre-Antoine
            Jul 10 '17 at 10:18










          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',
          autoActivateHeartbeat: false,
          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%2f44947104%2fmxnet-label-shapes-dont-match-names-specified-by-label-names%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Set label_names=None and allow_missing=True. That should get rid of the warning.



          model = mx.mod.Module(symbol=symbol, context=mx.cpu(), label_names=None)
          ...
          model.set_params(arg_params, aux_params, allow_missing=True)


          If you are curious why the warning is printed in the first place,



          Every module has associated label. When this model was trained, softmax_label was used as the label (most likely because the output layer was a softmax layer named 'softmax'). When the model was loaded from file, the module that was created had softmax_label as the module's label.



          >>>print(model.label_names)
          ['softmax_label']


          model.bind is then called without providing label_shapes.



          model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)


          MXNet sees that the module has a label in it which was not provided during bind and complains about it - which is the warning message you see.



          I think if bind is called with for_training=False, MXNet shouldn't complain about the missing label. I've created this issue: https://github.com/dmlc/mxnet/issues/6958



          However, for this particular case where we load a model from disk, we can load it with None as the label so that MXNet doesn't later complain when bind doesn't provide label - which is what the suggested fix does.






          share|improve this answer

























          • Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

            – Pierre-Antoine
            Jul 7 '17 at 10:26












          • Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

            – Indhu Bharathi
            Jul 7 '17 at 18:31











          • Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

            – Pierre-Antoine
            Jul 10 '17 at 10:18















          3














          Set label_names=None and allow_missing=True. That should get rid of the warning.



          model = mx.mod.Module(symbol=symbol, context=mx.cpu(), label_names=None)
          ...
          model.set_params(arg_params, aux_params, allow_missing=True)


          If you are curious why the warning is printed in the first place,



          Every module has associated label. When this model was trained, softmax_label was used as the label (most likely because the output layer was a softmax layer named 'softmax'). When the model was loaded from file, the module that was created had softmax_label as the module's label.



          >>>print(model.label_names)
          ['softmax_label']


          model.bind is then called without providing label_shapes.



          model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)


          MXNet sees that the module has a label in it which was not provided during bind and complains about it - which is the warning message you see.



          I think if bind is called with for_training=False, MXNet shouldn't complain about the missing label. I've created this issue: https://github.com/dmlc/mxnet/issues/6958



          However, for this particular case where we load a model from disk, we can load it with None as the label so that MXNet doesn't later complain when bind doesn't provide label - which is what the suggested fix does.






          share|improve this answer

























          • Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

            – Pierre-Antoine
            Jul 7 '17 at 10:26












          • Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

            – Indhu Bharathi
            Jul 7 '17 at 18:31











          • Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

            – Pierre-Antoine
            Jul 10 '17 at 10:18













          3












          3








          3







          Set label_names=None and allow_missing=True. That should get rid of the warning.



          model = mx.mod.Module(symbol=symbol, context=mx.cpu(), label_names=None)
          ...
          model.set_params(arg_params, aux_params, allow_missing=True)


          If you are curious why the warning is printed in the first place,



          Every module has associated label. When this model was trained, softmax_label was used as the label (most likely because the output layer was a softmax layer named 'softmax'). When the model was loaded from file, the module that was created had softmax_label as the module's label.



          >>>print(model.label_names)
          ['softmax_label']


          model.bind is then called without providing label_shapes.



          model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)


          MXNet sees that the module has a label in it which was not provided during bind and complains about it - which is the warning message you see.



          I think if bind is called with for_training=False, MXNet shouldn't complain about the missing label. I've created this issue: https://github.com/dmlc/mxnet/issues/6958



          However, for this particular case where we load a model from disk, we can load it with None as the label so that MXNet doesn't later complain when bind doesn't provide label - which is what the suggested fix does.






          share|improve this answer















          Set label_names=None and allow_missing=True. That should get rid of the warning.



          model = mx.mod.Module(symbol=symbol, context=mx.cpu(), label_names=None)
          ...
          model.set_params(arg_params, aux_params, allow_missing=True)


          If you are curious why the warning is printed in the first place,



          Every module has associated label. When this model was trained, softmax_label was used as the label (most likely because the output layer was a softmax layer named 'softmax'). When the model was loaded from file, the module that was created had softmax_label as the module's label.



          >>>print(model.label_names)
          ['softmax_label']


          model.bind is then called without providing label_shapes.



          model.bind(data_shapes=[('data', (1, 3, 224, 244))], for_training=False)


          MXNet sees that the module has a label in it which was not provided during bind and complains about it - which is the warning message you see.



          I think if bind is called with for_training=False, MXNet shouldn't complain about the missing label. I've created this issue: https://github.com/dmlc/mxnet/issues/6958



          However, for this particular case where we load a model from disk, we can load it with None as the label so that MXNet doesn't later complain when bind doesn't provide label - which is what the suggested fix does.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 8 '17 at 0:31

























          answered Jul 6 '17 at 20:37









          Indhu BharathiIndhu Bharathi

          1,1321 gold badge8 silver badges19 bronze badges




          1,1321 gold badge8 silver badges19 bronze badges












          • Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

            – Pierre-Antoine
            Jul 7 '17 at 10:26












          • Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

            – Indhu Bharathi
            Jul 7 '17 at 18:31











          • Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

            – Pierre-Antoine
            Jul 10 '17 at 10:18

















          • Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

            – Pierre-Antoine
            Jul 7 '17 at 10:26












          • Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

            – Indhu Bharathi
            Jul 7 '17 at 18:31











          • Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

            – Pierre-Antoine
            Jul 10 '17 at 10:18
















          Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

          – Pierre-Antoine
          Jul 7 '17 at 10:26






          Thanks for the help. I did try that. It removes the warning but the script doesn't work anymore. With label_name=None the script now fails with RuntimeError: softmax_label is not presented. It comes from File "/usr/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/module.py", line 264, in _impl raise RuntimeError("%s is not presented" % name) Any idea what is happening? I'm a bit clueless on what those various label parameters are meant for.

          – Pierre-Antoine
          Jul 7 '17 at 10:26














          Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

          – Indhu Bharathi
          Jul 7 '17 at 18:31





          Can you set allow_missing=True for the module? model.set_params(arg_params, aux_params, allow_missing=True)

          – Indhu Bharathi
          Jul 7 '17 at 18:31













          Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

          – Pierre-Antoine
          Jul 10 '17 at 10:18





          Thanks @indhu-bharathi for the answer and the explanation. Also adding allow_missing to true made it work.

          – Pierre-Antoine
          Jul 10 '17 at 10:18






          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44947104%2fmxnet-label-shapes-dont-match-names-specified-by-label-names%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript