Skip to content

Commit ff3147d

Browse files
authored
Organize the benchmark toolkit (#3793)
DEV
1 parent edca57d commit ff3147d

File tree

14 files changed

+75
-17
lines changed

14 files changed

+75
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ on NPM.
7777

7878
## Benchmarks
7979

80-
[Benchmark tool](https://tensorflow.github.io/tfjs/e2e/benchmarks/index.html). Use this webpage tool to test the performance related metrics (speed, memory, power, etc) of TensorFlow.js models on your local device with CPU, WebGL or WASM backend. You can benchmark custom models following this [guide](https://github.com/tensorflow/tfjs/e2e/benchmarks/README.md).
80+
[Benchmark tool](https://tensorflow.github.io/tfjs/e2e/benchmarks/local-benchmark/index.html). Use this webpage tool to test the performance related metrics (speed, memory, power, etc) of TensorFlow.js models on your local device with CPU, WebGL or WASM backend. You can benchmark custom models following this [guide](https://github.com/tensorflow/tfjs/blob/master/e2e/benchmarks/local-benchmark/README.md).
8181

8282
## Getting started
8383

e2e/benchmarks/SpecRunner.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,18 @@
2525
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine-html.js"></script>
2626
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/boot.js"></script>
2727

28-
29-
3028
<script src="https://unpkg.com/@tensorflow/tfjs-core@latest/dist/tf-core.js"></script>
3129
<script src="https://unpkg.com/@tensorflow/tfjs-backend-cpu@latest/dist/tf-backend-cpu.js"></script>
3230
<script src="https://unpkg.com/@tensorflow/tfjs-backend-webgl@latest/dist/tf-backend-webgl.js"></script>
3331
<script src="https://unpkg.com/@tensorflow/tfjs-layers@latest/dist/tf-layers.js"></script>
3432
<script src="https://unpkg.com/@tensorflow/tfjs-converter@latest/dist/tf-converter.js"></script>
3533
<script src="https://unpkg.com/@tensorflow/tfjs-backend-wasm@latest/dist/tf-backend-wasm.js"></script>
36-
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
3734

3835
<!-- include source files here... -->
3936
<script src="./benchmark_util.js"></script>
40-
<script src="./index.js"></script>
4137

4238
<!-- include spec files here... -->
4339
<script src="./benchmark_util_test.js"></script>
44-
<script src="./index_test.js"></script>
4540

4641
</head>
4742

e2e/benchmarks/benchmark_util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
* =============================================================================
1616
*/
1717

18+
/**
19+
* This tool depends on tf-core, tf-layers, tf-converter and the backends
20+
* (tf-backend-cpu, tf-backend-webgl or tf-backend-wasm) that you would use.
21+
*/
22+
1823
/**
1924
* Generates a random input for `model`, based on `model.inputs`. For
2025
* tf.GraphModel, `NamedTensorMap` input will be returned; otherwise,

e2e/benchmarks/benchmark_util_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
/**
19-
* The unit tests in this file can be run by opening `SpecRunner.html` in
19+
* The unit tests in this file can be run by opening `./SpecRunner.html` in
2020
* browser.
2121
*/
2222

e2e/benchmarks/browserstack-benchmark/app_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
* =============================================================================
1616
*/
1717

18+
/**
19+
* The unit tests in this file can be run by opening `./SpecRunner.html` in
20+
* browser.
21+
*/
22+
1823
describe('benchmark multiple browsers', () => {
1924
const browsersList = [
2025
{

e2e/benchmarks/browserstack-benchmark/index_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
/**
19-
* The unit tests in this file can be run by opening `SpecRunner.html` in
19+
* The unit tests in this file can be run by opening `./SpecRunner.html` in
2020
* browser.
2121
*/
2222

e2e/benchmarks/README.md renamed to e2e/benchmarks/local-benchmark/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Benchmark custom models
22

3-
The `custom model` in the [benchmark tool](https://tensorflow.github.io/tfjs/e2e/benchmarks/index.html) currently only supports `tf.GraphModel` or `tf.LayersModel`.
3+
The `custom model` in the [benchmark tool](https://tensorflow.github.io/tfjs/e2e/benchmarks/local-benchmark/index.html) currently only supports `tf.GraphModel` or `tf.LayersModel`.
44

55
If you want to benchmark models in other types or customize the inputs for model inference, you need to implement `load` and `predictFunc` methods, following this [example PR](https://github.com/tensorflow/tfjs/pull/3168/files).
66

77
## Models in local file system
88
If you have a model in local file system, you can follow the steps below:
99
1. Download [tfjs repository](https://github.com/tensorflow/tfjs.git).
10-
2. Put your `model.json` file and the weight files under the `tfjs/e2e/benchmarks/` folder.
11-
3. Under the `tfjs/e2e/benchmarks/` folder, run `npx http-server`.
10+
2. Put your `model.json` file and the weight files under the `tfjs/e2e/benchmarks/local-benchmark/` folder.
11+
3. Under the `tfjs/e2e/benchmarks/local-benchmark/` folder, run `npx http-server`.
1212
4. Open the browser go to `http://127.0.0.1:8080/`, this will open the benchmark tool. Then populate the `model.json` url to `modelUrl` under the custom model, which is `http://127.0.0.1:8080/model.json`.
1313

1414
In addition, if the online tool is blocked by `CORS` problems when fetching the custom model, you can locally serve the model by the above steps to solve this problem.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!-- Copyright 2020 Google LLC. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================-->
15+
16+
<!DOCTYPE html>
17+
<html>
18+
<head>
19+
<meta charset="utf-8">
20+
<title>Jasmine Test</title>
21+
22+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine.css">
23+
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine.js"></script>
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine-html.js"></script>
26+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/boot.js"></script>
27+
28+
<script src="https://unpkg.com/@tensorflow/tfjs-core@latest/dist/tf-core.js"></script>
29+
<script src="https://unpkg.com/@tensorflow/tfjs-backend-cpu@latest/dist/tf-backend-cpu.js"></script>
30+
<script src="https://unpkg.com/@tensorflow/tfjs-backend-webgl@latest/dist/tf-backend-webgl.js"></script>
31+
<script src="https://unpkg.com/@tensorflow/tfjs-layers@latest/dist/tf-layers.js"></script>
32+
<script src="https://unpkg.com/@tensorflow/tfjs-converter@latest/dist/tf-converter.js"></script>
33+
<script src="https://unpkg.com/@tensorflow/tfjs-backend-wasm@latest/dist/tf-backend-wasm.js"></script>
34+
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
35+
36+
<script src="../benchmark_util.js"></script>
37+
38+
<!-- include source files here... -->
39+
<script src="./index.js"></script>
40+
41+
<!-- include spec files here... -->
42+
<script src="./index_test.js"></script>
43+
44+
</head>
45+
46+
<body>
47+
</body>
48+
</html>

e2e/benchmarks/index.html renamed to e2e/benchmarks/local-benchmark/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ <h2>TensorFlow.js Model Benchmark</h2>
9696
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet@2"></script>
9797
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-pix@2"></script>
9898

99-
<script src="./model_config.js"></script>
99+
<script src="../model_config.js"></script>
100+
<script src="../benchmark_util.js"></script>
100101
<script src="./util.js"></script>
101-
<script src="./benchmark_util.js"></script>
102102
<script src="./index.js"></script>
103103
<script>
104104
'use strict';
File renamed without changes.

0 commit comments

Comments
 (0)