Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ Demo - Image Classification (PPResNet) #241

Merged
merged 11 commits into from
Mar 6, 2024

Conversation

ryan1288
Copy link
Contributor

@ryan1288 ryan1288 commented Mar 4, 2024

This PR adds the C++ demo for the Image Classification PPResNet model, as part of a request from #135.

  • demo.cpp: Added to have matching functionality to demo.py. All 1,000 classes included as a string to be parsed.
  • demo.py: Printout was adjusted be cleaner and matches the C++ version.
  • CMakeLists.txt: Created to build with OpenCV 4.9.0 and enforces C++11 standards upon building.
  • README.md: Updated with C++ instructions.

The interface matches other C++ demos within the set of ML models.

The predictions visualizations were adjusted for both C++ and Python demos for clarity.
Before (Python)
image
After (Python & C++)
image
image

Testing

  • Matching Python and C++ demo classifcations
    A number of images were tested with top-k = 20 and all had matching output classes, with one example provided below.
    goldfish
    image
  • Run demo with top-k = 1
cmake -B build -D OPENCV_INSTALLATION_PATH=/path/to/opencv .
cmake --build build
./build/opencv_zoo_image_classification_ppresnet --input=example_input/goldfish.jpg

image

  • Run demo with top-k > 1
cmake -B build -D OPENCV_INSTALLATION_PATH=/path/to/opencv .
cmake --build build
./build/opencv_zoo_image_classification_ppresnet --input=example_input/goldfish.jpg --top_k=5

image

Copy link
Member

Choose a reason for hiding this comment

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

Merge this file with demo.cpp and revert the changes in ppresnet.py. We made a decision long time ago that demo should be portable and convenient as much as possible with less files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! I've reverted the changes to ppresnet.py and merged the labels with demo.cpp. Agree with the portability 😄 .

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 we need example input as it demonstrates nothing and it increase repo size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed example 👍

return 0;
}

string LABELS_IMAGENET_1K = "tench\n"
Copy link
Member

Choose a reason for hiding this comment

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

How about using std::vector<std::string>? In this case we do not need to duplicate \n for each class and we do not need to re-load this in loadLabels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fengyuentau That's a great idea. Not sure why I didn't think of that 😅 I've updated it.

@fengyuentau fengyuentau self-assigned this Mar 6, 2024
@fengyuentau fengyuentau added the demo anything related to demo in Python / C++ label Mar 6, 2024
@fengyuentau fengyuentau added this to the 4.10.0 milestone Mar 6, 2024
Copy link
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! 👍

@fengyuentau fengyuentau merged commit 6929d47 into opencv:main Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo anything related to demo in Python / C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants