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

[action] add lint check steps in tizen-web workflows #343

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions .github/workflows/tizen-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: -${{ github.event.pull_request.commits }}
- name: Lint check
run: |
pushd Tizen.web
npm i -g eslint
npm i
eslint --config eslint.config.mjs .
popd
- name: Install Tizen Studio
run: |
wget -nc -O ${{ github.workspace }}/installer $TIZEN_STUDIO_URL
Expand Down
264 changes: 138 additions & 126 deletions Tizen.web/ImageClassificationOffloading/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,114 @@
*/

import {
getNetworkType,
getIpAddress,
GetMaxIdx,
GetImgPath,
loadLabelInfo,
} from './utils.js';
getNetworkType,
getIpAddress,
GetMaxIdx,
GetImgPath,
loadLabelInfo,
} from "./utils.js";

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

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

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

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

let localHandle;
let offloadingHandle;

function createPipelineDescription(isLocal, filter) {
return (
'appsrc caps=image/jpeg name=srcx_' + (isLocal ? 'local' : 'offloading') + ' ! jpegdec ! ' +
'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 ! ' + filter + ' ! ' +
'other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1 ! ' +
'tensor_sink name=sinkx_' + (isLocal ? 'local' : 'offloading')
);
return (
"appsrc caps=image/jpeg name=srcx_" +
(isLocal ? "local" : "offloading") +
" ! jpegdec ! " +
"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 ! " +
filter +
" ! " +
"other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1 ! " +
"tensor_sink name=sinkx_" +
(isLocal ? "local" : "offloading")
);
}

/**
* Callback function for pipeline sink listener
*/
function sinkListenerCallback(sinkName, data) {
const endTime = performance.now();
const endTime = performance.now();

const tensorsRetData = data.getTensorRawData(0);
const maxIdx = GetMaxIdx(tensorsRetData.data);
const tensorsRetData = data.getTensorRawData(0);
const maxIdx = GetMaxIdx(tensorsRetData.data);

let type;
if (sinkName.endsWith('local')) {
type = 'local';
}
else {
type = 'offloading';
}
let type;
if (sinkName.endsWith("local")) {
type = "local";
} else {
type = "offloading";
}

const label = document.getElementById('label_' + type);
label.innerText = labels[maxIdx];
const label = document.getElementById("label_" + type);
label.innerText = labels[maxIdx];

const time = document.getElementById('time_' + type);
time.innerText = type + ' : ' + (endTime - startTime) + ' ms';
const time = document.getElementById("time_" + type);
time.innerText = type + " : " + (endTime - startTime) + " ms";
}

/**
* Run a pipeline that uses Tizen device's resources
*/
function runLocal() {
const modelPath = 'wgt-package/res/mobilenet_v1_1.0_224_quant.tflite';
const URI_PREFIX = 'file://';
const absModelPath = tizen.filesystem.toURI(modelPath).substr(URI_PREFIX.length);
const filter = 'tensor_filter framework=tensorflow-lite model=' + absModelPath;

const pipelineDescription = createPipelineDescription(true,filter);

localHandle = tizen.ml.pipeline.createPipeline(pipelineDescription);
localHandle.start();
localHandle.registerSinkListener('sinkx_local', sinkListenerCallback);
const modelPath = "wgt-package/res/mobilenet_v1_1.0_224_quant.tflite";
const URI_PREFIX = "file://";
const absModelPath = tizen.filesystem
.toURI(modelPath)
.substr(URI_PREFIX.length);
const filter =
"tensor_filter framework=tensorflow-lite model=" + absModelPath;

const pipelineDescription = createPipelineDescription(true, filter);

localHandle = tizen.ml.pipeline.createPipeline(pipelineDescription);
localHandle.start();
localHandle.registerSinkListener("sinkx_local", sinkListenerCallback);
}

/**
* Run a pipeline that uses other device's resources
*/
function runOffloading() {
const filter = 'tensor_query_client host=' + ip + ' port=' + document.getElementById('port').value +
' dest-host=' + document.getElementById('ip').value +
' dest-port=' + document.getElementById('port').value +
' timeout=1000';

const pipelineDescription = createPipelineDescription(false,filter);

offloadingHandle = tizen.ml.pipeline.createPipeline(pipelineDescription);
offloadingHandle.start();
offloadingHandle.registerSinkListener('sinkx_offloading', sinkListenerCallback);
const filter =
"tensor_query_client host=" +
ip +
" port=" +
document.getElementById("port").value +
" dest-host=" +
document.getElementById("ip").value +
" dest-port=" +
document.getElementById("port").value +
" timeout=1000";

const pipelineDescription = createPipelineDescription(false, filter);

offloadingHandle = tizen.ml.pipeline.createPipeline(pipelineDescription);
offloadingHandle.start();
offloadingHandle.registerSinkListener(
"sinkx_offloading",
sinkListenerCallback,
);
}

let startTime;
Expand All @@ -108,82 +124,78 @@ let startTime;
* Run a pipeline that uses other device's resources
*/
function inference(isLocal) {
const img_path = GetImgPath();
let img = new Image();
img.src = img_path;
const img_path = GetImgPath();
let img = new Image();
img.src = img_path;

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

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

startTime = performance.now();

if (isLocal) {
localHandle.getSource("srcx_local").inputData(tensorsData);
} else {
offloadingHandle.getSource("srcx_offloading").inputData(tensorsData);
}

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

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

startTime = performance.now();

if (isLocal) {
localHandle.getSource('srcx_local').inputData(tensorsData);
} else {
offloadingHandle.getSource('srcx_offloading').inputData(tensorsData);
}

const canvasName = 'canvas_' + (isLocal ? 'local' : 'offloading');
const canvas = document.getElementById(canvasName);
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
};
const canvasName = "canvas_" + (isLocal ? "local" : "offloading");
const canvas = document.getElementById(canvasName);
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
};
}

let ip;
let labels;

window.onload = async function () {
const networkType = await getNetworkType();
ip = await getIpAddress(networkType);
labels = loadLabelInfo();

document
.getElementById('start_local')
.addEventListener('click', function () {
runLocal();
});

document
.getElementById('start_offloading')
.addEventListener('click', function () {
runOffloading();
});

document
.getElementById('local')
.addEventListener('click', function () {
inference(true);
});

document
.getElementById('offloading')
.addEventListener('click', function () {
inference(false);
});

/* add eventListener for tizenhwkey */
document.addEventListener('tizenhwkey', function (e) {
if (e.keyName === 'back') {
try {
console.log('Pipeline is disposed!!');
localHandle.stop();
localHandle.dispose();

offloadingHandle.stop();
offloadingHandle.dispose();

disposeData();

tizen.application.getCurrentApplication().exit();
} catch (ignore) {}
}
const networkType = await getNetworkType();
ip = await getIpAddress(networkType);
labels = loadLabelInfo();

document.getElementById("start_local").addEventListener("click", function () {
runLocal();
});

document
.getElementById("start_offloading")
.addEventListener("click", function () {
runOffloading();
});

document.getElementById("local").addEventListener("click", function () {
inference(true);
});

document.getElementById("offloading").addEventListener("click", function () {
inference(false);
});

/* add eventListener for tizenhwkey */
document.addEventListener("tizenhwkey", function (e) {
if (e.keyName === "back") {
try {
console.log("Pipeline is disposed!!");
localHandle.stop();
localHandle.dispose();

offloadingHandle.stop();
offloadingHandle.dispose();

disposeData();

tizen.application.getCurrentApplication().exit();
} catch (ignore) {
console.log("error " + ignore);
}
}
});
};
Loading