Skip to content

Improved classification sample#25519

Merged
asmorkalov merged 33 commits intoopencv:5.xfrom
gursimarsingh:improved_classification_sample
Aug 6, 2024
Merged

Improved classification sample#25519
asmorkalov merged 33 commits intoopencv:5.xfrom
gursimarsingh:improved_classification_sample

Conversation

@gursimarsingh
Copy link
Copy Markdown
Contributor

#25006 #25314

This pull requests replaces the caffe model for classification with onnx versions. It also adds resnet in model.yml.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@gursimarsingh gursimarsingh self-assigned this May 1, 2024
@gursimarsingh gursimarsingh added category: samples cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) OpenCV5 labels May 1, 2024
@gursimarsingh gursimarsingh added this to the 5.0 milestone May 1, 2024
@gursimarsingh gursimarsingh requested a review from asmorkalov June 10, 2024 08:56
@vpisarev
Copy link
Copy Markdown
Contributor

vpisarev commented Jun 27, 2024

@gursimarsingh, I found it's almost impossible to run the sample.

  1. If I build OpenCV from source and don't run "sudo make install" (which is not recommended anyway), I must set PYTHONPATH pointing to the directory containing cv2.cpython.*.so. It must be described somewhere, otherwise download_models.py cannot be run.
  2. download_models.py does not report information where it's downloading models.
  3. download_models.py tries to download some models repeatedly, e.g. resnet50. Please, make sure that all hash sums are proper and properly computed. Run download_models.py twice and make sure that once some model was downloaded, it's not downloaded again.
  4. How do I specify where my models are stored? I tried to specify OPENCV_DNN_TEST_DATA_PATH, but it still cannot find resnet or squeezenet.
  5. I guess, the samples in 5.x should use the new API to output text. Here is how to do it:
    TEST(Drawing, ttf_text)
  6. Can you double-check that the normalization parameters used for various models are still valid? I was under impression that many image classification models from ONNX model zoo use pretty much the same parameters, mostly defined by the dataset (ImageNet).
  7. Could you add MobileNet and EfficientNet into models.yml?
  8. Could you add option to just reference some entry in models.yml to specify preprocessing? Say, I cannot make the sample to locate resnet properly. Or I want different kind of Resnet (resnet18 or resnet101). Ok, I downloaded resnet by myself and specify explicit path to it. But I don't want to enter all preprocessing parameters manually. This flag could be called "-p" or "--preproc", e.g.
./example_dnn_classification -m <path_to_my_own_resnet> -p resnet -i lena.jpg

@vpisarev
Copy link
Copy Markdown
Contributor

vpisarev commented Jul 4, 2024

some more comments:

  1. 'about' message is not printed, whenever I run classification sample without any parameters or with '-h'.
  2. I managed to run example by manually specifying path to the downloaded model and the labels and after copying models.yml to the bin directory. I suggest to use a single environment variable to specify OpenCV source root. From this we can automatically find models.yml, the labels and even downloaded models, if they are properly downloaded.
  3. If I don't specify path to the labels explicitly, the error message tells me to download opencv_extra. This is not good. In order to run samples, users should not download opencv_extra. The labels are already inside opencv/samples/data/dnn.
  4. the old putText API is still used to print the labels. Please, use the new API where real truetype fonts are used.
  5. '--model' parameter is not described.

@gursimarsingh
Copy link
Copy Markdown
Contributor Author

@vpisarev

  1. about is now also printed in case alias is missing
  2. I propose changing the download_models.py to download the models at a path appended to OPENCV_SOURCE_ROOT environment variable and use that to find the model. At what point should this environment variable needs to be set for the user?
  3. OPENCV_SOURCE_ROOT/samples/data/dnn can be added in the search directory in common.hpp
  4. I have added the Fontface and rearranged the arguments to use the new API
  5. --model paramter is added by:
keys += genPreprocArguments(modelName, zooFile);
parser = CommandLineParser(argc, argv, keys);

It is described if alias is provided. Example: ./bin/example_dnn_classification resnet -h

@vpisarev
Copy link
Copy Markdown
Contributor

  1. In description the text still mentions 'OPENCV_DNN_TEST_DATA_PATH', not 'OPENCV_SAMPLES_DATA_PATH'.
  2. I don't see any information about 'classes' parameter when I run sample without parameters or with '-h'.
  3. When models.yml cannot be located, a proper message is printed without throwing CV_Error(). Good!
  4. When OPENCV_SAMPLES_DATA_PATH is set, models.yml seems to be located properly, but the file with labels still cannot be located. And in this case CV_Error() is thrown without any clear diagnostics. Why is that?

@vpisarev
Copy link
Copy Markdown
Contributor

@asmorkalov, please, merge it. We need to move forward with sample refactoring

@asmorkalov
Copy link
Copy Markdown
Contributor

/build/precommit_docs/5.x/opencv/doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown:63: warning: block marked with [Get a class with a highest score] for \snippet should appear twice in file dnn/classification.cpp, found it 1 times

@asmorkalov asmorkalov assigned vpisarev and unassigned gursimarsingh Aug 6, 2024
@asmorkalov asmorkalov merged commit 35eba9c into opencv:5.x Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: samples cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) OpenCV5

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants