Skip to content

[GSoC] Added TF and PyTorch classification conversion cases#17604

Merged
alalek merged 8 commits intoopencv:masterfrom
LupusSanctus:am/pytorch_tf_cls_tutorial
Jan 26, 2021
Merged

[GSoC] Added TF and PyTorch classification conversion cases#17604
alalek merged 8 commits intoopencv:masterfrom
LupusSanctus:am/pytorch_tf_cls_tutorial

Conversation

@LupusSanctus
Copy link
Copy Markdown

@LupusSanctus LupusSanctus commented Jun 21, 2020

GSoC project: "Write a tutorial about training a network in TF or PyTorch and then running it in OpenCV"

Part 1. Classification case.

  • Provided dnn_model_runner module with the below-listed functions:
  1. evaluation mode: a full pipeline for the evaluation of PyTorch and TF models (conversion, OpenCV Net retrievement, data fetch and preparation, evaluation)
  2. test mode: integrated with samples/dnn/classification.py for inference execution
  3. includes autonomous scripts with step by step TF/PyTorch models => OpenCV Net conversion and inference (described in tutorials)
  • Provided tutorial series

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 OpenCV (BSD) License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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

@LupusSanctus LupusSanctus force-pushed the am/pytorch_tf_cls_tutorial branch from dfd9c89 to a772769 Compare July 10, 2020 13:25
@LupusSanctus LupusSanctus force-pushed the am/pytorch_tf_cls_tutorial branch from a772769 to 7e6cb9c Compare July 31, 2020 12:57
@LupusSanctus LupusSanctus force-pushed the am/pytorch_tf_cls_tutorial branch from 7e6cb9c to 3907135 Compare August 30, 2020 20:03
@LupusSanctus LupusSanctus changed the title WIP: Added TF and PyTorch classification conversion cases WIP: [GSoC] Added TF and PyTorch classification conversion cases Aug 31, 2020
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Need to clarify licensing terms of used images.

@LupusSanctus LupusSanctus force-pushed the am/pytorch_tf_cls_tutorial branch 6 times, most recently from e93ee9d to b4e36ea Compare November 24, 2020 10:22
@asmorkalov
Copy link
Copy Markdown
Contributor

There is conflict in requirements.txt. Pip reports:

ERROR: Double requirement given: torch>=1.7.0.dev20200727 (from -r ./requirements.txt (line 15)) (already in torch>=1.5.1 (from -r ./requirements.txt (line 5)), name='torch')

@asmorkalov
Copy link
Copy Markdown
Contributor

Please add bock with setup instructions. Let's expect that user already have python3 and pip installed.

@asmorkalov
Copy link
Copy Markdown
Contributor

@LupusSanctus Sorry for confusion, please ignore the requirements.txt issue. I used old version of the code. Please remove OpenCV package from requirements.txt and add line to tutorial or just leave OpenCV without version. 4.5.x is not available with pip now.

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 4, 2020

Please rebase commits to resolve merge conflicts.

@LupusSanctus LupusSanctus force-pushed the am/pytorch_tf_cls_tutorial branch from b4e36ea to 968723b Compare December 10, 2020 22:30
@LupusSanctus
Copy link
Copy Markdown
Author

LupusSanctus commented Dec 10, 2020

@asmorkalov, setup instructions were added in tutorial's Requirements section. Also requirements.txt was corrected.

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 18, 2020

Is this PR in WIP status?

@LupusSanctus LupusSanctus changed the title WIP: [GSoC] Added TF and PyTorch classification conversion cases [GSoC] Added TF and PyTorch classification conversion cases Dec 18, 2020
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Well done!

Please take a look on minor comments below.


def get_args_parser(func_args):
backends = (cv.dnn.DNN_BACKEND_DEFAULT, cv.dnn.DNN_BACKEND_HALIDE, cv.dnn.DNN_BACKEND_INFERENCE_ENGINE,
cv.dnn.DNN_BACKEND_OPENCV)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CuDNN?

img = img.astype(np.float32)
img *= BASE_IMG_SCALE_FACTOR
img -= [0.485, 0.456, 0.406]
img /= [0.229, 0.224, 0.225]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same values are in default_preprocess_config.py. Let's reuse the constants.

@asmorkalov
Copy link
Copy Markdown
Contributor

@LupusSanctus Friendly reminder.

@LupusSanctus LupusSanctus force-pushed the am/pytorch_tf_cls_tutorial branch from 968723b to 1cb5054 Compare January 25, 2021 10:52
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Well done! Thank you 👍

@alalek alalek merged commit 8c22198 into opencv:master Jan 26, 2021
@alalek alalek mentioned this pull request Apr 9, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…utorial

[GSoC] Added TF and PyTorch classification conversion cases

* Added TF and PyTorch classification conversion cases

* Modified structure, some processing scripts. Added evaluation pipeline

* Minor structure change

* Removed extra functions, minor structure change

* Modified structure, code corrections

* Updated classification code block, added classification tutorials

* Added minor modifications of paths

* Classification block corrections in accordance with comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants