This repository was archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Add compatibility tests generated from Android Neural Networks API (NNAPI) Compatibility Test Suite. #29
Merged
huningxin
merged 28 commits into
webmachinelearning:master
from
BruceDai:converted_nnapi-cts
Jan 11, 2021
Merged
Add compatibility tests generated from Android Neural Networks API (NNAPI) Compatibility Test Suite. #29
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9ebe994
[tool] Init Android NNAPI CTS converter for WebNN API.
BruceDai a2ba302
[tool] Supported to convert NNAPI CTS for testing following first wav…
BruceDai 7fa92da
Fixed an issue of getting conv2d inputChannels for 'nchw' layout.
BruceDai 831cdb8
[tool] Expanded 1D bias to 4D for add operation of generated conv2d t…
BruceDai 85b2a2e
[test] Added generated tests converted from NNAPI CTS.
BruceDai a394ec8
Disabled eslint to check maximum line length (80).
BruceDai 112b6aa
Use node es6 modules support
huningxin 1fedc40
Merge pull request #2 from huningxin/converted_nnapi-cts
BruceDai 43ba85d
[tool] Converted 6 tests for WebNN concat op.
BruceDai 26b29e1
[tool] Converted 18 tests for WebNN split op.
BruceDai 30655b9
[tool] Converted 17 tests for WebNN slice op.
BruceDai a843db4
[tool] Converted 6 tests for WebNN softmax op.
BruceDai 0df647e
[tool] Converted 15 tests for WebNN matmul op.
BruceDai d8314cc
Fixed camelcase lint error.
BruceDai 5166ec6
[tool] Updated README.md for test_generator tool.
BruceDai ca95ddc
Updated README.md and test/index.html for running CTS tests.
BruceDai 567e6f1
[test] Updated split tests with fixing camelcase lint error.
BruceDai e05103b
[test] Skipped 12 fail averagePool2d tests for not blocking CI.
BruceDai de23892
[tool] Used four accuracy constants for generated tests.
BruceDai 79e8423
[tests] Updated generated tests with four accuracy constants.
BruceDai 7d57450
[tool] Commented unsupport-convert information for some NNAPI CTS.
BruceDai 31d5934
Export four accuracy constants to fix no-unused-vars lint error.
BruceDai b8ef5bf
Using class AccuracyCriterion for creating accuracy constants.
BruceDai ab89cae
Updated generated tests with accuracy criterion constants.
BruceDai 61c0e79
Optimized to convert clamp tests from RELU1 & RELU6 CTS.
BruceDai d4b9869
Disabled max-len lint check for generated tests.
BruceDai 2e45a76
Updated tf.js version as 2.8.3.
BruceDai be83e61
Added 12 pool tests since pool issue (tensorflow/tfjs#4271)
BruceDai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
global.navigator = {}; | ||
require('./dist/webnn-polyfill.js'); | ||
global.chai = require('chai'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebNN API Polyfill | Mocha Tests</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" /> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
<script src="https://unpkg.com/chai/chai.js"></script> | ||
<script src="https://unpkg.com/mocha/mocha.js"></script> | ||
<script src="../dist/webnn-polyfill.js"></script> | ||
<script type="module" src="./utils.js"></script> | ||
<script class="mocha-init"> | ||
mocha.setup('bdd'); | ||
mocha.checkLeaks(); | ||
</script> | ||
<script type="module" src="./cts/from_nnapi/tests/cts.js"></script> | ||
<script class="mocha-exec" type="module"> | ||
mocha.run(); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Compatibility Test Suite (CTS) | ||
|
||
This [cts](./) folder is for holding converted tools and tests from existed native tests of Machine Learning for WebNN API. | ||
|
||
[./from_nnapi](./from_nnapi): holds converted tests from [Android Neural Networks API (NNAPI) CTS](https://android.googlesource.com/platform/frameworks/ml/+/refs/tags/android-cts-10.0_r5/nn/runtime/test/specs/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
These two Python scripts cts_generator.py and test_generator.py in | ||
test/generator/src folder come from those scripts in nn/tools/test_generator of | ||
https://android.googlesource.com/platform/frameworks/ml/ | ||
(tags: android-cts-10.0_r5) with some modification below: | ||
|
||
1. Modify cts_generator.py to generate CTS for WebNN API. | ||
2. Modify test_generator.py to generate CTS for WebNN API. | ||
|
||
Copyright 2017 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Converted CTS from NNAPI CTS | ||
|
||
## Test Generator Tool | ||
This [test_generator](./test_generator) tool is for converting existed native | ||
[NNAPI CTS](https://android.googlesource.com/platform/frameworks/ml/+/refs/tags/android-cts-10.0_r5/nn/runtime/test/specs/) of V1_0, V1_1 and V1_2 versions to these tests for WebNN API. | ||
|
||
### NNAPI Operations being map to WebNN API Operations Tables | ||
* Part I | ||
|
||
The `test_generator` tool has supported to convert those tests of following | ||
NNAPI operations to the tests for such WebNN API operations of first wave. | ||
|
||
| NNAPI | WebNN API (first wave ops) | | ||
|:------------------------------|:------------------------------| | ||
| RELU1 | clamp | | ||
| RELU6 | clamp | | ||
| CONCATENATION | concat | | ||
huningxin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ADD | add [+ relu/clamp] | | ||
| SUB | sub [+ relu/clamp] | | ||
| MUL | mul [+ relu/clamp] | | ||
| DIV | div [+ relu/clamp] | | ||
| MAXIMUM | max | | ||
| MINIMUM | min | | ||
| EXP | exp | | ||
| LOGISTIC | sigmoid | | ||
| SQRT | sqrt | | ||
| TANH | tanh | | ||
| FULLY_CONNECTED | matmul [+ add+ relu/clamp] | | ||
| AVERAGE_POOL_2D | averagePool2d [+ relu/clamp] | | ||
| MAX_POOL_2D | maxPool2d [+ relu/clamp] | | ||
| CONV_2D | conv2d [+ add + relu/clamp] | | ||
| DEPTHWISE_CONV_2D | conv2d [+ add + relu/clamp] | | ||
| RELU | relu | | ||
| RESHAPE | reshape | | ||
| SLICE | slice | | ||
huningxin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SOFTMAX | softmax | | ||
| SPLIT | split | | ||
huningxin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SQUEEZE | squeeze | | ||
| TRANSPOSE | transpose | | ||
|
||
* Part II | ||
|
||
And there're these following NNAPI operations which could be map to others | ||
WebNN API operations of next waves. | ||
|
||
| NNAPI | WebNN API (next waves ops) | | ||
|:------------------------------|:------------------------------| | ||
| ABS | abs | | ||
| FLOOR | floor | | ||
| LOG | log | | ||
| NEG | neg | | ||
| SIN | sin | | ||
| L2_POOL_2D | l2Pool2d [+ relu/clamp] | | ||
huningxin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* Note: | ||
|
||
1. Current WebNN Polyfill API supports Float32 and Int32 two types, so these | ||
NNAPI CTS using Float32 and Int32 types were able to be converted, while those | ||
NNAPI CTS using Uint8 and Int8 types would be converted until WebNN Polyfill API | ||
supports Uint8 and Int8 types. | ||
|
||
2. Native NNAPI supports Float16, while there's lack of Float16 in JavaScript | ||
environments, so such NNAPI CTS with Float16 wouldn't be convertted. | ||
|
||
### Usage | ||
* Prerequisites | ||
* Python3 | ||
* Numpy | ||
* Download and unzip NNAPI CTS Specs tarball files locally by below commands | ||
|
||
```shell | ||
cd test_generator | ||
./ready_nnapi_cts_specs.sh | ||
``` | ||
* Generate Tests | ||
|
||
```shell | ||
npm start | ||
``` | ||
|
||
Generated tests would be in following three folders | ||
[./tests/V1_0](./test/V1_0) | ||
[./tests/V1_1](./test/V1_1) | ||
[./tests/V1_2](./test/V1_2) | ||
and these tests could also be in all-in-one | ||
[./tests/cts.js](./tests/cts.js) file. | ||
|
||
|
||
### Accuracy for Generated Tests | ||
The converted tests follow these [reference accuracy](https://android.googlesource.com/platform/frameworks/ml/+/refs/tags/android-cts-10.0_r5/nn/runtime/test/TestGenerated.cpp#117): | ||
```cpp | ||
float fpAtol = 1e-5f; | ||
float fpRtol = 5.0f * 1.1920928955078125e-7f; | ||
``` | ||
And for relaxed tests | ||
```cpp | ||
// If in relaxed mode, set the absolute tolerance to be 5ULP of FP16. | ||
fpAtol = 5.0f * 0.0009765625f; | ||
// Set the relative tolerance to be 5ULP of the corresponding FP precision. | ||
fpRtol = 5.0f * 0.0009765625f; | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "test_generator", | ||
"version": "0.0.1", | ||
"description": "Convert native NNAPI CTS tests to WebNN API tests", | ||
"license": "Apache 2.0", | ||
"main": "./src/main.py", | ||
"directories": { | ||
"src": "src files" | ||
}, | ||
"scripts": { | ||
"start": "python3 ./src/main.py ./specs -t ../tests -c ../tests/cts.js" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"authors": [ | ||
"Bruce Dai <[email protected]>" | ||
] | ||
} |
15 changes: 15 additions & 0 deletions
15
test/cts/from_nnapi/test_generator/ready_nnapi_cts_specs.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
TAG=android-cts-10.0_r5 | ||
NNAPI_VERSION=" | ||
V1_0 | ||
V1_1 | ||
V1_2 | ||
" | ||
|
||
# download and unzip Specs tarball files | ||
for version in ${NNAPI_VERSION} | ||
do | ||
wget https://android.googlesource.com/platform/frameworks/ml/+archive/refs/tags/${TAG}/nn/runtime/test/specs/${version}.tar.gz | ||
mkdir -p specs/${version} | ||
tar -xvzf ${version}.tar.gz -C specs/${version} | ||
done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.