Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen/Web] Move dispose function and add timeout #334

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
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
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