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

Select default layout model on different platform #215

Merged
merged 2 commits into from
Apr 3, 2024
Merged
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
15 changes: 15 additions & 0 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,18 @@

return [permutedData, shape];
}

export function getDefaultLayout(deviceType) {
const userAgent = navigator.userAgent;
if (userAgent.indexOf("Linux") != -1 || userAgent.indexOf("Android") != -1 ||

Check failure on line 490 in common/utils.js

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest)

Strings must use singlequote

Check failure on line 490 in common/utils.js

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest)

Strings must use singlequote
userAgent.indexOf("CrOS") != -1) {

Check failure on line 491 in common/utils.js

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest)

Strings must use singlequote
return 'nhwc';
} else {
// Windows or Mac platform.
if (deviceType.indexOf('cpu') != -1) {
return 'nhwc';
} else if (deviceType.indexOf('gpu') != -1) {
return 'nchw'

Check failure on line 498 in common/utils.js

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest)

Missing semicolon
}
}
}
9 changes: 1 addition & 8 deletions face_recognition/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ $(document).ready(async () => {
});

$('#backendBtns .btn').on('change', async (e) => {
if (inputType === 'camera') utils.stopCameraStream(rafReq, stream);
fujunwei marked this conversation as resolved.
Show resolved Hide resolved
if ($(e.target).attr('id').indexOf('cpu') != -1) {
layout = 'nhwc';
} else if (($(e.target).attr('id').indexOf('gpu') != -1)) {
layout = 'nchw';
} else {
throw new Error('Unknown backend');
}
layout = utils.getDefaultLayout($(e.target).attr('id'));
await main();
});

Expand Down
8 changes: 1 addition & 7 deletions facial_landmark_detection/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ $(document).ready(async () => {

$('#backendBtns .btn').on('change', async (e) => {
if (inputType === 'camera') utils.stopCameraStream(rafReq, stream);
if ($(e.target).attr('id').indexOf('cpu') != -1) {
layout = 'nhwc';
} else if (($(e.target).attr('id').indexOf('gpu') != -1)) {
layout = 'nchw';
} else {
throw new Error('Unknown backend');
}
layout = utils.getDefaultLayout($(e.target).attr('id'));
await main();
});

Expand Down
8 changes: 1 addition & 7 deletions image_classification/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ $(document).ready(async () => {

$('#backendBtns .btn').on('change', async (e) => {
if (inputType === 'camera') utils.stopCameraStream(rafReq, stream);
if ($(e.target).attr('id').indexOf('cpu') != -1) {
layout = 'nhwc';
} else if (($(e.target).attr('id').indexOf('gpu') != -1)) {
layout = 'nchw';
} else {
throw new Error('Unknown backend');
}
layout = utils.getDefaultLayout($(e.target).attr('id'));
await main();
});

Expand Down
8 changes: 1 addition & 7 deletions object_detection/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ $(document).ready(async () => {

$('#backendBtns .btn').on('change', async (e) => {
if (inputType === 'camera') utils.stopCameraStream(rafReq, stream);
if ($(e.target).attr('id').indexOf('cpu') != -1) {
layout = 'nhwc';
} else if (($(e.target).attr('id').indexOf('gpu') != -1)) {
layout = 'nchw';
} else {
throw new Error('Unknown backend');
}
layout = utils.getDefaultLayout($(e.target).attr('id'));
await main();
});

Expand Down
8 changes: 1 addition & 7 deletions semantic_segmentation/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ $(window).on('load', () => {

$('#backendBtns .btn').on('change', async (e) => {
if (inputType === 'camera') utils.stopCameraStream(rafReq, stream);
if ($(e.target).attr('id').indexOf('cpu') != -1) {
layout = 'nhwc';
} else if (($(e.target).attr('id').indexOf('gpu') != -1)) {
layout = 'nchw';
} else {
throw new Error('Unknown backend');
}
layout = utils.getDefaultLayout($(e.target).attr('id'));
await main();
});

Expand Down
Loading