Skip to content

Commit a31c98f

Browse files
committed
Support electron-packager
1 parent a9094e4 commit a31c98f

File tree

4 files changed

+100
-6
lines changed

4 files changed

+100
-6
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ using bazel and emsdk.
3737
sure Chrome has these two features
3838
[turned on](https://drive.google.com/file/d/13hqGwBOTJFoqMQVUAn_tiYp-uqQN_NUq/view?usp=sharing)
3939
from `chrome://flags`.
40-
- Run `yarn run electron` to start the demo in electron.js. As electron.js has issues to support WebWorker, add the single thread build target `tflite_model_runner_cc_st` and use it when running in electron.js.
40+
- Run `yarn run electron` to start the demo in electron.js.
41+
- Run `yarn run electron-packager` to build an electron.js app of this demo.
4142
5. The WebNN delegate support
4243
- `tensorflow_lite_webnn_delegate.patch`: the WebNN delegate implementation.
4344
- `emscripten_webnn_support.patch`: WebNN support of emscripten.
4445
- `emsdk.patch`: workaround the frozen cache setting of emscripten so WebNN support can be regenerated. As the cache is cleared, the first `yarn build` would fail. Please rerun, it would succeed.
4546
- Add `TFLiteWebModelRunnerOptions.enableWebNNDelegate` to enable or disable WebNN delegate.
4647
- Demo in browser is using webnn-polyfill.
47-
- Demo in electron.js could use WebNN-native node.js binding. Add it via `npm install <path_to_webnn_native_node>`. See [WebNN-native node.js binding](https://github.com/webmachinelearning/webnn-native/tree/main/node) for more details.
48+
- Demo in electron.js could use [WebNN-native node.js binding](https://github.com/webmachinelearning/webnn-native/tree/main/node) for more details.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# TFLite Web API Model Runner Demo
2+
3+
## Use Cases
4+
5+
### 1. MobileNetV2
6+
7+
### 2. ResNet50V2
8+
9+
## Run TFLite Web API Model Runner Demo
10+
11+
### Install Dependencies
12+
13+
```
14+
npm install
15+
```
16+
17+
### Build TFLite Web from source
18+
19+
```
20+
npm run build
21+
```
22+
23+
### Serve the demo
24+
25+
**Serve the demo in localhost**
26+
27+
```
28+
npm run start
29+
```
30+
31+
### Electron support
32+
33+
```
34+
npm run electron
35+
```
36+
37+
This demo can also be packaged as a Linux desktop app using Electron
38+
39+
```
40+
npm run electron-packager
41+
```
42+
43+
This will create a new `/tflite-web-api-model-runner-demo-linux-x64` folder. Run `/tflite-web-api-model-runner-demo-linux-x64/demo-launcher` to enjoy Electron desktop app.
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
# Let the wrapped binary know that it has been run through the wrapper.
8+
export CHROME_WRAPPER="`readlink -f "$0"`"
9+
10+
HERE="`dirname "$CHROME_WRAPPER"`"
11+
12+
# We include some xdg utilities next to the binary, and we want to prefer them
13+
# over the system versions when we know the system versions are very old. We
14+
# detect whether the system xdg utilities are sufficiently new to be likely to
15+
# work for us by looking for xdg-settings. If we find it, we leave $PATH alone,
16+
# so that the system xdg utilities (including any distro patches) will be used.
17+
if ! which xdg-settings &> /dev/null; then
18+
# Old xdg utilities. Prepend $HERE to $PATH to use ours instead.
19+
export PATH="$HERE:$PATH"
20+
else
21+
# Use system xdg utilities. But first create mimeapps.list if it doesn't
22+
# exist; some systems have bugs in xdg-mime that make it fail without it.
23+
xdg_app_dir="${XDG_DATA_HOME:-$HOME/.local/share/applications}"
24+
mkdir -p "$xdg_app_dir"
25+
[ -f "$xdg_app_dir/mimeapps.list" ] || touch "$xdg_app_dir/mimeapps.list"
26+
fi
27+
28+
# Always use our versions of ffmpeg libs.
29+
# This also makes RPMs find the compatibly-named library symlinks.
30+
if [[ -n "$LD_LIBRARY_PATH" ]]; then
31+
LD_LIBRARY_PATH="$HERE:$HERE/lib:$HERE/resources/app/node_modules/webnn-node/build/Release:$LD_LIBRARY_PATH"
32+
else
33+
LD_LIBRARY_PATH="$HERE:$HERE/lib;$HERE/resources/app/node_modules/webnn-node/build/Release"
34+
fi
35+
export LD_LIBRARY_PATH
36+
37+
# Sanitize std{in,out,err} because they'll be shared with untrusted child
38+
# processes (http://crbug.com/376567).
39+
exec < /dev/null
40+
exec > >(exec cat)
41+
exec 2> >(exec cat >&2)
42+
43+
# Note: exec -a below is a bashism.
44+
exec -a "$0" "$HERE/tflite-web-api-model-runner-demo" "$@"
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{
2+
"name": "tflite-web-api-model-runner-demo",
3+
"version": "0.1.0",
4+
"private": true,
25
"devDependencies": {
3-
"clang-format": "~1.2.4"
6+
"clang-format": "~1.2.4",
7+
"electron": "^15.0.0",
8+
"electron-packager": "^15.4.0"
49
},
510
"dependencies": {
6-
"electron": "^15.0.0",
7-
"webnn-node": "file:webnn-native/node"
11+
"webnn-node": "file:deps/webnn-native/node"
812
},
913
"main": "main.js",
1014
"scripts": {
1115
"build": "./build.sh",
1216
"start": "./start.sh",
13-
"electron": "./electron.sh"
17+
"electron": "./electron.sh",
18+
"electron-packager": "electron-packager . tflite-web-api-model-runner-demo --linux --ignore=\"/(deps|src)\"; cp demo-launcher ./tflite-web-api-model-runner-demo-linux-x64"
1419
}
1520
}

0 commit comments

Comments
 (0)