Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Add the OpenVINO.js framework #1383

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/image_classification/ImageClassificationExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ImageClassificationExample extends BaseCameraExample {
case 'OpenCV.js':
runner = new ImageClassificationOpenCVRunner();
break;
case 'OpenVINO.js':
runner = new ImageClassificationOpenVINORunner();
Copy link
Contributor

Choose a reason for hiding this comment

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

@lionkunonly Here missed a 'break'.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
runner.setProgressHandler(updateLoadingProgressComponent);
return runner;
Expand All @@ -28,6 +30,7 @@ class ImageClassificationExample extends BaseCameraExample {
/** @override */
_processExtra = (output) => {
let labelClasses;
console.log(output);
Copy link
Contributor

Choose a reason for hiding this comment

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

@lionkunonly Please remove this console.log line, thanks.

Copy link
Author

Choose a reason for hiding this comment

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

Done

switch (this._currentFramework) {
case 'WebNN':
const deQuantizeParams = this._runner.getDeQuantizeParams();
Expand All @@ -36,6 +39,8 @@ class ImageClassificationExample extends BaseCameraExample {
case 'OpenCV.js':
labelClasses = getTopClasses(output.tensor, output.labels, 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

@lionkunonly The case 'OpenVINO.js' uses the same code as case 'OpenCV.js', you could code as

      case 'OpenCV.js':
      case 'OpenVINO.js':

Copy link
Author

Choose a reason for hiding this comment

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

Done

break;
case 'OpenVINO.js':
labelClasses = getTopClasses(output.tensor, output.labels, 3);
}
$('#inferenceresult').show();
labelClasses.forEach((c, i) => {
Expand Down
17 changes: 17 additions & 0 deletions examples/image_classification/ImageClassificationOpenVINORunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ImageClassificationOpenVINORunner extends OpenVINORunner {
constructor() {
super();
}

/** @override */
_getOutputTensor = () => {
const postSoftmax = this._postOptions.softmax || false;
let outputTensor;
if(postSoftmax) {
outputTensor = softmax(this._output);
} else {
outputTensor = this._output;
}
return outputTensor;
};
}
11 changes: 11 additions & 0 deletions examples/image_classification/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ <h5 class="modal-title" id="modaltitle">Subgraphs Summary</h5>
</div>
</div>

<script>
try {
window.nodeRequire = require;
delete window.exports;
delete window.module;
} catch(e) {
console.log("Node module is not supported");
}
</script>
<script src='../static/lib/jquery/jquery.min.js'></script>
<script src='../static/lib/jquery/jquery-migrate-3.0.1.min.js'></script>
<script src='../static/lib/superfish/superfish.min.js'></script>
Expand All @@ -390,6 +399,7 @@ <h5 class="modal-title" id="modaltitle">Subgraphs Summary</h5>
<script src='../util/BaseRunner.js'></script>
<script src='../util/WebNNRunner.js'></script>
<script src='../util/OpenCVRunner.js'></script>
<script src='../util/OpenVINORunner.js'></script>
<script src='../util/BaseApp.js'></script>
<script src='../util/BaseExample.js'></script>
<script src='../util/BaseCameraExample.js'></script>
Expand All @@ -408,6 +418,7 @@ <h5 class="modal-title" id="modaltitle">Subgraphs Summary</h5>
<script src='../util/caffe2/Caffe2ModelUtils.js'></script>
<script src='../util/caffe2/Caffe2ModelImporter.js'></script>
<script src='ImageClassificationOpenCVRunner.js'></script>
<script src='ImageClassificationOpenVINORunner.js'></script>
<script src='ImageClassificationExample.js'></script>
<script src='main.js'></script>

Expand Down
6 changes: 6 additions & 0 deletions examples/image_classification/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const example = new ImageClassificationExample({model: imageClassificationModels});

let specialoffer = () => {
//http://localhost:8080/examples/image_classification_opencv/?prefer=none&b=WASM&m=resnet50_v1_openvino&s=image&d=0&f=WebNN
let f = parseSearchParams('f')
let url = location.href.replace('image_classification/', 'image_classification_opencv/')
let urlimg = url.replace('s=camera', 's=image')
Expand All @@ -27,6 +28,11 @@ $(document).ready(() => {
$('#frameworkWebNN').click(function() {
$('#opencvspecial').hide()
})

$('#frameworkOpenVINOjs').click(function() {
$('#opencvspecial').hide()
})

});

$(window).load(() => {
Expand Down
9 changes: 9 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,15 @@ <h3>
</svg>
</a>

<script>
try {
window.nodeRequire = require;
delete window.exports;
delete window.module;
} catch(e) {
console.log("Node module is not supported");
}
</script>
<script src='static/lib/jquery/jquery.min.js'></script>
<script src='static/lib/jquery/jquery-migrate-3.0.1.min.js'></script>
<script src='static/lib/superfish/superfish.min.js'></script>
Expand Down
3 changes: 3 additions & 0 deletions examples/semantic_segmentation/SemanticSegmentationExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class SemanticSegmentationExample extends BaseCameraExample {
case 'OpenCV.js':
runner = new SemanticSegmentationOpenCVRunner();
break;
case 'OpenVINO.js':
runner = new SemanticSegmentationOpenVINORunner();
break;
}
runner.setProgressHandler(updateLoadingProgressComponent);
return runner;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class SemanticSegmentationOpenVINORunner extends OpenVINORunner {
constructor() {
super();
}

/** @override */
_getOutputTensorTypedArray = () => {
return Int32Array;
};

/** @override */
_getOutputTensor = () => {
let outputTensor = this._output;
return outputTensor;
};

}
11 changes: 11 additions & 0 deletions examples/semantic_segmentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
</div>
</div>

<script>
try {
window.nodeRequire = require;
delete window.exports;
delete window.module;
} catch(e) {
console.log("Node module is not supported");
}
</script>
<script src='../static/lib/jquery/jquery.min.js'></script>
<script src='../static/lib/jquery/jquery-migrate-3.0.1.min.js'></script>
<script src='../static/lib/superfish/superfish.min.js'></script>
Expand All @@ -411,6 +420,7 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
<script src='../util/BaseRunner.js'></script>
<script src='../util/WebNNRunner.js'></script>
<script src='../util/OpenCVRunner.js'></script>
<script src='../util/OpenVINORunner.js'></script>
<script src='../util/BaseApp.js'></script>
<script src='../util/BaseExample.js'></script>
<script src='../util/BaseCameraExample.js'></script>
Expand All @@ -436,6 +446,7 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
<script src='SemanticSegmentationRunner.js'></script>
<script src='SemanticSegmentationExample.js'></script>
<script src='SemanticSegmentationOpenCVRunner.js'></script>
<script src='SemanticSegmentationOpenVINORunner.js'></script>
<script src='main.js'></script>


Expand Down
9 changes: 8 additions & 1 deletion examples/speech_commands/SpeechCommandsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ class SpeechCommandsExample extends BaseMircophoneExample {

/** @override */
_createRunner = () => {
const runner = new WebNNRunner();
let runner;
switch (this._currentFramework) {
case 'WebNN':
runner = new WebNNRunner();
break;
case 'OpenVINO.js':
runner = new OpenVINORunner();
Copy link
Contributor

Choose a reason for hiding this comment

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

@lionkunonly Here missed a 'break'

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
runner.setProgressHandler(updateLoadingProgressComponent);
return runner;
};
Expand Down
11 changes: 11 additions & 0 deletions examples/speech_commands/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,16 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
</div>
</div>
</div>

<script>
try {
window.nodeRequire = require;
delete window.exports;
delete window.module;
} catch(e) {
console.log("Node module is not supported");
}
</script>
<script src='../static/lib/jquery/jquery.min.js'></script>
<script src='../static/lib/jquery/jquery-migrate-3.0.1.min.js'></script>
<script src='../static/lib/superfish/superfish.min.js'></script>
Expand All @@ -420,6 +430,7 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
<script src='../util/modelZoo.js'></script>
<script src='../util/BaseRunner.js'></script>
<script src='../util/WebNNRunner.js'></script>
<script src='../util/OpenVINORunner.js'></script>
<script src='../util/BaseApp.js'></script>
<script src='../util/BaseExample.js'></script>
<script src='../util/BaseMircophoneExample.js'></script>
Expand Down
9 changes: 8 additions & 1 deletion examples/speech_recognition/SpeechRecognitionExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class SpeechRecognitionExample extends BaseMircophoneExample {

/** @override */
_createRunner = () => {
const runner = new SpeechRecognitionRunner();
let runner;
switch (this._currentFramework) {
case 'WebNN':
runner = new SpeechRecognitionRunner();
break;
case 'OpenVINO.js':
runner = new SpeechRecognitionOpenVINORunner();
Copy link
Contributor

Choose a reason for hiding this comment

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

@lionkunonly ditto.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
runner.setProgressHandler(updateLoadingProgressComponent);
return runner;
};
Expand Down
22 changes: 22 additions & 0 deletions examples/speech_recognition/SpeechRecognitionOpenVINORunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class SpeechRecognitionOpenVINORunner extends OpenVINORunner {
constructor() {
super();
}

_getInputTensor = (input) => {
let infer_req = this._execNet.createInferRequest();
const input_blob = infer_req.getBlob(this._inputInfo.name());
const input_data = new Float32Array(input_blob.wmap());

for(let index = 0; index < input.length; index++) {
input_data[index] = input[index];
}
input_blob.unmap();
this._inferReq = infer_req;
};

_getOutputTensor = () => {
let outputTensor = this._output;
return outputTensor;
};
}
12 changes: 12 additions & 0 deletions examples/speech_recognition/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
</div>
</div>
</div>

<script>
try {
window.nodeRequire = require;
delete window.exports;
delete window.module;
} catch(e) {
console.log("Node module is not supported");
}
</script>
<script src='../static/lib/jquery/jquery.min.js'></script>
<script src='../static/lib/jquery/jquery-migrate-3.0.1.min.js'></script>
<script src='../static/lib/superfish/superfish.min.js'></script>
Expand All @@ -320,6 +330,7 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
<script src='../util/modelZoo.js'></script>
<script src='../util/BaseRunner.js'></script>
<script src='../util/WebNNRunner.js'></script>
<script src='../util/OpenVINORunner.js'></script>
<script src='../util/BaseApp.js'></script>
<script src='../util/BaseExample.js'></script>
<script src='../util/BaseMircophoneExample.js'></script>
Expand All @@ -330,6 +341,7 @@ <h5 class='modal-title' id='modaltitle'>Subgraphs Summary</h5>
<script src='../util/openvino/OpenVINOModelImporter.js'></script>

<script src='SpeechRecognitionRunner.js'></script>
<script src='SpeechRecognitionOpenVINORunner.js'></script>
<script src='SpeechRecognitionExample.js'></script>
<script src='main.js'></script>

Expand Down
2 changes: 1 addition & 1 deletion examples/static/js/ui.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const singleModelTable = (modelList, category) => {
const setModelComponents = (models, selectedModelIdStr) => {
$('.model').remove();
let formatTypes = [];

console.log(models);
for (let [category, modelList] of Object.entries(models)) {
let formats = singleModelTable(modelList, category);
formatTypes.push(...formats);
Expand Down
Loading