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

Cleaned up image classification cpp example #9799

Merged
merged 8 commits into from
Mar 2, 2018

Conversation

lebeg
Copy link
Contributor

@lebeg lebeg commented Feb 15, 2018

Description

Cleaned up image classification cpp example.

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete

Changes

  • Introduced mxnet build option
  • Enabled build on mac
  • Cleaned up cmake file
  • Applied minor code improvements
  • Applied code formatting

Code improvements

  • std::string -> const std::string& as method or function parameters
  • Handling buffer memory with std::unique_ptr<char[]> instead of raw pointer
  • Use std::size_t instead of int for sizes where possible
  • Fixed log phrasing and whitespace formatting
  • Used ostream for logs instead of printf
  • Used standard exit codes from main
  • Added license header

Tested

  • Mac OS
  • Ubuntu
  • Windows

}

~BufferFile() {
if (buffer_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the check is not needed

Copy link
Contributor

Choose a reason for hiding this comment

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

Better a smart pointer in any case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

// LoadSynsets
// Code from : https://github.com/pertusa/mxnet_predict_cc/blob/master/mxnet_predict.cc
std::vector<std::string> LoadSynset(std::string synset_file) {
std::ifstream fi(synset_file.c_str());
std::vector <std::string> LoadSynset(std::string synset_file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why space before template arg?


std::vector<std::string> output;
std::vector <std::string> output;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this your IDE settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this was a weird default setting on a new machine

@piiswrong
Copy link
Contributor

Those keys are release signing keys. If you are not going to drive a release you don't need it

@@ -671,8 +672,7 @@ if(USE_CPP_PACKAGE)
add_subdirectory(cpp-package)
endif()

# Problems on Mac OS X: 1. librt not available 2. mxnet built as MODULE library, which can't be linked.
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

KEYS Outdated
@@ -480,3 +480,40 @@ IxR3jVTKye+UerEtN8yATW8CRIKO3IobUfLMDdPCLO7uzoW95cI35Y0l8JgK2NeU
=E4W5
-----END PGP PUBLIC KEY BLOCK-----

pub rsa2048 2018-02-07 [SC] [expires: 2020-02-07]
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're not going to make a release, I don't think that your key should be in here.

@marcoabreu
Copy link
Contributor

Could you please add on which platforms you have tested your modifications? Since we're not testing examples on CI, we'll have to test them ourselves.

Copy link
Contributor Author

@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.

Alright, thanks for letting me know

@@ -671,8 +672,7 @@ if(USE_CPP_PACKAGE)
add_subdirectory(cpp-package)
endif()

# Problems on Mac OS X: 1. librt not available 2. mxnet built as MODULE library, which can't be linked.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@lebeg
Copy link
Contributor Author

lebeg commented Feb 16, 2018

Listed tested platforms in the description

@marcoabreu
Copy link
Contributor

Could you please also test Windows?

@lebeg
Copy link
Contributor Author

lebeg commented Feb 19, 2018

Added windows to tested platforms

# ---[ OpenCV
if(NOT USE_OPENCV OR NOT OpenCV_FOUND)
message(WARNING "\
OpenCV should be enabled and found to build image classification example, skipping...")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a critical error, right?

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 example will just not be build and it will not break the whole project configuration.

Copy link
Member

Choose a reason for hiding this comment

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

This certainly is chopping out a lot of stuff. WHat's the net change in static linking logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not about static, it's an early return from this cmake file. The example can not be built if there is no OpenCV and will not be added to the main project. That's it.

Copy link
Member

Choose a reason for hiding this comment

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

isn’t the unittest static link flag removed?

Copy link
Member

Choose a reason for hiding this comment

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

UNITTEST_STATIC_LINK is descriptive and editable. Changing the check to MSVC at the actual interpretation point makes it difficult to see what's being done.
Also, I think MSVC has to build static because of dllimport issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can leave the variable itself but would rename it, because it's an example, not a unit test.

@lebeg
Copy link
Contributor Author

lebeg commented Feb 26, 2018

@marcoabreu @piiswrong @cjolivier01 @szha do you want to take another look and merge if possible?

@marcoabreu
Copy link
Contributor

I can't really help here, sorry.

CMakeLists.txt Outdated
@@ -32,6 +32,7 @@ mxnet_option(USE_GPROF "Compile with gprof (profiling) flag" OFF)
mxnet_option(USE_CXX14_IF_AVAILABLE "Build with C++14 if the compiler supports it" OFF)
mxnet_option(USE_VTUNE "Enable use of Intel Amplifier XE (VTune)" OFF) # one could set VTUNE_ROOT for search path
mxnet_option(ENABLE_CUDA_RTC "Build with CUDA runtime compilation support" ON)
mxnet_option(BUILD_CPP_EXAMPLES "Build cpp examples" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

default to on, please. Otherwise, people may check in/merge broken code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

# ---[ OpenCV
if(NOT USE_OPENCV OR NOT OpenCV_FOUND)
message(WARNING "\
OpenCV should be enabled and found to build image classification example, skipping...")
Copy link
Member

Choose a reason for hiding this comment

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

This certainly is chopping out a lot of stuff. WHat's the net change in static linking logic?

/*!
* Copyright (c) 2015 by Xiao Liu, pertusa, caprice-j
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can do this, can you? I was under the impression that license text could never be removed.
@smarthi , this this ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically I'm not removing contributors, just naming them as a group. I followed the pattern in the rest of the project, but will be happy to change it back.

Copy link
Member

Choose a reason for hiding this comment

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

is the guy’s name still there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, brought it back


const mx_float DEFAULT_MEAN = 117.0;

std::string trim(const std::string& input) {
Copy link
Member

Choose a reason for hiding this comment

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

make static, please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@cjolivier01
Copy link
Member

Can you please summarize the "cleaning up" items in the description? It's a little hard to follow what the added value is from the diff, since it's a bit scattered.

@lebeg
Copy link
Contributor Author

lebeg commented Feb 27, 2018

@cjolivier01 The changes are already listed:

Changes

  • Introduced mxnet build option
  • Enabled build on mac
  • Cleaned up cmake file
  • Applied minor code improvements
  • Applied code formatting

@lebeg
Copy link
Contributor Author

lebeg commented Feb 27, 2018

@cjolivier01 please take another look, thanks!

@cjolivier01
Copy link
Member

Can you please summarize the "cleaning up" items in the description? It's a little hard to follow what the added value is from the diff, since it's a bit scattered.

@cjolivier01
Copy link
Member

Also, is this used in any of the unit tests or nightly tests? If not, probably we should be running at least one test with it.

# ---[ OpenCV
if(NOT USE_OPENCV OR NOT OpenCV_FOUND)
message(WARNING "\
OpenCV should be enabled and found to build image classification example, skipping...")
Copy link
Member

Choose a reason for hiding this comment

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

UNITTEST_STATIC_LINK is descriptive and editable. Changing the check to MSVC at the actual interpretation point makes it difficult to see what's being done.
Also, I think MSVC has to build static because of dllimport issues

@lebeg
Copy link
Contributor Author

lebeg commented Mar 1, 2018

@cjolivier01 for now this is not tested on ci, but I will ingerate this as the base for valgrind memcheck tests

@lebeg
Copy link
Contributor Author

lebeg commented Mar 1, 2018

Added 'Code improvements' section for detailisation

@marcoabreu marcoabreu merged commit 9757091 into apache:master Mar 2, 2018
jinhuang415 pushed a commit to jinhuang415/incubator-mxnet that referenced this pull request Mar 30, 2018
* Cleaned up cpp image classification example

* Added gpg key

* Revert "Added gpg key"

This reverts commit d5c29d7.

* Adressed review comments, made other small improvements

* Reverted default device type to cpu

* Minor type change

* Applied review comments

* Brought back the static linking option
@lebeg lebeg deleted the cpp-example branch April 16, 2018 15:22
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* Cleaned up cpp image classification example

* Added gpg key

* Revert "Added gpg key"

This reverts commit d5c29d7.

* Adressed review comments, made other small improvements

* Reverted default device type to cpu

* Minor type change

* Applied review comments

* Brought back the static linking option
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* Cleaned up cpp image classification example

* Added gpg key

* Revert "Added gpg key"

This reverts commit d5c29d7.

* Adressed review comments, made other small improvements

* Reverted default device type to cpu

* Minor type change

* Applied review comments

* Brought back the static linking option
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.

5 participants