[Opencv.js doc] Init commit to add image classification example in op…#343
[Opencv.js doc] Init commit to add image classification example in op…#343huningxin merged 5 commits intohuningxin:gsoc_2020_dnnfrom
Conversation
|
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. |
huningxin
left a comment
There was a problem hiding this comment.
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?
|
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. |
…ns into code snippet.
|
@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. |
|
I can try your example and let you know my feedback. |
huningxin
left a comment
There was a problem hiding this comment.
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} | |||
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
| <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> |
| <script id="codeSnippet1" type="text/code-snippet"> | ||
| loadLables = function(labelsUrl){ | ||
| document.getElementById('status').innerHTML = 'Loading classification labels'; | ||
| let request = new XMLHttpRequest(); |
| </script> | ||
|
|
||
| <script id="codeSnippet1" type="text/code-snippet"> | ||
| loadLables = function(labelsUrl){ |
There was a problem hiding this comment.
Please make this API return the labels instead of setting some global variables.
| </script> | ||
|
|
||
| <script id="codeSnippet1" type="text/code-snippet"> | ||
| loadLables = function(labelsUrl){ |
There was a problem hiding this comment.
Please also make this function async and use await to get the return values.
| modelUrl: modelUrl, | ||
| configPath: configPath, | ||
| configUrl: configUrl | ||
| } |
There was a problem hiding this comment.
Please a separate code snippet to host all configurations.
| } | ||
| loadModel(() => { | ||
| runModel(); | ||
| }); |
There was a problem hiding this comment.
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)
Thanks for your review and I modified the code according to your comments. Please take a look again, thanks. |
|
Review comments:
|
…ow in the web page.
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! |
|
Looks good. I am going to merge this PR. Thanks again. |

To fix #308
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.