Skip to content

Commit c4c21a9

Browse files
authored
Fix GL reference in headless WebGL test code. (tensorflow#1832)
* Fix GL reference in headless WebGL test code. * Cleanup & README
1 parent c028b3c commit c4c21a9

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

tfjs-backend-nodegl/demo/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# MobileNet tfjs-backend-nodegl Demo
2+
3+
*This is a very early demo to show how tfjs-backend-nodegl can be used for headless WebGL acceleration.*
4+
5+
To run this demo, perform the following:
6+
7+
1. Move into `tfjs-backend-nodegl` (parent directory of this demo folder):
8+
```sh
9+
$ cd tfjs-backend-nodegl
10+
```
11+
12+
2. Build package and compile TypeScript:
13+
```sh
14+
$ yarn && yarn tsc
15+
```
16+
17+
3. Move into the demo directory:
18+
```sh
19+
$ cd demo
20+
```
21+
22+
4. Prep and build demo:
23+
```sh
24+
$ yarn
25+
```
26+
27+
5. Run demo:
28+
```sh
29+
$ node run_mobilenet_inference.js dog.jpg
30+
```
31+
32+
Expected output:
33+
```sh
34+
$ node run_mobilenet_inference.js dog.jpg
35+
Platform node has already been set. Overwriting the platform with [object Object].
36+
- gl.VERSION: OpenGL ES 3.0 (ANGLE 2.1.0.9512a0ef062a)
37+
- gl.RENDERER: ANGLE (Intel Inc., Intel(R) Iris(TM) Plus Graphics 640, OpenGL 4.1 core)
38+
- Loading model...
39+
- Mobilenet load: 6450.763924002647ms
40+
- Coldstarting model...
41+
- Mobilenet cold start: 297.92842200398445ms
42+
- Running inference (100x) ...
43+
- Mobilenet inference: (100x) : 35.75772546708584ms
44+
```

tfjs-backend-nodegl/demo/run_mobilenet_inference.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ const jpeg = require('jpeg-js');
2222

2323
const backendNodeGL = require('./../dist/index');
2424

25-
console.log(` - gl.VERSION: ${
26-
backendNodeGL.gl.getParameter(backendNodeGL.gl.VERSION)}`);
27-
console.log(` - gl.RENDERER: ${
28-
backendNodeGL.gl.getParameter(backendNodeGL.gl.RENDERER)}`);
25+
const gl = tf.backend().getGPGPUContext().gl;
26+
console.log(` - gl.VERSION: ${gl.getParameter(gl.VERSION)}`);
27+
console.log(` - gl.RENDERER: ${gl.getParameter(gl.RENDERER)}`);
2928

3029
const NUMBER_OF_CHANNELS = 3;
31-
const PREPROCESS_DIVISOR = tf.scalar(255 / 2);
30+
const PREPROCESS_DIVISOR = 255 / 2;
3231

3332
function readImageAsJpeg(path) {
3433
return jpeg.decode(fs.readFileSync(path), true);

0 commit comments

Comments
 (0)