Skip to content

[Opencv.js doc] Init commit to add image classification example in op…#343

Merged
huningxin merged 5 commits intohuningxin:gsoc_2020_dnnfrom
akineeic:gsoc_2020_dnn
Jul 8, 2020
Merged

[Opencv.js doc] Init commit to add image classification example in op…#343
huningxin merged 5 commits intohuningxin:gsoc_2020_dnnfrom
akineeic:gsoc_2020_dnn

Conversation

@akineeic
Copy link
Copy Markdown
Collaborator

To fix #308

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

@akineeic
Copy link
Copy Markdown
Collaborator Author

Sorry for the late PR. I have divided the whole code into several functions. But I can't access the functions declared in the code editor area, so the functions haven't been put into the code editor yet. I'll try to fix this problem.

Copy link
Copy Markdown
Owner

@huningxin huningxin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I left some comments inline. For the label and image files, what are their license? Are you able to use some existing ones within opencv repo?

@huningxin huningxin added this to the Evaluation #1 milestone Jun 22, 2020
@huningxin
Copy link
Copy Markdown
Owner

Ping @akineeic , are there any updates on this PR after we synced in last week?

@akineeic
Copy link
Copy Markdown
Collaborator Author

Ping @akineeic , are there any updates on this PR after we synced in last week?

I put the function into the code snippet and the example works well now. But I'm still adjust the web page and I'll update soon.

@huningxin
Copy link
Copy Markdown
Owner

@akineeic , is this PR ready for the next review?

@akineeic
Copy link
Copy Markdown
Collaborator Author

@akineeic , is this PR ready for the next review?

Yes, please take a look and try to build the doc to see the web page. I'm still trying to write a json file to show the model information in the web page.

@huningxin
Copy link
Copy Markdown
Owner

I can try your example and let you know my feedback.

@huningxin
Copy link
Copy Markdown
Owner

There is a layout issue when uploading big image.

image

Copy link
Copy Markdown
Owner

@huningxin huningxin left a comment

Choose a reason for hiding this comment

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

Thanks for the update. I've finished my review and left some comments. Please take a look.

@@ -0,0 +1,6 @@
DNN Module application {#tutorial_js_table_of_contents_dnn}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please change the title to "Deep Neural Networks (dnn module)"

- @subpage tutorial_js_table_of_contents_dnn

In this section you
will see several examples of dnn module.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please change to "These tutorials show how to use dnn module in JavaScript"

Goal
----

- learn the basic pipeline of DNN module, like image processing, model import, inference, etc.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please change to "In this tutorial you will learn how to use OpenCV.js dnn module for image classification."

Image Classification example {#tutorial_js_image_classification}
=======================================

Goal
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Introduction

<h2>Image Classification Example</h2>
<p>
This tutorial show you how to write an image classification example with OpenCV.js.<br>
Click <b>Try it</b> button to see the result. You can choose any other image.<br>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

other images

<script id="codeSnippet1" type="text/code-snippet">
loadLables = function(labelsUrl){
document.getElementById('status').innerHTML = 'Loading classification labels';
let request = new XMLHttpRequest();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please use fetch API to implement.

</script>

<script id="codeSnippet1" type="text/code-snippet">
loadLables = function(labelsUrl){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please make this API return the labels instead of setting some global variables.

</script>

<script id="codeSnippet1" type="text/code-snippet">
loadLables = function(labelsUrl){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please also make this function async and use await to get the return values.

modelUrl: modelUrl,
configPath: configPath,
configUrl: configUrl
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please a separate code snippet to host all configurations.

}
loadModel(() => {
runModel();
});
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please use the await to make it easy to read.

I think the main flow should be something like this:

const path = await loadModel(modelInfo);
const labels = await loadLables(labelsUrl);
const input = getBlobFromImage(imageElementId, preprocessInfo);
const net = cv.readNet(path);
net.setInput(input);
const result = net.forward();
const prob = softmax(result)
const classes = getTopClasses(prob, labels, topK)

@akineeic
Copy link
Copy Markdown
Collaborator Author

akineeic commented Jul 3, 2020

Thanks for the update. I've finished my review and left some comments. Please take a look.

Thanks for your review and I modified the code according to your comments. Please take a look again, thanks.

@huningxin
Copy link
Copy Markdown
Owner

Review comments:

  1. change model url to relative path (same as the examples path)
  2. put getNameFromUrl into the code snippet
  3. fix indention
  4. add the model URLs into the json file

@akineeic
Copy link
Copy Markdown
Collaborator Author

akineeic commented Jul 6, 2020

Review comments:

  1. change model url to relative path (same as the examples path)
  2. put getNameFromUrl into the code snippet
  3. fix indention
  4. add the model URLs into the json file

I have modified the code according to your comments and add a json file to store the parameters for models. Please take a look, thanks!

Copy link
Copy Markdown
Owner

@huningxin huningxin left a comment

Choose a reason for hiding this comment

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

Looks good with nits. Please fix that then I'll merge this PR. Thanks much @akineeic !

@huningxin
Copy link
Copy Markdown
Owner

Looks good. I am going to merge this PR. Thanks again.

@huningxin huningxin merged commit 70fff50 into huningxin:gsoc_2020_dnn Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants