Skip to content

Commit

Permalink
[Tizen/Web] Move dispose function and add timeout
Browse files Browse the repository at this point in the history
This patch moves dispose function and adds timeout to fix bug.

Signed-off-by: Yelin Jeong <[email protected]>
  • Loading branch information
niley7464 committed May 16, 2024
1 parent 03f7b17 commit 69ecc60
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Tizen.web/ImageClassificationOffloading/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* @date 30 April 2024
* @brief Image classification Offloading example
* @author Yelin Jeong <[email protected]>
* @bug When pushing data to appsrc for the first time
* after creating a pipeline, the sink listener is not called.
*/

var localSrc;
Expand Down Expand Up @@ -105,7 +103,7 @@ function runRemote() {
'videoconvert ! video/x-raw,format=RGB,framerate=0/1,width=224,height=224 ! tensor_converter ! ' +
'other/tensor,format=static,dimension=(string)3:224:224:1,type=uint8,framerate=0/1 ! ' +
'tensor_query_client host=192.168.50.38 port=' + document.getElementById('port').value + ' dest-host=' + '192.168.50.191' + ' ' +
'dest-port=' + document.getElementById('port').value + ' ! ' +
'dest-port=' + document.getElementById('port').value + ' timeout=1000 ! ' +
'other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1 ! tensor_sink name=sinkx_remote';

const pHandle = tizen.ml.pipeline.createPipeline(pipelineDescription);
Expand All @@ -125,27 +123,42 @@ function runRemote() {
});
}

let fHandle = null;
let tensorsData = null;
let tensorsInfo = null;

function disposeData() {
if (fHandle != null) {
fHandle.close();
}

if (tensorsData != null) {
tensorsData.dispose();
}

if (tensorsInfo != null) {
tensorsInfo.dispose();
}
}

function inference(src, canvas) {
const img_path = GetImgPath();
let img = new Image();
img.src = img_path;

img.onload = function () {
const fHandle = tizen.filesystem.openFile('wgt-package' + img_path, 'r');
disposeData();
fHandle = tizen.filesystem.openFile('wgt-package' + img_path, 'r');
const imgUInt8Array = fHandle.readData();
fHandle.close();

const tensorsInfo = new tizen.ml.TensorsInfo();
tensorsInfo = new tizen.ml.TensorsInfo();
tensorsInfo.addTensorInfo('tensor', 'UINT8', [imgUInt8Array.length]);
const tensorsData = tensorsInfo.getTensorsData();
tensorsData = tensorsInfo.getTensorsData();
tensorsData.setTensorRawData(0, imgUInt8Array);

startTime = performance.now()
src.inputData(tensorsData);

tensorsData.dispose();
tensorsInfo.dispose();

const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
}
Expand Down Expand Up @@ -190,6 +203,8 @@ window.onload = function() {
pHandle.stop();
pHandle.dispose();

disposeData();

tizen.application.getCurrentApplication().exit();
} catch (ignore) {}
}
Expand Down

0 comments on commit 69ecc60

Please sign in to comment.