Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-1083] Add the example to demonstrate the inference workflow using C++ API #13294

Merged
merged 6 commits into from
Dec 15, 2018

Conversation

leleamol
Copy link
Contributor

Description

The PR includes an example that demonstrates the inference workflow using C++ API.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • [y] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue 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

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)
    The example demonstrates how to load the pre-trained model and associated parameter files.
    The model and parameter files can be specified as command line arguments.

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@leleamol
Copy link
Contributor Author

@nswamy addressed the latest review comments

  1. Loading the mean image only once.
  2. Remove the image_data instance variable.

cpp-package/example/inference/Makefile Outdated Show resolved Hide resolved
cpp-package/example/inference/Makefile Outdated Show resolved Hide resolved
cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
int num_unit = strtol(hidden_units_string.c_str(), &pNext, 10);
dimensions.push_back(num_unit);
while (*pNext) {
num_unit = strtol(pNext, &pNext, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::stringstream with >> operators could be much more readable and safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a little more?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::istringstream stream(hidden_units_string);
std::vector<index_t> dimensions;
int num_unit;
while (stream >> num_unit) {
  dimensions.push_back(num_unit);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lebeg The "strtol method" was recommended by @larroy in my last PR, hence I am using is to keep it consistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larroy which method would you suggest?

@kalyc
Copy link
Contributor

kalyc commented Nov 16, 2018

@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Nov 16, 2018
else
echo "FAIL: inception_inference FAILED to identify the image."
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can put all the training and inference unit tests under the unittest folder? and why not use C++ testing framework such as Catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch is 👍 but gtest is already available in MXNet as a subrepo, so it might be considered as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples are written so that they won't have external dependency. However, will definitely consider gtest for unit tests.

@stu1130
Copy link
Contributor

stu1130 commented Nov 20, 2018

@mxnet-label-bot update [pr-awaiting-response]

@marcoabreu marcoabreu added pr-awaiting-response PR is reviewed and waiting for contributor to respond and removed pr-awaiting-review PR is waiting for code review labels Nov 20, 2018
@vandanavk
Copy link
Contributor

Could you add information about this example in the README file cpp-package/example/README.md

@leleamol
Copy link
Contributor Author

@vandanavk Added the ReadMe file for example.

@leleamol
Copy link
Contributor Author

@sandeep-krishnamurthy

cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
int num_unit = strtol(hidden_units_string.c_str(), &pNext, 10);
dimensions.push_back(num_unit);
while (*pNext) {
num_unit = strtol(pNext, &pNext, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larroy which method would you suggest?

cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
@leleamol
Copy link
Contributor Author

@mxnet-jenkins The recent CI failure doesn't seem to be related to my changes. Can we re trigger the build?

@lebeg
Copy link
Contributor

lebeg commented Nov 30, 2018

Job timed out due to dockerhub failure. Restarted (even if I'm not @mxnet-jenkins).

@leleamol
Copy link
Contributor Author

leleamol commented Dec 3, 2018

Can this PR be merged? I have addressed the review comments. The example is working as expected and demonstrates the usage of C++ API in running inference workflow.

@lupesko
Copy link
Contributor

lupesko commented Dec 4, 2018

@mxnet-label-bot update [pr-awaiting-review]
@sandeep-krishnamurthy @nswamy @anirudh2290 - can you guys review/merge please?

@marcoabreu marcoabreu added pr-awaiting-review PR is waiting for code review and removed pr-awaiting-response PR is reviewed and waiting for contributor to respond labels Dec 4, 2018
Copy link
Contributor

@larroy larroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@sandeep-krishnamurthy sandeep-krishnamurthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Amol.

cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
cpp-package/example/README.md Show resolved Hide resolved
cpp-package/example/README.md Show resolved Hide resolved
cpp-package/example/README.md Show resolved Hide resolved
cpp-package/example/inference/README.md Show resolved Hide resolved
cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
cpp-package/example/inference/inception_inference.cpp Outdated Show resolved Hide resolved
@leleamol
Copy link
Contributor Author

I have addressed all the review comments. Can this be merged? Since the purpose of this example is to show the inference workflow, I would like to keep the example simple.

Copy link
Contributor

@sandeep-krishnamurthy sandeep-krishnamurthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@lebeg @stu1130 - This is good to go if your comments are addressed.

Copy link
Contributor

@lebeg lebeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@leleamol
Copy link
Contributor Author

Thanks @sandeep-krishnamurthy @lebeg ,

can you please merge the PR?

@leleamol
Copy link
Contributor Author

leleamol commented Dec 14, 2018

@mxnet-label-bot update [pr-awaiting-merge]

@marcoabreu marcoabreu added pr-awaiting-merge Review and CI is complete. Ready to Merge and removed pr-awaiting-review PR is waiting for code review labels Dec 14, 2018
@sandeep-krishnamurthy sandeep-krishnamurthy merged commit ed2cb76 into apache:master Dec 15, 2018
mseth10 pushed a commit to mseth10/incubator-mxnet that referenced this pull request Dec 18, 2018
…ing C++ API (apache#13294)

* [MXNET-1083] Add the example to demonstrate the inference workflow using C++ API

* [MXNET-1083] Add the example to demonstrate the inference workflow using C++ API

* Updated the code to address the review comments.

* Added the README file for the folder.

* Addressed the review comments

* Addressed the review comments to use argmax and default mean values.
@leleamol leleamol deleted the inception-example branch December 19, 2018 00:34
@leleamol
Copy link
Contributor Author

@mxnet-label-bot remove [pr-awaiting-merge]

@marcoabreu marcoabreu removed the pr-awaiting-merge Review and CI is complete. Ready to Merge label Jun 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants