You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/08/14 19:41:06 UTC

[GitHub] azai91 opened a new pull request #12166: Module predict API can accept NDArray as input

azai91 opened a new pull request #12166: Module predict API can accept NDArray as input
URL: https://github.com/apache/incubator-mxnet/pull/12166
 
 
   ## Description ##
   Currently the module API can only accept DataIter as an input type. However, for developers who wish to quickly try out the module api (build a sym and then bind to a module), the predict API is one of the quickest ways to check if their network produces valid outputs. The developer may not want to learn to use the DataIter API and it is intuitive for the developer to think they can pass an NDArray or np.array as an input the predict  API. 
   
   Additionally, I added an Exception that will warn developers if they use an incorrect input type (currently they run into a runtime exception if the input type does not have a `.data` method.
   
   ```
   import mxnet as mx
   import numpy as np
   
   # from docs https://mxnet.apache.org/api/python/module/module.html
   data = mx.sym.Variable('data')
   fc1  = mx.sym.FullyConnected(data, name='fc1', num_hidden=128)
   out  = mx.sym.SoftmaxOutput(fc1, name = 'softmax')
   mod = mx.mod.Module(out)
   
   mod.bind(data_shapes=[('data', [10,10])]) # this errors
   mod.init_params()
   
   data = np.random.rand(10,10)
   result = mod.predict(data)
   ```
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
   - Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Module.predict API can accept ndarray / np.array as input
   - [ ] Add exception for invalid input types
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note here
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services