├── .github └── workflows │ ├── codeql-analysis.yml │ └── deploy-debugger-prod.yml ├── .gitignore ├── .tslint ├── noImportsFromDistRule.js └── noImportsFromDistRule.ts ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── cloudbuild.yml ├── coral-tflite-delegate ├── .npmignore ├── README.md ├── jasmine-integration.json ├── jasmine.json ├── package.json ├── src │ ├── index.ts │ ├── index_test.ts │ └── integration_test │ │ └── index_test.ts ├── test_model │ ├── COPYRIGHT │ ├── inat_bird_labels.txt │ ├── mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite │ └── parrot-small.jpg ├── tsconfig.json ├── tslint.json └── yarn.lock ├── dockers └── sig-ci-docker │ └── Dockerfile ├── package.json ├── presubmit.ts ├── rfc-template.md ├── rfcs ├── 20211020-webnn-delegate-for-tflite-web.md ├── 20211020-webnn-delegate-for-tflite-web │ └── class_diagram.png ├── 20211109-tflite-support-for-node.md └── 20211109-tflite-support-for-node │ ├── coral-delegate-node.png │ ├── mediapipe-face-coral.png │ └── mediapipe-face.png ├── tfjs-tflite-node-codelab ├── coral_inference_working │ ├── README.md │ ├── coral_model │ │ ├── labels.txt │ │ └── model_edgetpu.tflite │ ├── index.html │ ├── main.js │ ├── model │ │ ├── labels.txt │ │ └── model_unquant.tflite │ ├── package.json │ └── renderer.js ├── coral_movenet │ ├── README.md │ ├── index.html │ ├── main.js │ ├── models │ │ ├── README.txt │ │ ├── movenet_single_pose_thunder_ptq.tflite │ │ └── movenet_single_pose_thunder_ptq_edgetpu.tflite │ ├── package.json │ ├── renderer.js │ └── yarn.lock ├── cpu_inference_working │ ├── README.md │ ├── index.html │ ├── main.js │ ├── model │ │ ├── labels.txt │ │ └── model_unquant.tflite │ ├── package-lock.json │ ├── package.json │ └── renderer.js ├── starter_code │ ├── README.md │ ├── coral_model │ │ └── README.md │ ├── index.html │ ├── main.js │ ├── model │ │ └── README.md │ ├── package-lock.json │ ├── package.json │ └── renderer.js └── webnn_inference_working │ ├── README.md │ ├── index.html │ ├── main.js │ ├── model │ ├── labels.txt │ └── model_unquant.tflite │ ├── package.json │ └── renderer.js ├── tfjs-tflite-node ├── .npmignore ├── README.md ├── binding.gyp ├── binding │ └── node_tflite_binding.cc ├── cc_deps │ ├── darwin_arm64 │ │ ├── libexternal_delegate_obj.dylib │ │ └── libtensorflowlite_c.dylib │ ├── include │ │ └── tensorflow │ │ │ └── lite │ │ │ ├── c │ │ │ ├── c_api.h │ │ │ ├── c_api_types.h │ │ │ └── common.h │ │ │ └── delegates │ │ │ └── external │ │ │ └── external_delegate.h │ ├── linux_amd64 │ │ ├── libexternal_delegate_obj.so │ │ └── libtensorflowlite_c.so │ ├── linux_arm64 │ │ ├── libexternal_delegate_obj.so │ │ └── libtensorflowlite_c.so │ └── windows_amd64 │ │ ├── external_delegate_obj.dll │ │ ├── external_delegate_obj.dll.if.lib │ │ ├── tensorflowlite_c.dll │ │ └── tensorflowlite_c.dll.if.lib ├── jasmine.json ├── package.json ├── src │ ├── delegate_plugin.ts │ ├── index.ts │ ├── index_test.ts │ └── tflite_model.ts ├── test_data │ ├── COPYRIGHT │ ├── inat_bird_labels.txt │ ├── mobilenet_v2_1.0_224_inat_bird_quant.tflite │ ├── parrot-small.jpg │ └── teachable_machine_float.tflite ├── tsconfig.json ├── tslint.json └── yarn.lock ├── toolings └── tfjs-debugger │ ├── .browserslistrc │ ├── .editorconfig │ ├── .gitignore │ ├── .stylelintrc.json │ ├── README.md │ ├── angular.json │ ├── firebase.json │ ├── karma-ci.conf.js │ ├── karma.conf.js │ ├── package.json │ ├── scripts │ └── deploy-to-firebase.sh │ ├── src │ ├── app │ │ ├── app │ │ │ ├── app.component.html │ │ │ ├── app.component.scss │ │ │ ├── app.component.spec.ts │ │ │ ├── app.component.ts │ │ │ └── app.module.ts │ │ ├── common │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ ├── components │ │ │ ├── app_bar │ │ │ │ ├── app_bar.component.html │ │ │ │ ├── app_bar.component.scss │ │ │ │ ├── app_bar.component.ts │ │ │ │ └── app_bar.module.ts │ │ │ ├── backend_selector │ │ │ │ ├── backend_selector.component.html │ │ │ │ ├── backend_selector.component.scss │ │ │ │ ├── backend_selector.component.spec.ts │ │ │ │ ├── backend_selector.component.ts │ │ │ │ ├── backend_selector.module.ts │ │ │ │ ├── backend_version_selector.component.html │ │ │ │ ├── backend_version_selector.component.scss │ │ │ │ ├── backend_version_selector.component.ts │ │ │ │ └── types.ts │ │ │ ├── config_section │ │ │ │ ├── config_section.component.html │ │ │ │ ├── config_section.component.scss │ │ │ │ ├── config_section.component.ts │ │ │ │ └── config_section.module.ts │ │ │ ├── configs_panel │ │ │ │ ├── configs_panel.component.html │ │ │ │ ├── configs_panel.component.scss │ │ │ │ ├── configs_panel.component.ts │ │ │ │ └── configs_panel.module.ts │ │ │ ├── error_panel │ │ │ │ ├── error_panel.component.html │ │ │ │ ├── error_panel.component.scss │ │ │ │ ├── error_panel.component.spec.ts │ │ │ │ ├── error_panel.component.ts │ │ │ │ └── error_panel.module.ts │ │ │ ├── graph_panel │ │ │ │ ├── graph_panel.component.html │ │ │ │ ├── graph_panel.component.scss │ │ │ │ ├── graph_panel.component.ts │ │ │ │ ├── graph_panel.module.ts │ │ │ │ ├── graph_service.ts │ │ │ │ └── types.d.ts │ │ │ ├── info_panel │ │ │ │ ├── info_panel.component.html │ │ │ │ ├── info_panel.component.scss │ │ │ │ ├── info_panel.component.ts │ │ │ │ └── info_panel.module.ts │ │ │ ├── input_selector │ │ │ │ ├── input_selector.component.html │ │ │ │ ├── input_selector.component.scss │ │ │ │ ├── input_selector.component.spec.ts │ │ │ │ ├── input_selector.component.ts │ │ │ │ ├── input_selector.module.ts │ │ │ │ └── types.ts │ │ │ ├── model_selector │ │ │ │ ├── model_selector.component.html │ │ │ │ ├── model_selector.component.scss │ │ │ │ ├── model_selector.component.spec.ts │ │ │ │ ├── model_selector.component.ts │ │ │ │ ├── model_selector.module.ts │ │ │ │ └── types.ts │ │ │ └── run_progress_overlay │ │ │ │ ├── run_progress_overlay.component.html │ │ │ │ ├── run_progress_overlay.component.scss │ │ │ │ ├── run_progress_overlay.component.ts │ │ │ │ └── run_progress_overlay.module.ts │ │ ├── data_model │ │ │ ├── backend_type.ts │ │ │ ├── configuration.ts │ │ │ ├── input_type.ts │ │ │ ├── misc.ts │ │ │ ├── model_type.ts │ │ │ ├── run_results.ts │ │ │ └── tfjs_release.ts │ │ ├── layout_generator │ │ │ └── layout_generator.worker.ts │ │ ├── services │ │ │ ├── github_service.ts │ │ │ ├── tfjs_service.ts │ │ │ └── url_service.ts │ │ └── store │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ ├── reducers.ts │ │ │ ├── selectors.ts │ │ │ ├── state.ts │ │ │ └── utils.ts │ ├── assets │ │ ├── .gitkeep │ │ ├── GoogleSans-Medium.ttf │ │ └── GoogleSans-Regular.ttf │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.svg │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ ├── test.ts │ ├── theme.scss │ └── variables.scss │ ├── tsconfig.app.json │ ├── tsconfig.json │ ├── tsconfig.spec.json │ ├── tsconfig.worker.json │ ├── tslint.json │ └── yarn.lock ├── tslint.json ├── webnn-tflite-delegate ├── .npmignore ├── README.md ├── cc_lib │ ├── linux_x64 │ │ ├── libngraph_c_api.so │ │ ├── libwebnn_native.so │ │ ├── libwebnn_proc.so │ │ └── webnn_external_delegate_obj.so │ └── win32_x64 │ │ ├── ngraph_c_api.dll │ │ ├── webnn_external_delegate_obj.dll │ │ ├── webnn_native.dll │ │ └── webnn_proc.dll ├── jasmine-integration.json ├── jasmine.json ├── package.json ├── setupvars.bat ├── setupvars.sh ├── src │ ├── index.ts │ ├── index_test.ts │ └── integration_test │ │ └── index_test.ts ├── test_model │ ├── mobilenetv2.tflite │ ├── mobilenetv2_labels.txt │ └── wine.jpeg ├── tsconfig.json ├── tslint.json └── yarn.lock └── yarn.lock /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '35 14 * * 6' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'typescript', 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /.github/workflows/deploy-debugger-prod.yml: -------------------------------------------------------------------------------- 1 | name: Deploy TFJS Debugger Site to Live 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - 'toolings/tfjs-debugger/**' 9 | 10 | jobs: 11 | deploy_live_website: 12 | runs-on: ubuntu-latest 13 | defaults: 14 | run: 15 | shell: bash 16 | working-directory: toolings/tfjs-debugger 17 | steps: 18 | - uses: actions/checkout@v2 19 | - uses: actions/setup-node@v2 20 | with: 21 | node-version: 12 22 | - run: | 23 | yarn 24 | yarn build 25 | - uses: FirebaseExtended/action-hosting-deploy@v0 26 | with: 27 | repoToken: '${{ secrets.GITHUB_TOKEN }}' 28 | firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSTENSORFLOW }}' 29 | projectId: jstensorflow 30 | target: tfjs-debugger 31 | channelId: live 32 | entryPoint: toolings/tfjs-debugger/ 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *~ 3 | #*# 4 | build/ 5 | dist/ 6 | yarn-error.log -------------------------------------------------------------------------------- /.tslint/noImportsFromDistRule.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | 'use strict'; 19 | var __extends = (this && this.__extends) || (function() { 20 | var extendStatics = function(d, b) { 21 | extendStatics = Object.setPrototypeOf || 22 | ({__proto__: []} instanceof Array && function(d, b) { 23 | d.__proto__ = b; 24 | }) || function(d, b) { 25 | for (var p in b) 26 | if (b.hasOwnProperty(p)) d[p] = b[p]; 27 | }; 28 | return extendStatics(d, b); 29 | }; 30 | return function(d, b) { 31 | extendStatics(d, b); 32 | function __() { 33 | this.constructor = d; 34 | } 35 | d.prototype = b === null ? 36 | Object.create(b) : 37 | (__.prototype = b.prototype, new __()); 38 | }; 39 | })(); 40 | exports.__esModule = true; 41 | var Lint = require('tslint'); 42 | var Rule = /** @class */ (function(_super) { 43 | __extends(Rule, _super); 44 | function Rule() { 45 | return _super !== null && _super.apply(this, arguments) || this; 46 | } 47 | Rule.prototype.apply = function(sourceFile) { 48 | return this.applyWithWalker( 49 | new NoImportsFromDistWalker(sourceFile, this.getOptions())); 50 | }; 51 | Rule.FAILURE_STRING = 52 | 'importing from dist/ is prohibited. Please use public API'; 53 | return Rule; 54 | }(Lint.Rules.AbstractRule)); 55 | exports.Rule = Rule; 56 | var NoImportsFromDistWalker = /** @class */ (function(_super) { 57 | __extends(NoImportsFromDistWalker, _super); 58 | function NoImportsFromDistWalker() { 59 | return _super !== null && _super.apply(this, arguments) || this; 60 | } 61 | NoImportsFromDistWalker.prototype.visitImportDeclaration = function(node) { 62 | var importFrom = node.moduleSpecifier.getText(); 63 | var reg = /@tensorflow\/tfjs[-a-z]*\/dist/; 64 | if (importFrom.match(reg)) { 65 | var fix = new Lint.Replacement( 66 | node.moduleSpecifier.getStart(), node.moduleSpecifier.getWidth(), 67 | importFrom.replace(/\/dist[\/]*/, '')); 68 | this.addFailure(this.createFailure( 69 | node.moduleSpecifier.getStart(), node.moduleSpecifier.getWidth(), 70 | Rule.FAILURE_STRING, fix)); 71 | } 72 | _super.prototype.visitImportDeclaration.call(this, node); 73 | }; 74 | return NoImportsFromDistWalker; 75 | }(Lint.RuleWalker)); 76 | -------------------------------------------------------------------------------- /.tslint/noImportsFromDistRule.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import * as Lint from 'tslint'; 19 | import * as ts from 'typescript'; 20 | 21 | export class Rule extends Lint.Rules.AbstractRule { 22 | public static FAILURE_STRING = 23 | 'importing from dist/ is prohibited. Please use public API'; 24 | 25 | public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { 26 | return this.applyWithWalker( 27 | new NoImportsFromDistWalker(sourceFile, this.getOptions())); 28 | } 29 | } 30 | 31 | class NoImportsFromDistWalker extends Lint.RuleWalker { 32 | public visitImportDeclaration(node: ts.ImportDeclaration) { 33 | const importFrom = node.moduleSpecifier.getText(); 34 | const reg = /@tensorflow\/tfjs[-a-z]*\/dist/; 35 | if (importFrom.match(reg)) { 36 | const fix = new Lint.Replacement( 37 | node.moduleSpecifier.getStart(), node.moduleSpecifier.getWidth(), 38 | importFrom.replace(/\/dist[\/]*/, '')); 39 | 40 | this.addFailure(this.createFailure( 41 | node.moduleSpecifier.getStart(), node.moduleSpecifier.getWidth(), 42 | Rule.FAILURE_STRING, fix)); 43 | } 44 | 45 | super.visitImportDeclaration(node); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TensorFlow.JS SIG repo 2 | 3 | A community repo for TFJS SIG projects. 4 | -------------------------------------------------------------------------------- /cloudbuild.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: 'gcr.io/learnjs-174218/sig-ci-docker' 3 | entrypoint: 'yarn' 4 | id: 'yarn' 5 | args: ['install'] 6 | - name: 'gcr.io/learnjs-174218/sig-ci-docker' 7 | entrypoint: 'yarn' 8 | id: 'test' 9 | args: ['presubmit'] 10 | waitFor: ['yarn'] 11 | env: ['BROWSERSTACK_USERNAME=deeplearnjs1'] 12 | secretEnv: ['BROWSERSTACK_KEY'] 13 | secrets: 14 | - kmsKeyName: projects/learnjs-174218/locations/global/keyRings/tfjs/cryptoKeys/enc 15 | secretEnv: 16 | BROWSERSTACK_KEY: CiQAkwyoIW0LcnxymzotLwaH4udVTQFBEN4AEA5CA+a3+yflL2ASPQAD8BdZnGARf78MhH5T9rQqyz9HNODwVjVIj64CTkFlUCGrP1B2HX9LXHWHLmtKutEGTeFFX9XhuBzNExA= 17 | timeout: 1800s 18 | logsBucket: 'gs://tfjs-build-logs' 19 | options: 20 | logStreamingOption: 'STREAM_ON' 21 | machineType: 'N1_HIGHCPU_8' 22 | substitution_option: 'ALLOW_LOOSE' 23 | -------------------------------------------------------------------------------- /coral-tflite-delegate/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test_model/ 3 | *~ 4 | #*# 5 | yarn-error.log -------------------------------------------------------------------------------- /coral-tflite-delegate/README.md: -------------------------------------------------------------------------------- 1 | # Coral Delegate for tfjs-tflite-node 2 | The `coral-tflite-delegate` package adds support for [Coral EdgeTPU Accelerators](https://coral.ai/products/accelerator/) to [tfjs-tflite-node](https://www.npmjs.com/package/tfjs-tflite-node). 3 | 4 | ## Installing 5 | This package depends on the [EdgeTPU Runtime Library (libedgetpu)](https://github.com/google-coral/libedgetpu). Follow the [instructions here](https://coral.ai/docs/accelerator/get-started#1-install-the-edge-tpu-runtime) to install it on Linux (x64, arm64), Mac (x64), or Windows (x64). libedgetpu can also be [built from source](https://github.com/google-coral/libedgetpu#building) if binaries are not available for your platform. 6 | 7 | After libedgetpu is installed, you can install the `coral-tflite-delegate` package with `npm i --save coral-tflite-delegate`. 8 | 9 | ## Usage 10 | Register the Coral delegate while loading a TFLite model in `tfjs-tflite-node` by adding it to the list of delegates in the TFLite options: 11 | 12 | ```typescript 13 | const model = await loadTFLiteModel('./model_edgetpu.tflite', { 14 | delegates: [new CoralDelegate()], 15 | }); 16 | 17 | ``` 18 | 19 | The Coral delegate will be used for any edgetpu ops the model contains. Most model files will need to be compiled for Coral before they can be accelerated. See the [EdgeTPU documentation](https://coral.ai/docs/edgetpu/models-intro/#compiling) for more details on how to do this. 20 | -------------------------------------------------------------------------------- /coral-tflite-delegate/jasmine-integration.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_files": [ 3 | "dist/integration_test/*_test.js" 4 | ], 5 | "env": { 6 | "stopSpecOnExpectationFailure": false, 7 | "random": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /coral-tflite-delegate/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_files": [ 3 | "dist/*_test.js" 4 | ], 5 | "env": { 6 | "stopSpecOnExpectationFailure": false, 7 | "random": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /coral-tflite-delegate/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "coral-tflite-delegate", 3 | "version": "0.0.1-alpha.1", 4 | "description": "A tflite delegate for using Coral accelerators.", 5 | "main": "dist/index.js", 6 | "license": "Apache-2.0", 7 | "scripts": { 8 | "build": "tsc", 9 | "build-deps": "cd ../tfjs-tflite-node && yarn && yarn build", 10 | "test-dev": "jasmine --config=jasmine.json", 11 | "test": "yarn build && yarn test-dev", 12 | "test-integration-dev": "jasmine --config=jasmine-integration.json", 13 | "test-integration": "yarn build && yarn test-integration-dev", 14 | "lint": "tslint -p . -t verbose" 15 | }, 16 | "devDependencies": { 17 | "@tensorflow/tfjs-backend-cpu": "^3.15.0", 18 | "@tensorflow/tfjs-core": "^3.15.0", 19 | "tfjs-tflite-node": "link:../tfjs-tflite-node", 20 | "@types/jasmine": "^4.0.0", 21 | "@types/node": "^17.0.21", 22 | "jasmine": "^4.0.2", 23 | "jpeg-js": "^0.4.3", 24 | "tslint": "^6.1.3", 25 | "tslint-no-circular-imports": "^0.7.0", 26 | "typescript": "^4.5.4" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /coral-tflite-delegate/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import type {TFLiteDelegatePlugin} from 'tfjs-tflite-node'; 19 | import * as os from 'os'; 20 | 21 | // The Coral delegate is unusual since it requires the user to have installed 22 | // libedgetpu themselves (due to udev rules for accessing the USB device). 23 | // This means we don't actually ship any DLLs for node. Instead, we load the 24 | // one the user already has installed in their library path. 25 | // 26 | // The following names are from the python implementation. 27 | // https://github.com/google-coral/pycoral/blob/9972f8ec6dbb8b2f46321e8c0d2513e0b6b152ce/pycoral/utils/edgetpu.py#L34-L38 28 | const libNames = new Map([ 29 | ['linux', 'libedgetpu.so.1'], 30 | ['darwin', 'libedgetpu.1.dylib'], 31 | ['win32', 'edgetpu.dll'], 32 | ]); 33 | 34 | // Which Coral device to use. See edgetpu.py for more details. 35 | // https://github.com/google-coral/pycoral/blob/master/pycoral/utils/edgetpu.py#L66-L72 36 | export type CoralDevice = `:${number}` | 'usb' | `usb:${number}` | 'pci' 37 | | `pci:${number}`; 38 | 39 | export interface CoralOptions { 40 | device?: CoralDevice; 41 | } 42 | 43 | export class CoralDelegate implements TFLiteDelegatePlugin { 44 | readonly name = 'CoralDelegate'; 45 | readonly tfliteVersion = '2.7'; 46 | readonly node: TFLiteDelegatePlugin['node']; 47 | readonly options: Array<[string, string]> = []; 48 | 49 | constructor(options: CoralOptions = {}, 50 | libPath?: string, platform = os.platform()) { 51 | if (!libPath) { 52 | libPath = libNames.get(platform); 53 | if (!libPath) { 54 | throw new Error(`Unknown platform ${platform}`); 55 | } 56 | } 57 | 58 | if (options.device) { 59 | this.options.push(['device', options.device]); 60 | } 61 | 62 | this.node = { 63 | path: libPath, 64 | }; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /coral-tflite-delegate/src/index_test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import '@tensorflow/tfjs-backend-cpu'; 19 | import {CoralDelegate} from './index'; 20 | 21 | describe('coral delegate', () => { 22 | it('has the name "CoralDelegate"', () => { 23 | expect(new CoralDelegate().name).toEqual('CoralDelegate'); 24 | }); 25 | 26 | it('has a TfLite version string', () => { 27 | expect(new CoralDelegate().tfliteVersion).toBeDefined(); 28 | }); 29 | 30 | it('stores options', () => { 31 | const coralDelegate = new CoralDelegate({ 32 | device: 'usb:123', 33 | }); 34 | expect(coralDelegate.options).toEqual([['device', 'usb:123']]); 35 | }); 36 | 37 | it('allows manually setting lib path', () => { 38 | const libPath = 'some lib path'; 39 | const coralDelegate = new CoralDelegate({}, libPath); 40 | expect(coralDelegate.node.path).toEqual(libPath); 41 | }); 42 | 43 | it('sets the lib path automatically based on platorm', () => { 44 | const coralLinux = new CoralDelegate({}, undefined, 'linux'); 45 | const coralMac = new CoralDelegate({}, undefined, 'darwin'); 46 | const coralWindows = new CoralDelegate({}, undefined, 'win32'); 47 | 48 | expect(coralLinux.node.path).toEqual('libedgetpu.so.1'); 49 | expect(coralMac.node.path).toEqual('libedgetpu.1.dylib'); 50 | expect(coralWindows.node.path).toEqual('edgetpu.dll'); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /coral-tflite-delegate/src/integration_test/index_test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CoralDelegate} from '../index'; 19 | import {loadTFLiteModel} from 'tfjs-tflite-node'; 20 | import type {TFLiteModel} from 'tfjs-tflite-node/dist/tflite_model'; 21 | import * as fs from 'fs'; 22 | import * as tf from '@tensorflow/tfjs-core'; 23 | import '@tensorflow/tfjs-backend-cpu'; 24 | import * as jpeg from 'jpeg-js'; 25 | 26 | describe('coral delegate', () => { 27 | const modelPath = './test_model/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite'; 28 | let model: TFLiteModel; 29 | let parrot: tf.Tensor; 30 | let labels: string[]; 31 | 32 | beforeEach(async () => { 33 | model = await loadTFLiteModel(modelPath, { 34 | delegates: [new CoralDelegate()], 35 | }); 36 | 37 | // Load the input image of a parrot. 38 | const parrotJpeg = jpeg.decode( 39 | fs.readFileSync('./test_model/parrot-small.jpg')); 40 | 41 | // Create an RGB array of the parrot's pixels (no Alpha channel). 42 | const {width, height, data} = parrotJpeg; 43 | const parrotRGB = new Uint8Array(width * height * 3); 44 | for (let i = 0; i < width * height; i++) { 45 | const i3 = i * 3; 46 | const i4 = i * 4; 47 | parrotRGB[i3] = data[i4]; 48 | parrotRGB[i3 + 1] = data[i4 + 1]; 49 | parrotRGB[i3 + 2] = data[i4 + 2]; 50 | } 51 | 52 | parrot = tf.tensor(parrotRGB, [1, 224, 224, 3]); 53 | labels = fs.readFileSync('./test_model/inat_bird_labels.txt', 'utf-8') 54 | .split('\n'); 55 | }); 56 | 57 | it('runs a coral model (will fail without coral device)', () => { 58 | const prediction = model.predict(parrot); 59 | const argmax = tf.argMax(prediction as tf.Tensor, 1); 60 | const label = labels[argmax.dataSync()[0]]; 61 | expect(label).toEqual('Ara macao (Scarlet Macaw)'); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /coral-tflite-delegate/test_model/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Open Images Dataset V5. 2 | License: Attribution 2.0 Generic (CC BY 2.0) 3 | URL: https://creativecommons.org/licenses/by/2.0/ 4 | 5 | - parrot-small.jpg 6 | https://storage.googleapis.com/openimages/web/visualizer/index.html?set=train&c=%2Fm%2F0gv1x&id=0f3ebab958f44f5f&type=detection` -------------------------------------------------------------------------------- /coral-tflite-delegate/test_model/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/coral-tflite-delegate/test_model/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite -------------------------------------------------------------------------------- /coral-tflite-delegate/test_model/parrot-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/coral-tflite-delegate/test_model/parrot-small.jpg -------------------------------------------------------------------------------- /coral-tflite-delegate/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "noImplicitAny": true, 5 | "sourceMap": true, 6 | "removeComments": false, 7 | "preserveConstEnums": true, 8 | "declaration": true, 9 | "target": "es6", 10 | "lib": ["esnext", "dom"], 11 | "downlevelIteration": true, 12 | "outDir": "./dist", 13 | "noUnusedLocals": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "alwaysStrict": true, 17 | "noUnusedParameters": false, 18 | "pretty": true, 19 | "noFallthroughCasesInSwitch": true, 20 | "allowUnreachableCode": false, 21 | "experimentalDecorators": true 22 | }, 23 | "include": [ 24 | "src/" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /coral-tflite-delegate/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json" 3 | } 4 | -------------------------------------------------------------------------------- /dockers/sig-ci-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:17 2 | 3 | RUN apt-get update -qqy && apt-get install -qqy python python3 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sig-tfjs", 3 | "version": "0.0.1", 4 | "license": "Apache-2.0", 5 | "scripts": { 6 | "presubmit": "ts-node presubmit.ts" 7 | }, 8 | "devDependencies": { 9 | "@types/node": "~16.10.9", 10 | "@types/shelljs": "~0.8.9", 11 | "fs": "~0.0.1-security", 12 | "jasmine": "~3.10.0", 13 | "shelljs": "0.8.5", 14 | "ts-node": "~10.3.0", 15 | "tslint": "~6.1.3", 16 | "tslint-no-circular-imports": "~0.7.0", 17 | "typescript": "4.4.4" 18 | }, 19 | "resolutions": { 20 | "path-parse": "1.0.7" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /presubmit.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // TODO: change this to only run tests for packages with diffs (refer to tfjs 19 | // repo). 20 | 21 | import * as fs from 'fs'; 22 | import {join} from 'path'; 23 | import * as shell from 'shelljs'; 24 | 25 | // Exit if any commands error. 26 | shell.set('-e'); 27 | process.on('unhandledRejection', e => { 28 | throw e; 29 | }); 30 | 31 | // Read sub dirs that are under the parent dirs below. 32 | const parentDirs = ['.', 'toolings']; 33 | const dirs: string[] = []; 34 | parentDirs.forEach(curParentDir => { 35 | const curDirs = 36 | fs.readdirSync(curParentDir) 37 | .filter(f => fs.statSync(join(curParentDir, f)).isDirectory()) 38 | .filter(f => !f.startsWith('.') && f !== 'node_modules'); 39 | dirs.push(...curDirs.map(curDir => join(curParentDir, curDir))); 40 | }) 41 | 42 | dirs.forEach(dir => { 43 | shell.cd(dir); 44 | 45 | if (!fs.existsSync('./package.json')) { 46 | shell.cd(__dirname); 47 | return; 48 | } 49 | 50 | const packageJSON: {'scripts': {[key: string]: string}} = 51 | JSON.parse(fs.readFileSync('./package.json', {encoding: 'utf-8'})); 52 | console.log(`~~~~~~~~~~~~ Running yarn in ${dir} ~~~~~~~~~~~~`); 53 | shell.exec('yarn'); 54 | 55 | if (packageJSON['scripts']['build-deps'] != null) { 56 | console.log(`~~~~~~~~~~~~ Building deps for ${dir} ~~~~~~~~~~~~`); 57 | shell.exec('yarn build-deps'); 58 | console.log('\n'); 59 | } 60 | 61 | if (packageJSON['scripts']['test-ci'] != null) { 62 | console.log(`~~~~~~~~~~~~ Testing ${dir} ~~~~~~~~~~~~`); 63 | shell.exec('yarn test-ci'); 64 | console.log('\n'); 65 | } else if (packageJSON['scripts']['test'] != null) { 66 | console.log(`~~~~~~~~~~~~ Testing ${dir} ~~~~~~~~~~~~`); 67 | shell.exec('yarn test'); 68 | console.log('\n'); 69 | } 70 | 71 | if (packageJSON['scripts']['lint'] != null) { 72 | console.log(`~~~~~~~~~~~~ Linting ${dir} ~~~~~~~~~~~~`); 73 | shell.exec('yarn lint'); 74 | console.log('\n'); 75 | } 76 | shell.cd(__dirname); 77 | }); 78 | -------------------------------------------------------------------------------- /rfcs/20211020-webnn-delegate-for-tflite-web/class_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/rfcs/20211020-webnn-delegate-for-tflite-web/class_diagram.png -------------------------------------------------------------------------------- /rfcs/20211109-tflite-support-for-node/coral-delegate-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/rfcs/20211109-tflite-support-for-node/coral-delegate-node.png -------------------------------------------------------------------------------- /rfcs/20211109-tflite-support-for-node/mediapipe-face-coral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/rfcs/20211109-tflite-support-for-node/mediapipe-face-coral.png -------------------------------------------------------------------------------- /rfcs/20211109-tflite-support-for-node/mediapipe-face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/rfcs/20211109-tflite-support-for-node/mediapipe-face.png -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/README.md: -------------------------------------------------------------------------------- 1 | # TFLite Node Codelab 2 | 3 | This is a checkpoint for the [Coral Acceleration for TFLite Node][codelab] codelab. This checkpoint runs the Coral and CPU versions of the model and represents what your app will look like after step five. 4 | 5 | In this codelab, you'll build an Electron app that classifies images. Your app will 6 | 7 | * Classify images from the webcam into the categories defined in the model you've trained. 8 | * Use a Coral accelerator to increase performance, if one is available. 9 | * Use WebNN to increase performance, if it is supported on your platform. 10 | 11 | ## What you'll learn 12 | 13 | * How to install and setup the tensorflow.js npm package to run TFLite models in Node.js. 14 | * How to install the Edge TPU runtime library to run models on a Coral device. 15 | * How to accelerate model inference using a Coral edge TPU. 16 | * How to accelerate model inference with WebNN. 17 | 18 | ## Getting started 19 | 20 | To get started, check out the [codelab instructions][codelab]. 21 | 22 | 23 | ## Feedback 24 | 25 | This is a work in progress, if you find a mistake, please [file an issue][git-issue]. 26 | 27 | 28 | ## License 29 | 30 | Copyright 2022 Google, Inc. 31 | 32 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 33 | license agreements. See the NOTICE file distributed with this work for 34 | additional information regarding copyright ownership. The ASF licenses this 35 | file to you under the Apache License, Version 2.0 (the “License”); you may not 36 | use this file except in compliance with the License. You may obtain a copy of 37 | the License at 38 | 39 | http://www.apache.org/licenses/LICENSE-2.0 40 | 41 | Unless required by applicable law or agreed to in writing, software distributed 42 | under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 43 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 44 | specific language governing permissions and limitations under the License. 45 | 46 | 47 | [codelab]: https://codelabs.developers.google.com/tensorflowjs-coral-tflite-node 48 | [git-issue]: https://github.com/tensorflow/sig-tfjs/issues/new 49 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/coral_model/labels.txt: -------------------------------------------------------------------------------- 1 | 0 Person 2 | 1 No Person 3 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/coral_model/model_edgetpu.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node-codelab/coral_inference_working/coral_model/model_edgetpu.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | const {app, BrowserWindow} = require('electron'); 19 | const path = require('path'); 20 | 21 | function createWindow() { 22 | const mainWindow = new BrowserWindow({ 23 | width: 800, 24 | height: 600, 25 | webPreferences: { 26 | nodeIntegration: true, 27 | contextIsolation: false, 28 | }, 29 | }); 30 | 31 | mainWindow.loadFile('index.html'); 32 | } 33 | 34 | app.whenReady().then(() => { 35 | createWindow(); 36 | }); 37 | 38 | app.on('window-all-closed', () => { 39 | app.quit(); 40 | }); 41 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/model/labels.txt: -------------------------------------------------------------------------------- 1 | 0 Person 2 | 1 No Person 3 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/model/model_unquant.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node-codelab/coral_inference_working/model/model_unquant.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_inference_working/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tflite-node-example", 3 | "version": "0.0.1-alpha.1", 4 | "description": "A codelab for tfjs-tflite-node", 5 | "main": "main.js", 6 | "license": "Apache-2.0", 7 | "private": true, 8 | "scripts": { 9 | "start": "electron ." 10 | }, 11 | "devDependencies": { 12 | "electron": "^17.1.2" 13 | }, 14 | "dependencies": { 15 | "@tensorflow/tfjs": "^3.15.0", 16 | "coral-tflite-delegate": "^0.0.1", 17 | "tfjs-tflite-node": "^0.0.2", 18 | "stats.js": "^0.17.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/README.md: -------------------------------------------------------------------------------- 1 | # TFLite Node Movenet 2 | 3 | This is an extension of the starter code from the [Coral Acceleration for TFLite Node][codelab] codelab that adds support for [MoveNet pose estimation](https://coral.ai/models/pose-estimation/). There is no step in the codelab for this code. Its purpose is to show a more complex model. 4 | 5 | The demo will display a warning if no Coral device is found, but it will still work using TFLite on CPU instead. 6 | 7 | ## Run the Demo 8 | 9 | Install dependencies 10 | ```sh 11 | yarn 12 | ``` 13 | 14 | Start Electron 15 | ```sh 16 | yarn start 17 | ``` 18 | 19 | ## Feedback 20 | 21 | This is a work in progress, if you find a mistake, please [file an issue][git-issue]. 22 | 23 | 24 | ## License 25 | 26 | Copyright 2022 Google, Inc. 27 | 28 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 29 | license agreements. See the NOTICE file distributed with this work for 30 | additional information regarding copyright ownership. The ASF licenses this 31 | file to you under the Apache License, Version 2.0 (the “License”); you may not 32 | use this file except in compliance with the License. You may obtain a copy of 33 | the License at 34 | 35 | http://www.apache.org/licenses/LICENSE-2.0 36 | 37 | Unless required by applicable law or agreed to in writing, software distributed 38 | under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 39 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 40 | specific language governing permissions and limitations under the License. 41 | 42 | 43 | [codelab]: https://codelabs.developers.google.com/tensorflowjs-coral-tflite-node 44 | [git-issue]: https://github.com/tensorflow/sig-tfjs/issues/new 45 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | const {app, BrowserWindow} = require('electron'); 19 | const path = require('path'); 20 | 21 | function createWindow() { 22 | const mainWindow = new BrowserWindow({ 23 | width: 800, 24 | height: 600, 25 | webPreferences: { 26 | nodeIntegration: true, 27 | contextIsolation: false, 28 | }, 29 | }); 30 | 31 | mainWindow.loadFile('index.html'); 32 | } 33 | 34 | app.whenReady().then(() => { 35 | createWindow(); 36 | }); 37 | 38 | app.on('window-all-closed', () => { 39 | app.quit(); 40 | }); 41 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/models/README.txt: -------------------------------------------------------------------------------- 1 | These models were downloaded from https://coral.ai/models/pose-estimation/ 2 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/models/movenet_single_pose_thunder_ptq.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node-codelab/coral_movenet/models/movenet_single_pose_thunder_ptq.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/models/movenet_single_pose_thunder_ptq_edgetpu.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node-codelab/coral_movenet/models/movenet_single_pose_thunder_ptq_edgetpu.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/coral_movenet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tflite-node-example", 3 | "version": "0.0.1-alpha.1", 4 | "description": "A codelab for tfjs-tflite-node", 5 | "main": "main.js", 6 | "license": "Apache-2.0", 7 | "private": true, 8 | "scripts": { 9 | "start": "electron ." 10 | }, 11 | "devDependencies": { 12 | "electron": "^18.3.7" 13 | }, 14 | "dependencies": { 15 | "@tensorflow/tfjs": "^3.15.0", 16 | "coral-tflite-delegate": "^0.0.1", 17 | "pixi.js": "^7.0.4", 18 | "stats.js": "^0.17.0", 19 | "tfjs-tflite-node": "^0.0.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/cpu_inference_working/README.md: -------------------------------------------------------------------------------- 1 | # TFLite Node Codelab 2 | 3 | This is a checkpoint for the [Coral Acceleration for TFLite Node][codelab] codelab. This checkpoint runs the CPU version of the model and represents what your app will look like after step four. 4 | 5 | In this codelab, you'll build an Electron app that classifies images. Your app will 6 | 7 | * Classify images from the webcam into the categories defined in the model you've trained. 8 | * Use a Coral accelerator to increase performance, if one is available. 9 | * Use WebNN to increase performance, if it is supported on your platform. 10 | 11 | ## What you'll learn 12 | 13 | * How to install and setup the tensorflow.js npm package to run TFLite models in Node.js. 14 | * How to install the Edge TPU runtime library to run models on a Coral device. 15 | * How to accelerate model inference using a Coral edge TPU. 16 | * How to accelerate model inference with WebNN. 17 | 18 | ## Getting started 19 | 20 | To get started, check out the [codelab instruction][codelab] 21 | 22 | 23 | ## Feedback 24 | 25 | This is a work in progress, if you find a mistake, please [file an issue][git-issue]. 26 | 27 | 28 | ## License 29 | 30 | Copyright 2022 Google, Inc. 31 | 32 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 33 | license agreements. See the NOTICE file distributed with this work for 34 | additional information regarding copyright ownership. The ASF licenses this 35 | file to you under the Apache License, Version 2.0 (the “License”); you may not 36 | use this file except in compliance with the License. You may obtain a copy of 37 | the License at 38 | 39 | http://www.apache.org/licenses/LICENSE-2.0 40 | 41 | Unless required by applicable law or agreed to in writing, software distributed 42 | under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 43 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 44 | specific language governing permissions and limitations under the License. 45 | 46 | 47 | [codelab]: https://codelabs.developers.google.com/tensorflowjs-coral-tflite-node 48 | [git-issue]: https://github.com/tensorflow/sig-tfjs/issues/new 49 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/cpu_inference_working/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/cpu_inference_working/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | const {app, BrowserWindow} = require('electron'); 19 | const path = require('path'); 20 | 21 | function createWindow() { 22 | const mainWindow = new BrowserWindow({ 23 | width: 800, 24 | height: 600, 25 | webPreferences: { 26 | nodeIntegration: true, 27 | contextIsolation: false, 28 | }, 29 | }); 30 | 31 | mainWindow.loadFile('index.html'); 32 | } 33 | 34 | app.whenReady().then(() => { 35 | createWindow(); 36 | }); 37 | 38 | app.on('window-all-closed', () => { 39 | app.quit(); 40 | }); 41 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/cpu_inference_working/model/labels.txt: -------------------------------------------------------------------------------- 1 | 0 Person 2 | 1 No Person 3 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/cpu_inference_working/model/model_unquant.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node-codelab/cpu_inference_working/model/model_unquant.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/cpu_inference_working/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tflite-node-example", 3 | "version": "0.0.1-alpha.1", 4 | "description": "A codelab for tfjs-tflite-node", 5 | "main": "main.js", 6 | "license": "Apache-2.0", 7 | "private": true, 8 | "scripts": { 9 | "start": "electron ." 10 | }, 11 | "devDependencies": { 12 | "electron": "^22.0.0" 13 | }, 14 | "dependencies": { 15 | "@tensorflow/tfjs": "^3.15.0", 16 | "tfjs-tflite-node": "^0.0.2", 17 | "stats.js": "^0.17.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/README.md: -------------------------------------------------------------------------------- 1 | # TFLite Node Codelab 2 | 3 | These are the starter files needed for the 4 | [Coral Acceleration for TFLite Node][codelab] codelab. 5 | 6 | In this codelab, you'll build an Electron app that classifies images. Your app will 7 | 8 | * Classify images from the webcam into the categories defined in the model you've trained. 9 | * Use a Coral accelerator to increase performance, if one is available. 10 | * Use WebNN to increase performance, if it is supported on your platform. 11 | 12 | ## What you'll learn 13 | 14 | * How to install and setup the tensorflow.js npm package to run TFLite models in Node.js. 15 | * How to install the Edge TPU runtime library to run models on a Coral device. 16 | * How to accelerate model inference using a Coral edge TPU. 17 | * How to accelerate model inference with WebNN. 18 | 19 | ## Getting started 20 | 21 | To get started, check out the [codelab instructions][codelab]. 22 | 23 | 24 | ## Feedback 25 | 26 | This is a work in progress, if you find a mistake, please [file an issue][git-issue]. 27 | 28 | 29 | ## License 30 | 31 | Copyright 2022 Google, Inc. 32 | 33 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 34 | license agreements. See the NOTICE file distributed with this work for 35 | additional information regarding copyright ownership. The ASF licenses this 36 | file to you under the Apache License, Version 2.0 (the “License”); you may not 37 | use this file except in compliance with the License. You may obtain a copy of 38 | the License at 39 | 40 | http://www.apache.org/licenses/LICENSE-2.0 41 | 42 | Unless required by applicable law or agreed to in writing, software distributed 43 | under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 44 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 45 | specific language governing permissions and limitations under the License. 46 | 47 | 48 | [codelab]: https://codelabs.developers.google.com/tensorflowjs-coral-tflite-node 49 | [git-issue]: https://github.com/tensorflow/sig-tfjs/issues/new 50 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/coral_model/README.md: -------------------------------------------------------------------------------- 1 | # Coral Model Directory 2 | 3 | Put your Coral model files here. 4 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | const {app, BrowserWindow} = require('electron'); 19 | const path = require('path'); 20 | 21 | function createWindow() { 22 | const mainWindow = new BrowserWindow({ 23 | width: 800, 24 | height: 600, 25 | webPreferences: { 26 | nodeIntegration: true, 27 | contextIsolation: false, 28 | }, 29 | }); 30 | 31 | mainWindow.loadFile('index.html'); 32 | } 33 | 34 | app.whenReady().then(() => { 35 | createWindow(); 36 | }); 37 | 38 | app.on('window-all-closed', () => { 39 | app.quit(); 40 | }); 41 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/model/README.md: -------------------------------------------------------------------------------- 1 | # Model Directory 2 | 3 | Put your TFLite model files from Teachable Machine here. 4 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tflite-node-example", 3 | "version": "0.0.1-alpha.1", 4 | "description": "A codelab for tfjs-tflite-node", 5 | "main": "main.js", 6 | "license": "Apache-2.0", 7 | "private": true, 8 | "scripts": { 9 | "start": "electron ." 10 | }, 11 | "devDependencies": { 12 | "electron": "^22.0.0" 13 | }, 14 | "dependencies": { 15 | "@tensorflow/tfjs": "^3.15.0", 16 | "stats.js": "^0.17.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/starter_code/renderer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // CODELAB part 1: Import tfjs-tflite-node. 19 | const tf = require('@tensorflow/tfjs'); 20 | // CODELAB part 2: Import the delegate here. 21 | const fs = require('fs'); 22 | const Stats = require('stats.js'); 23 | 24 | async function getWebcam() { 25 | const webcam = document.createElement('video'); 26 | webcam.width = 224; 27 | webcam.height = 224; 28 | const stream = await navigator.mediaDevices.getUserMedia({ 29 | audio: false, 30 | video: { 31 | mandatory: { 32 | minHeight: webcam.height, 33 | minWidth: webcam.width, 34 | maxHeight: webcam.height, 35 | maxWidth: webcam.width, 36 | } 37 | } 38 | }); 39 | // Flip the image so the video looks like a mirror. 40 | webcam.style.transform = 'scaleX(-1)'; 41 | webcam.srcObject = stream; 42 | webcam.play(); 43 | return webcam; 44 | } 45 | 46 | async function main() { 47 | const stats = new Stats(); 48 | document.body.appendChild(stats.dom); 49 | 50 | const webcam = await getWebcam(); 51 | document.body.appendChild(webcam); 52 | 53 | // For displaying results 54 | const resultHeader = document.createElement('h1'); 55 | resultHeader.innerHTML = 'Classification: '; 56 | document.body.appendChild(resultHeader); 57 | 58 | const resultList = document.createElement('ul'); 59 | document.body.appendChild(resultList); 60 | 61 | function showPrediction(data, labels) { 62 | resultList.innerHTML = ''; // Clear the list 63 | for (let i = 0; i < data.length; i++) { 64 | const percent = data[i].toFixed(1); 65 | const resultText = `${labels[i]}: ${percent}`; 66 | const result = document.createElement('li'); 67 | result.innerHTML = resultText; 68 | resultList.appendChild(result); 69 | } 70 | } 71 | 72 | // CODELAB part 1: Load the model here. 73 | // CODELAB part 2: Load the delegate model here. 74 | // CODELAB part 1: Set up tf.data.webcam here. 75 | // CODELAB part 2: Create the delegate button here. 76 | 77 | async function run() { 78 | // CODELAB part 1: Capture webcam frames here. 79 | tf.tidy(() => { 80 | // CODELAB part 1: Preprocess webcam frames here. 81 | // CODELAB part 2: Check whether to use the delegate here. 82 | // CODELAB part 1: Run the model and display the results here. 83 | }); 84 | // CODELAB part 1: Dispose webcam frames here. 85 | requestAnimationFrame(run); 86 | } 87 | 88 | run(); 89 | } 90 | 91 | main(); 92 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/webnn_inference_working/README.md: -------------------------------------------------------------------------------- 1 | # TFLite Node Codelab 2 | 3 | This is a checkpoint for the [WebNN Acceleration for TFLite Node][codelab] codelab. This checkpoint runs the CPU version of the model and represents what your app will look like after step five. 4 | 5 | In this codelab, you'll build an Electron app that classifies images. Your app will 6 | 7 | * Classify images from the webcam into the categories defined in the model you've trained. 8 | * Use WebNN to increase performance, if it is supported on your platform. 9 | 10 | ## What you'll learn 11 | 12 | * How to install and setup the tensorflow.js npm package to run TFLite models in Node.js. 13 | * How to accelerate model inference with WebNN. 14 | 15 | ## Getting started 16 | 17 | To get started, check out the [codelab instructions][codelab]. 18 | 19 | 20 | ## Feedback 21 | 22 | This is a work in progress, if you find a mistake, please [file an issue][git-issue]. 23 | 24 | 25 | ## License 26 | 27 | Copyright 2022 Google, Inc. 28 | 29 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 30 | license agreements. See the NOTICE file distributed with this work for 31 | additional information regarding copyright ownership. The ASF licenses this 32 | file to you under the Apache License, Version 2.0 (the “License”); you may not 33 | use this file except in compliance with the License. You may obtain a copy of 34 | the License at 35 | 36 | http://www.apache.org/licenses/LICENSE-2.0 37 | 38 | Unless required by applicable law or agreed to in writing, software distributed 39 | under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR 40 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 41 | specific language governing permissions and limitations under the License. 42 | 43 | 44 | [codelab]: https://codelabs.developers.google.com/tensorflowjs-coral-tflite-node 45 | [git-issue]: https://github.com/tensorflow/sig-tfjs/issues/new 46 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/webnn_inference_working/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/webnn_inference_working/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | const {app, BrowserWindow} = require('electron'); 19 | const path = require('path'); 20 | 21 | function createWindow() { 22 | const mainWindow = new BrowserWindow({ 23 | width: 800, 24 | height: 600, 25 | webPreferences: { 26 | nodeIntegration: true, 27 | contextIsolation: false, 28 | }, 29 | }); 30 | 31 | mainWindow.loadFile('index.html'); 32 | } 33 | 34 | app.whenReady().then(() => { 35 | createWindow(); 36 | }); 37 | 38 | app.on('window-all-closed', () => { 39 | app.quit(); 40 | }); 41 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/webnn_inference_working/model/labels.txt: -------------------------------------------------------------------------------- 1 | 0 Person 2 | 1 No Person 3 | -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/webnn_inference_working/model/model_unquant.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node-codelab/webnn_inference_working/model/model_unquant.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node-codelab/webnn_inference_working/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tflite-node-example", 3 | "version": "0.0.1-alpha.1", 4 | "description": "A codelab for tfjs-tflite-node", 5 | "main": "main.js", 6 | "license": "Apache-2.0", 7 | "private": true, 8 | "scripts": { 9 | "start": "electron ." 10 | }, 11 | "devDependencies": { 12 | "electron": "^17.1.2" 13 | }, 14 | "dependencies": { 15 | "@tensorflow/tfjs": "^3.15.0", 16 | "stats.js": "^0.17.0", 17 | "tfjs-tflite-node": "^0.0.2", 18 | "webnn-tflite-delegate": "^0.0.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tfjs-tflite-node/.npmignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | test_data/ 4 | yarn-error.log -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/darwin_arm64/libexternal_delegate_obj.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/darwin_arm64/libexternal_delegate_obj.dylib -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/darwin_arm64/libtensorflowlite_c.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/darwin_arm64/libtensorflowlite_c.dylib -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/include/tensorflow/lite/delegates/external/external_delegate.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. 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 | #ifndef TENSORFLOW_LITE_DELEGATES_EXTERNAL_EXTERNAL_DELEGATE_H_ 17 | #define TENSORFLOW_LITE_DELEGATES_EXTERNAL_EXTERNAL_DELEGATE_H_ 18 | 19 | #include "tensorflow/lite/c/common.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif // __cplusplus 24 | 25 | // TfLiteExternalDelegateOptions is a structure of key/value options to create 26 | // an external delegate. 27 | const int kMaxOptions = 256; 28 | typedef struct TfLiteExternalDelegateOptions { 29 | const char* lib_path; 30 | int count; 31 | const char* keys[kMaxOptions]; 32 | const char* values[kMaxOptions]; 33 | TfLiteStatus (*insert)(TfLiteExternalDelegateOptions* options, 34 | const char* key, const char* value); 35 | } TfLiteExternalDelegateOptions; 36 | 37 | // Populates TfLiteExternalDelegateOptions with the given shared library path. 38 | TfLiteExternalDelegateOptions TfLiteExternalDelegateOptionsDefault( 39 | const char* lib_path); 40 | 41 | // Creates a new delegate instance that need to be destroyed with 42 | // `TfLiteExternalDelegateDelete` when delegate is no longer used by TFLite. 43 | TfLiteDelegate* TfLiteExternalDelegateCreate( 44 | const TfLiteExternalDelegateOptions* options); 45 | 46 | // Destroys a delegate created with `TfLiteExternalDelegateCreate` call. 47 | void TfLiteExternalDelegateDelete(TfLiteDelegate* delegate); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif // __cplusplus 52 | 53 | #endif // TENSORFLOW_LITE_DELEGATES_EXTERNAL_EXTERNAL_DELEGATE_H_ 54 | -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/linux_amd64/libexternal_delegate_obj.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/linux_amd64/libexternal_delegate_obj.so -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/linux_amd64/libtensorflowlite_c.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/linux_amd64/libtensorflowlite_c.so -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/linux_arm64/libexternal_delegate_obj.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/linux_arm64/libexternal_delegate_obj.so -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/linux_arm64/libtensorflowlite_c.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/linux_arm64/libtensorflowlite_c.so -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/windows_amd64/external_delegate_obj.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/windows_amd64/external_delegate_obj.dll -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/windows_amd64/external_delegate_obj.dll.if.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/windows_amd64/external_delegate_obj.dll.if.lib -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/windows_amd64/tensorflowlite_c.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/windows_amd64/tensorflowlite_c.dll -------------------------------------------------------------------------------- /tfjs-tflite-node/cc_deps/windows_amd64/tensorflowlite_c.dll.if.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/cc_deps/windows_amd64/tensorflowlite_c.dll.if.lib -------------------------------------------------------------------------------- /tfjs-tflite-node/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_files": [ 3 | "dist/**/*_test.js" 4 | ], 5 | "env": { 6 | "stopSpecOnExpectationFailure": false, 7 | "random": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tfjs-tflite-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tflite-node", 3 | "version": "0.0.1-alpha.1", 4 | "description": "TFLite NodeJS support for TensorFlow.js", 5 | "main": "dist/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/tensorflow/tfjs.git", 9 | "directory": "tfjs-tflite-node" 10 | }, 11 | "license": "Apache-2.0", 12 | "scripts": { 13 | "build": "node-gyp rebuild && tsc", 14 | "test-dev": "jasmine --config=jasmine.json", 15 | "test": "yarn build && yarn test-dev", 16 | "lint": "tslint -p . -t verbose" 17 | }, 18 | "dependencies": { 19 | "@tensorflow/tfjs-tflite": "^0.0.1-alpha.8", 20 | "bindings": "^1.5.0", 21 | "node-addon-api": "^4.3.0", 22 | "node-fetch": "2" 23 | }, 24 | "devDependencies": { 25 | "@tensorflow/tfjs-backend-cpu": "^3.15.0", 26 | "@tensorflow/tfjs-core": "^3.15.0", 27 | "@types/jasmine": "^4.0.0", 28 | "@types/node": "^17.0.21", 29 | "@types/node-fetch": "2.x", 30 | "jasmine": "^4.0.2", 31 | "jpeg-js": "^0.4.3", 32 | "node-gyp": "^8.4.1", 33 | "tslint": "^6.1.3", 34 | "tslint-no-circular-imports": "^0.7.0", 35 | "typescript": "^4.5.4" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tfjs-tflite-node/src/delegate_plugin.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // TODO(mattsoulanille): Move this to @tensorflow/tfjs-tflite 19 | /** 20 | * Represents a TFLite delegate that can be passed as an option to the 21 | * loadTFLitemodel function. 22 | * @example 23 | * // Load the Coral delegate 24 | * const coralDelegate: TFLiteDelegatePlugin = new CoralDelegate(); 25 | * // Load a model with the delegate registered. 26 | * const model = loadTFLiteModel('./model.tflite', { 27 | * delegates: [coralDelegate], 28 | * }); 29 | */ 30 | export interface TFLiteDelegatePlugin { 31 | readonly name: string; 32 | readonly tfliteVersion: string; 33 | readonly options: Array<[string, string]>; 34 | readonly node?: { 35 | path: string; 36 | }; 37 | readonly browser?: { 38 | url: string; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /tfjs-tflite-node/test_data/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Open Images Dataset V5. 2 | License: Attribution 2.0 Generic (CC BY 2.0) 3 | URL: https://creativecommons.org/licenses/by/2.0/ 4 | 5 | - parrot-small.jpg 6 | https://storage.googleapis.com/openimages/web/visualizer/index.html?set=train&c=%2Fm%2F0gv1x&id=0f3ebab958f44f5f&type=detection` -------------------------------------------------------------------------------- /tfjs-tflite-node/test_data/mobilenet_v2_1.0_224_inat_bird_quant.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/test_data/mobilenet_v2_1.0_224_inat_bird_quant.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node/test_data/parrot-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/test_data/parrot-small.jpg -------------------------------------------------------------------------------- /tfjs-tflite-node/test_data/teachable_machine_float.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/tfjs-tflite-node/test_data/teachable_machine_float.tflite -------------------------------------------------------------------------------- /tfjs-tflite-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "noImplicitAny": true, 5 | "sourceMap": true, 6 | "removeComments": false, 7 | "preserveConstEnums": true, 8 | "declaration": true, 9 | "target": "es6", 10 | "lib": ["esnext", "dom"], 11 | "downlevelIteration": true, 12 | "outDir": "./dist", 13 | "noUnusedLocals": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "alwaysStrict": true, 17 | "noUnusedParameters": false, 18 | "pretty": true, 19 | "noFallthroughCasesInSwitch": true, 20 | "allowUnreachableCode": false, 21 | "experimentalDecorators": true 22 | }, 23 | "include": [ 24 | "src/" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tfjs-tflite-node/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json" 3 | } 4 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.scss] 15 | quote_type = single 16 | 17 | [*.md] 18 | max_line_length = off 19 | trim_trailing_whitespace = false 20 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | 16 | # IDEs and editors 17 | /.idea 18 | .project 19 | .classpath 20 | .c9/ 21 | *.launch 22 | .settings/ 23 | *.sublime-workspace 24 | 25 | # IDE - VSCode 26 | .vscode/* 27 | !.vscode/settings.json 28 | !.vscode/tasks.json 29 | !.vscode/launch.json 30 | !.vscode/extensions.json 31 | .history/* 32 | 33 | # misc 34 | /.sass-cache 35 | /connect.lock 36 | /coverage 37 | /libpeerconnection.log 38 | npm-debug.log 39 | yarn-error.log 40 | testem.log 41 | /typings 42 | /.firebase 43 | /.angular 44 | 45 | # System Files 46 | .DS_Store 47 | Thumbs.db 48 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "stylelint-config-standard-scss", 4 | "stylelint-config-rational-order" 5 | ], 6 | "plugins": ["stylelint-order", "stylelint-scss"], 7 | "overrides": [ 8 | { 9 | "files": ["**/*.scss"], 10 | "customSyntax": "postcss-scss" 11 | } 12 | ], 13 | "ignoreFiles": ["src/theme.scss", "node_modules/**/*.*"], 14 | "rules": { 15 | "string-quotes": "single", 16 | "selector-pseudo-element-no-unknown": [true, { 17 | "ignorePseudoElements": ["ng-deep"] 18 | }] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/README.md: -------------------------------------------------------------------------------- 1 | # TFJS Debugger 2 | 3 | *Work in progress* 4 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "site": "tfjs-debugger", 4 | "public": "dist", 5 | "headers": [{ 6 | "source": "**", 7 | "headers": [ 8 | { 9 | "key": "Cross-Origin-Embedder-Policy", 10 | "value": "require-corp" 11 | }, 12 | { 13 | "key": "Cross-Origin-Opener-Policy", 14 | "value": "same-origin" 15 | } 16 | ] 17 | }] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/karma.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // Karma configuration file, see link for more information 19 | // https://karma-runner.github.io/1.0/config/configuration-file.html 20 | 21 | module.exports = function (config) { 22 | config.set({ 23 | basePath: '', 24 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 25 | plugins: [ 26 | require('karma-jasmine'), 27 | require('karma-chrome-launcher'), 28 | require('karma-jasmine-html-reporter'), 29 | require('karma-coverage'), 30 | require('@angular-devkit/build-angular/plugins/karma') 31 | ], 32 | client: { 33 | jasmine: { 34 | // you can add configuration options for Jasmine here 35 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 36 | // for example, you can disable the random execution with `random: false` 37 | // or set a specific seed with `seed: 4321` 38 | }, 39 | clearContext: false // leave Jasmine Spec Runner output visible in browser 40 | }, 41 | jasmineHtmlReporter: { 42 | suppressAll: true // removes the duplicated traces 43 | }, 44 | coverageReporter: { 45 | dir: require('path').join(__dirname, './coverage/tfjs-debugger'), 46 | subdir: '.', 47 | reporters: [ 48 | { type: 'html' }, 49 | { type: 'text-summary' } 50 | ] 51 | }, 52 | reporters: ['progress', 'kjhtml'], 53 | port: 9876, 54 | colors: true, 55 | logLevel: config.LOG_INFO, 56 | autoWatch: true, 57 | browsers: ['Chrome'], 58 | singleRun: false, 59 | restartOnFileChange: true 60 | }); 61 | }; 62 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-debugger", 3 | "version": "0.0.1", 4 | "license": "Apache-2.0", 5 | "private": true, 6 | "dependencies": { 7 | "@angular/animations": "~13.0.0", 8 | "@angular/cdk": "~13.0.0", 9 | "@angular/common": "~13.0.0", 10 | "@angular/compiler": "~13.0.0", 11 | "@angular/core": "~13.0.0", 12 | "@angular/forms": "~13.0.0", 13 | "@angular/material": "~13.0.0", 14 | "@angular/platform-browser": "~13.0.0", 15 | "@angular/platform-browser-dynamic": "~13.0.0", 16 | "@angular/router": "~13.0.0", 17 | "@ngrx/effects": "~13.0.2", 18 | "@ngrx/store": "~13.0.2", 19 | "@ngrx/router-store": "~13.0.2", 20 | "@ngrx/store-devtools": "~13.0.2", 21 | "@tensorflow/tfjs-converter": "^3.13.0", 22 | "d3": "^7.3.0", 23 | "dagre": "^0.8.5", 24 | "dateformat": "~5.0.2", 25 | "rxjs": "~7.4.0", 26 | "three": "^0.137.5", 27 | "troika-three-text": "^0.45.0", 28 | "tslib": "^2.3.0", 29 | "zone.js": "~0.11.4" 30 | }, 31 | "peerDependencies": {}, 32 | "devDependencies": { 33 | "@angular-devkit/build-angular": "~13.0.1", 34 | "@angular/animation": "~4.0.0-beta.8", 35 | "@angular/cli": "~13.0.1", 36 | "@angular/compiler-cli": "~13.0.0", 37 | "@types/jasmine": "~3.8.0", 38 | "@types/d3": "^7.1.0", 39 | "@types/dagre": "^0.7.46", 40 | "@types/dateformat": "~5.0.0", 41 | "@types/node": "^12.11.1", 42 | "@types/three": "0.137.0", 43 | "clang-format": "~1.5.0", 44 | "jasmine-core": "~3.8.0", 45 | "karma": "~6.3.16", 46 | "karma-browserstack-launcher": "~1.6.0", 47 | "karma-chrome-launcher": "~3.1.0", 48 | "karma-coverage": "~2.0.3", 49 | "karma-jasmine": "~4.0.0", 50 | "karma-jasmine-html-reporter": "~1.7.0", 51 | "postcss": "^8.3.11", 52 | "stylelint": "^14.0.1", 53 | "stylelint-order": "^5.0.0", 54 | "stylelint-config-standard-scss": "^2.0.1", 55 | "stylelint-config-rational-order": "^0.1.2", 56 | "stylelint-scss": "^4.0.0", 57 | "tslint": "~6.1.3", 58 | "typescript": "~4.4.4" 59 | }, 60 | "scripts": { 61 | "ng": "ng", 62 | "start": "ng serve", 63 | "build": "ng build", 64 | "watch": "ng build --watch --configuration development", 65 | "lint": "tslint -p . -t verbose", 66 | "test": "ng test", 67 | "test-headless": "ng test --browsers=ChromeHeadless", 68 | "test-ci": "ng test --karma-config karma-ci.conf.js", 69 | "deploy-firebase": "./scripts/deploy-to-firebase.sh", 70 | "deploy-firebase-dev": "./scripts/deploy-to-firebase.sh --dev" 71 | }, 72 | "resolutions": { 73 | "set-value": "^4.0.1", 74 | "trim-newlines": "^3.0.1", 75 | "glob-parent": "^5.1.2", 76 | "trim": "^0.0.3", 77 | "yargs-parser": "^13.1.2", 78 | "ansi-regex": "^5.0.1" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/scripts/deploy-to-firebase.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2021 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | # Deploy content in e2e/benchmarks to firebase hosting. 18 | 19 | # Halt if a single command errors 20 | set -e 21 | 22 | PROJECT="jstensorflow" 23 | 24 | if [[ "$1" == "--dev" ]]; then 25 | # Deploy to the preview channel which will expire in 14 days. 26 | # 27 | # Use the second command line parameter as the feature name which will be 28 | # part of the preview URL. Use the current date+time as fallback. 29 | feature_name="${2:-$(date '+%Y%m%d-%H%M%S')}" 30 | firebase hosting:channel:deploy \ 31 | "${feature_name}" \ 32 | --only tfjs-debugger \ 33 | --project ${PROJECT} \ 34 | --expires 14d 35 | else 36 | firebase deploy \ 37 | --only hosting:tfjs-debugger \ 38 | --project ${PROJECT} 39 | fi 40 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/app/app.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/app/app.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../variables.scss' as var; 19 | 20 | $error-msg-container-width: 400px; 21 | 22 | .container { 23 | position: relative; 24 | display: flex; 25 | flex-direction: column; 26 | height: 100%; 27 | overflow: hidden; 28 | 29 | .content { 30 | display: flex; 31 | flex-grow: 1; 32 | overflow: hidden; 33 | } 34 | 35 | error-panel { 36 | position: absolute; 37 | bottom: var.$spacing-6x; 38 | left: calc(50% - $error-msg-container-width / 2); 39 | z-index: 300; 40 | width: $error-msg-container-width; 41 | } 42 | 43 | run-progress-overlay { 44 | z-index: 200; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {TestBed} from '@angular/core/testing'; 19 | import {StoreModule} from '@ngrx/store'; 20 | 21 | import {mainReducer} from '../store/reducers'; 22 | 23 | import {AppComponent} from './app.component'; 24 | 25 | describe('AppComponent', () => { 26 | beforeEach(async () => { 27 | await TestBed 28 | .configureTestingModule({ 29 | declarations: [AppComponent], 30 | imports: [ 31 | StoreModule.forRoot({ 32 | main: mainReducer, 33 | }), 34 | ], 35 | }) 36 | .compileComponents(); 37 | }); 38 | 39 | it('should create the app', () => { 40 | const fixture = TestBed.createComponent(AppComponent); 41 | const app = fixture.componentInstance; 42 | expect(app).toBeTruthy(); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/app/app.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; 19 | import {Store} from '@ngrx/store'; 20 | 21 | import {fetchTfjsReleases} from '../store/actions'; 22 | import {AppState} from '../store/state'; 23 | 24 | @Component({ 25 | selector: 'app-root', 26 | templateUrl: './app.component.html', 27 | styleUrls: ['./app.component.scss'], 28 | changeDetection: ChangeDetectionStrategy.OnPush, 29 | }) 30 | export class AppComponent implements OnInit { 31 | constructor( 32 | private readonly store: Store, 33 | ) {} 34 | 35 | ngOnInit() { 36 | // Start fetching TFJS releases. 37 | this.store.dispatch(fetchTfjsReleases()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/common/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ModelGraph, ModelGraphLayout} from '../data_model/run_results'; 19 | 20 | /** URL parameter keys. */ 21 | export enum UrlParamKey { 22 | SELECTED_MODEL_TYPE_ID = 'mid', 23 | TFJS_MODEL_URL = 'tfjsmu', 24 | SELECTED_INPUT_TYPE_ID = 'iid', 25 | SELECTED_BACKEND_ID = 'bi', 26 | SELECTED_BACKEND_VERSION = 'bv', 27 | } 28 | 29 | /** Valid config index. */ 30 | export type ConfigIndex = 0|1; 31 | 32 | /** Message sent between main app and layout worker. */ 33 | export interface WorkerMessage { 34 | cmd: WorkerCommand; 35 | } 36 | 37 | export interface LayoutRequest extends WorkerMessage { 38 | configIndex: number; 39 | /** The model graph to calculate layout for. */ 40 | modelGraph: ModelGraph; 41 | } 42 | 43 | export interface LayoutResponse extends WorkerMessage { 44 | configIndex: number; 45 | /** The layout result. */ 46 | modelGraphLayout: ModelGraphLayout; 47 | } 48 | 49 | /** Possible commands for the msg. */ 50 | export enum WorkerCommand { 51 | LAYOUT = 'layout', 52 | LAYOUT_RESULT = 'layout_result', 53 | } 54 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/common/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {UrlParamKey} from './types'; 19 | 20 | const CONFIG_INDEX_SEP = '__'; 21 | 22 | /** 23 | * A helper function to append config index (0 or 1) to the given url parameter 24 | * key. 25 | */ 26 | export function appendConfigIndexToKey(paramKey: UrlParamKey, index: number) { 27 | return `${paramKey}${CONFIG_INDEX_SEP}${index}`; 28 | } 29 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/app_bar/app_bar.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 |
20 | 21 |
TFJS Debugger
22 |
23 | 24 | 25 |
27 | 32 |
33 |
34 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/app_bar/app_bar.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | display: flex; 22 | align-items: center; 23 | justify-content: space-between; 24 | height: 64px; 25 | padding: 0 var.$spacing-3x; 26 | overflow: hidden; 27 | border-bottom: 1px solid var.$grey-200; 28 | 29 | .app-title-container { 30 | display: flex; 31 | align-items: center; 32 | height: 100%; 33 | 34 | .icon { 35 | width: 24px; 36 | margin-right: var.$spacing-3x; 37 | } 38 | 39 | .title { 40 | color: var.$grey-800; 41 | font-weight: 700; 42 | font-size: var.$font-size-large; 43 | text-transform: uppercase; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/app_bar/app_bar.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit} from '@angular/core'; 19 | import {Store} from '@ngrx/store'; 20 | import {ModelTypeId} from 'src/app/data_model/model_type'; 21 | import {triggerRunCurrentConfigs} from 'src/app/store/actions'; 22 | import {selectCurrentConfigs} from 'src/app/store/selectors'; 23 | import {AppState, Configs} from 'src/app/store/state'; 24 | 25 | /** 26 | * The app bar located at the top of the screen that shows the app title and a 27 | * set of action buttons. 28 | */ 29 | @Component({ 30 | selector: 'app-bar', 31 | templateUrl: './app_bar.component.html', 32 | styleUrls: ['./app_bar.component.scss'], 33 | changeDetection: ChangeDetectionStrategy.OnPush, 34 | }) 35 | export class AppBar implements OnInit { 36 | private curConfigs?: Configs; 37 | 38 | constructor( 39 | private readonly changeDetectorRef: ChangeDetectorRef, 40 | private readonly store: Store, 41 | ) {} 42 | 43 | handleClickRun(event: MouseEvent) { 44 | // Don't leave focus on the button. 45 | (event.target as HTMLElement).blur(); 46 | 47 | // Triggers a run for the current configs when the "Run" button is clicked. 48 | this.store.dispatch(triggerRunCurrentConfigs()); 49 | } 50 | 51 | ngOnInit() { 52 | // Stores the current configs when it changes. 53 | this.store.select(selectCurrentConfigs).subscribe(curConfigs => { 54 | this.curConfigs = curConfigs; 55 | this.changeDetectorRef.markForCheck(); 56 | }); 57 | } 58 | 59 | /** 60 | * Returns the tooltip that will be shown when the Run button is disabled to 61 | * give users hint about why the button is disabled (e.g. didn't fill out the 62 | * required fields, etc). 63 | */ 64 | get runButtonDisabledMessage(): string { 65 | if (!this.curConfigs) { 66 | return 'Configs not initialized'; 67 | } 68 | 69 | const config1 = this.curConfigs.config1; 70 | const config2 = this.curConfigs.config2; 71 | 72 | // TODO: add more check conditions. 73 | if (config1.modelType === ModelTypeId.TFJS) { 74 | return (config1.tfjsModelUrl == null || config1.tfjsModelUrl === '') ? 75 | 'TFJS model url required in configuration 1' : 76 | ''; 77 | } 78 | 79 | if (config2.modelType === ModelTypeId.TFJS) { 80 | return (config2.tfjsModelUrl == null || config2.tfjsModelUrl === '') ? 81 | 'TFJS model url required in configuration 2' : 82 | ''; 83 | } 84 | 85 | return ''; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/app_bar/app_bar.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {MatButtonModule} from '@angular/material/button'; 21 | import {MatTooltipModule} from '@angular/material/tooltip'; 22 | 23 | import {AppBar} from './app_bar.component'; 24 | 25 | @NgModule({ 26 | declarations: [ 27 | AppBar, 28 | ], 29 | imports: [ 30 | CommonModule, 31 | MatButtonModule, 32 | MatTooltipModule, 33 | ], 34 | exports: [ 35 | AppBar, 36 | ], 37 | }) 38 | export class AppBarModule { 39 | } 40 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/backend_selector/backend_selector.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 20 | 23 | 25 | {{option.label}} 26 | 27 | 28 | 29 | 30 | 31 |
32 |
Version
33 | 34 |
35 |
36 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/backend_selector/backend_selector.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | mat-form-field { 22 | width: 100%; 23 | } 24 | 25 | .title { 26 | margin-top: var.$spacing-1x; 27 | color: var.$grey-600; 28 | font-size: var.$font-size-smaller; 29 | line-height: 11px; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/backend_selector/backend_selector.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {FormsModule} from '@angular/forms'; 21 | import {MatFormFieldModule} from '@angular/material/form-field'; 22 | import {MatSelectModule} from '@angular/material/select'; 23 | 24 | import {BackendSelector} from './backend_selector.component'; 25 | import {BackendVersionSelector} from './backend_version_selector.component'; 26 | 27 | @NgModule({ 28 | declarations: [ 29 | BackendSelector, 30 | BackendVersionSelector, 31 | ], 32 | imports: [ 33 | CommonModule, 34 | FormsModule, 35 | MatFormFieldModule, 36 | MatSelectModule, 37 | ], 38 | exports: [ 39 | BackendSelector, 40 | ], 41 | }) 42 | export class BackendSelectorModule { 43 | } 44 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/backend_selector/backend_version_selector.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 20 | 21 | 24 | 25 | 26 |
27 |
{{selectedVersion}}
28 |
{{getDate(selectedVersion)}}
29 |
30 |
31 | 32 | 34 | 35 |
36 |
{{release.version}}
37 |
{{release.date}}
38 |
39 |
40 |
41 |
42 |
43 | 44 | 45 | 46 |
47 | Loading... 48 |
49 |
50 |
51 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/backend_selector/backend_version_selector.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | mat-form-field { 22 | width: 100%; 23 | } 24 | 25 | .loading { 26 | margin-top: var.$spacing-1x; 27 | color: var.$grey-400; 28 | font-size: var.$font-size-smaller; 29 | font-style: italic; 30 | } 31 | } 32 | 33 | ::ng-deep .version-item { 34 | display: flex; 35 | justify-content: space-between; 36 | padding-right: 2px; 37 | 38 | .date { 39 | color: var.$grey-500; 40 | font-size: var.$font-size-smaller; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/backend_selector/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {BackendId} from 'src/app/data_model/backend_type'; 19 | 20 | /** An option in the backend selector. */ 21 | export interface BackendOption { 22 | /** This is a number not string. */ 23 | id: BackendId; 24 | label: string; 25 | } 26 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/config_section/config_section.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 |
20 |
Model
21 | 22 |
23 | 24 | 25 |
26 |
27 |
Input
28 | 29 |
30 | 31 | 32 |
33 |
34 |
Backend
35 | 36 |
37 |
38 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/config_section/config_section.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | box-sizing: border-box; 22 | min-height: calc(50% - var.$config-header-height); 23 | padding: var.$spacing-3x var.$spacing-3x; 24 | 25 | .section { 26 | margin-bottom: var.$spacing-5x; 27 | 28 | .title { 29 | font-weight: 500; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/config_section/config_section.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ChangeDetectionStrategy, Component, Input, OnInit} from '@angular/core'; 19 | import {ConfigIndex} from 'src/app/common/types'; 20 | 21 | /** A single configuration in the configs panel. */ 22 | @Component({ 23 | selector: 'config-section', 24 | templateUrl: './config_section.component.html', 25 | styleUrls: ['./config_section.component.scss'], 26 | changeDetection: ChangeDetectionStrategy.OnPush, 27 | }) 28 | export class ConfigSection implements OnInit { 29 | @Input() configIndex!: ConfigIndex; 30 | 31 | constructor() {} 32 | 33 | ngOnInit() { 34 | if (this.configIndex == null) { 35 | throw new Error('configIndex not set'); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/config_section/config_section.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | 21 | import {BackendSelectorModule} from '../backend_selector/backend_selector.module'; 22 | import {InputSelectorModule} from '../input_selector/input_selector.module'; 23 | import {ModelSelectorModule} from '../model_selector/model_selector.module'; 24 | 25 | import {ConfigSection} from './config_section.component'; 26 | 27 | @NgModule({ 28 | declarations: [ 29 | ConfigSection, 30 | ], 31 | imports: [ 32 | BackendSelectorModule, 33 | CommonModule, 34 | ModelSelectorModule, 35 | InputSelectorModule, 36 | ], 37 | exports: [ 38 | ConfigSection, 39 | ] 40 | }) 41 | export class ConfigSectionModule { 42 | } 43 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/configs_panel/configs_panel.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 24 |
25 | Configuration 1 26 |
27 | 28 | 29 | 30 |
31 | Configuration 2 32 |
33 | 34 |
35 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/configs_panel/configs_panel.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | width: 300px; 22 | height: 100%; 23 | overflow-y: auto; 24 | font-size: var.$font-size-small; 25 | background-color: #f3f6fb; 26 | border-right: 1px solid var.$grey-200; 27 | 28 | .config-header { 29 | position: sticky; 30 | top: 0; 31 | z-index: 100; 32 | display: flex; 33 | align-items: center; 34 | height: var.$config-header-height; 35 | padding: 0 var.$spacing-3x; 36 | color: var.$grey-800; 37 | font-weight: 500; 38 | font-size: var.$font-size-normal; 39 | background-color: #e7edf7; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/configs_panel/configs_panel.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; 19 | 20 | /** 21 | * The configs panel located at the left of the screen where users set up 2 22 | * configurations for comparison (or 1 configuration for single-configuration 23 | * mode). 24 | * 25 | * Each configuration section is implemented in the `config-section` component. 26 | */ 27 | @Component({ 28 | selector: 'configs-panel', 29 | templateUrl: './configs_panel.component.html', 30 | styleUrls: ['./configs_panel.component.scss'], 31 | changeDetection: ChangeDetectionStrategy.OnPush, 32 | }) 33 | export class ConfigsPanel implements OnInit { 34 | constructor() {} 35 | 36 | ngOnInit() {} 37 | } 38 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/configs_panel/configs_panel.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | 21 | import {ConfigSectionModule} from '../config_section/config_section.module'; 22 | 23 | import {ConfigsPanel} from './configs_panel.component'; 24 | 25 | @NgModule({ 26 | declarations: [ 27 | ConfigsPanel, 28 | ], 29 | imports: [ 30 | CommonModule, 31 | ConfigSectionModule, 32 | ], 33 | exports: [ 34 | ConfigsPanel, 35 | ] 36 | }) 37 | export class ConfigsPanelModule { 38 | } 39 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/error_panel/error_panel.component.html: -------------------------------------------------------------------------------- 1 | 16 |
17 |
18 | 19 |
20 | error 21 |
22 | {{curErrorMessage!.title}} 23 |
24 |
25 | 26 | 27 |
28 | {{curErrorMessage!.content}} 29 |
30 | 31 | 32 |
33 | 34 | 35 |
36 |
37 | 38 |
39 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/error_panel/error_panel.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables.scss' as var; 19 | 20 | .error-msg-container { 21 | padding: var.$spacing-2x; 22 | background-color: #fdedef; 23 | border: 1px solid #f5d6da; 24 | border-radius: 6px; 25 | box-shadow: var.$card-shadow; 26 | 27 | .title-container { 28 | display: flex; 29 | align-items: center; 30 | margin: var.$spacing-2x 0; 31 | font-weight: 500; 32 | font-size: var.$font-size-normal; 33 | 34 | .mat-icon { 35 | margin-right: var.$spacing-1x; 36 | color: #ef4d61; 37 | } 38 | } 39 | 40 | .content-container { 41 | padding-left: 29px; 42 | font-size: var.$font-size-small; 43 | } 44 | 45 | .buttons-container { 46 | display: flex; 47 | align-items: center; 48 | justify-content: flex-end; 49 | margin-top: var.$spacing-2x; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/error_panel/error_panel.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {animate, style, transition, trigger} from '@angular/animations'; 19 | import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit} from '@angular/core'; 20 | import {Store} from '@ngrx/store'; 21 | import {ErrorMessage} from 'src/app/data_model/misc'; 22 | import {clearErrorMessage} from 'src/app/store/actions'; 23 | import {selectErrorMessage} from 'src/app/store/selectors'; 24 | import {AppState} from 'src/app/store/state'; 25 | 26 | /** A panel showing any errors occurred in the app. */ 27 | @Component({ 28 | selector: 'error-panel', 29 | templateUrl: './error_panel.component.html', 30 | styleUrls: ['./error_panel.component.scss'], 31 | changeDetection: ChangeDetectionStrategy.OnPush, 32 | animations: [ 33 | trigger( 34 | 'errorMessageTrigger', 35 | [ 36 | // Zoom in and fade in the panel when showing it. 37 | transition( 38 | ':enter', 39 | [ 40 | style({ 41 | transform: 'scale(0.6)', 42 | opacity: 0, 43 | }), 44 | animate('200ms ease-out', style({ 45 | transform: 'scale(1)', 46 | opacity: 1, 47 | })), 48 | ]), 49 | // Zoom out and fade out the panel when hiding it. 50 | transition( 51 | ':leave', 52 | [ 53 | animate('150ms ease-in', style({ 54 | transform: 'scale(0.6)', 55 | opacity: 0, 56 | })), 57 | ]), 58 | ]), 59 | ] 60 | }) 61 | export class ErrorPanel implements OnInit { 62 | curErrorMessage?: ErrorMessage; 63 | 64 | constructor( 65 | private readonly changeDetectorRef: ChangeDetectorRef, 66 | private readonly store: Store, 67 | ) {} 68 | 69 | ngOnInit() { 70 | // Show the error message panel when it is set. 71 | this.store.select(selectErrorMessage).subscribe(errorMessage => { 72 | if (!errorMessage) { 73 | this.curErrorMessage = undefined; 74 | } else { 75 | this.curErrorMessage = {...errorMessage}; 76 | } 77 | this.changeDetectorRef.markForCheck(); 78 | }); 79 | } 80 | 81 | dismissErrorMessage() { 82 | this.store.dispatch(clearErrorMessage()); 83 | } 84 | 85 | refresh() { 86 | window.location.reload(); 87 | } 88 | 89 | get hasErrorMessage(): boolean { 90 | return this.curErrorMessage !== undefined; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/error_panel/error_panel.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {MatButtonModule} from '@angular/material/button'; 21 | import {MatIconModule} from '@angular/material/icon'; 22 | 23 | import {ErrorPanel} from './error_panel.component'; 24 | 25 | @NgModule({ 26 | declarations: [ 27 | ErrorPanel, 28 | ], 29 | imports: [ 30 | CommonModule, 31 | MatButtonModule, 32 | MatIconModule, 33 | ], 34 | exports: [ 35 | ErrorPanel, 36 | ] 37 | }) 38 | export class ErrorPanelModule { 39 | } 40 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/graph_panel/graph_panel.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 20 | 21 | 27 |
28 |
29 | 30 |
31 |
32 | navigation 33 |
34 |
35 |
Zoom
36 |
Ctrl+ScrollWheel, or pinch on trackpad
37 |
38 |
39 |
Pan
40 |
41 | Drag the graph, two-finger move on trackpad, or use scroll wheel to pan vertically 42 |
43 |
44 |
45 |
Reset
46 |
The Space key
47 |
48 |
49 | 50 | 51 |
52 |
53 | legends 54 |
55 |
56 |
57 |
Input nodes
58 |
59 |
60 |
61 |
Output nodes
62 |
63 |
64 |
65 |
Operators
66 |
67 |
68 |
69 |
Constants/Weights
70 |
71 |
72 |
73 |
76 | help_outline 77 |
78 |
79 |
80 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/graph_panel/graph_panel.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {MatIconModule} from '@angular/material/icon'; 21 | 22 | import {GraphPanel} from './graph_panel.component'; 23 | 24 | @NgModule({ 25 | declarations: [ 26 | GraphPanel, 27 | ], 28 | imports: [ 29 | CommonModule, 30 | MatIconModule, 31 | ], 32 | exports: [ 33 | GraphPanel, 34 | ], 35 | }) 36 | export class GraphPaneModule { 37 | } 38 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/graph_panel/types.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // Minimum module definition for troika-three-text npm package. 19 | // 20 | // TODO: add proper type definitions. For now, all types are "any". 21 | declare module 'troika-three-text'; 22 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/info_panel/info_panel.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | Info panel 19 |
20 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/info_panel/info_panel.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | display: flex; 22 | align-items: center; 23 | justify-content: center; 24 | width: 300px; 25 | height: 100%; 26 | background-color: var.$grey-50; 27 | border-left: 1px solid var.$grey-200; 28 | } 29 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/info_panel/info_panel.component.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; 19 | 20 | /** 21 | * The info panel located at the right side of the screen. It shows the summary 22 | * of the run and the detailed data for the selected node in the model graph. 23 | */ 24 | @Component({ 25 | selector: 'info-panel', 26 | templateUrl: './info_panel.component.html', 27 | styleUrls: ['./info_panel.component.scss'], 28 | changeDetection: ChangeDetectionStrategy.OnPush, 29 | }) 30 | export class InfoPanel implements OnInit { 31 | constructor() {} 32 | 33 | ngOnInit() {} 34 | } 35 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/info_panel/info_panel.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | 21 | import {InfoPanel} from './info_panel.component'; 22 | 23 | @NgModule({ 24 | declarations: [ 25 | InfoPanel, 26 | ], 27 | imports: [ 28 | CommonModule, 29 | ], 30 | exports: [ 31 | InfoPanel, 32 | ] 33 | }) 34 | export class InfoPanelModule { 35 | } 36 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/input_selector/input_selector.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 20 | 24 | 27 | {{option.label}} 28 | 29 | 30 | 31 |
32 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/input_selector/input_selector.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | mat-form-field { 22 | width: 100%; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/input_selector/input_selector.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {FormsModule} from '@angular/forms'; 21 | import {MatFormFieldModule} from '@angular/material/form-field'; 22 | import {MatSelectModule} from '@angular/material/select'; 23 | 24 | import {InputSelector} from './input_selector.component'; 25 | 26 | @NgModule({ 27 | imports: [ 28 | CommonModule, 29 | FormsModule, 30 | MatFormFieldModule, 31 | MatSelectModule, 32 | ], 33 | declarations: [ 34 | InputSelector, 35 | ], 36 | exports: [ 37 | InputSelector, 38 | ], 39 | }) 40 | export class InputSelectorModule { 41 | } 42 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/input_selector/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {InputTypeId} from 'src/app/data_model/input_type'; 19 | 20 | /** An option in the input selector. */ 21 | export interface InputTypeOption { 22 | /** This is a number not string. */ 23 | id: InputTypeId; 24 | label: string; 25 | disabled?: boolean; 26 | } 27 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/model_selector/model_selector.component.html: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 20 | 24 | 27 | {{option.label}} 28 | 29 | 30 | 31 | 32 | 33 |
35 | 36 | 37 |
38 |
Model url
39 | 40 | 47 | 48 |
49 | 50 |
51 |
52 |
53 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/model_selector/model_selector.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables' as var; 19 | 20 | .container { 21 | .title { 22 | margin-top: var.$spacing-1x; 23 | color: var.$grey-600; 24 | font-size: var.$font-size-smaller; 25 | line-height: 11px; 26 | } 27 | 28 | mat-form-field { 29 | width: 100%; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/model_selector/model_selector.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {FormsModule} from '@angular/forms'; 21 | import {MatFormFieldModule} from '@angular/material/form-field'; 22 | import {MatInputModule} from '@angular/material/input'; 23 | import {MatSelectModule} from '@angular/material/select'; 24 | 25 | import {ModelSelector} from './model_selector.component'; 26 | 27 | @NgModule({ 28 | declarations: [ 29 | ModelSelector, 30 | ], 31 | imports: [ 32 | CommonModule, 33 | FormsModule, 34 | MatFormFieldModule, 35 | MatInputModule, 36 | MatSelectModule, 37 | ], 38 | exports: [ 39 | ModelSelector, 40 | ], 41 | }) 42 | export class ModelSelectorModule { 43 | } 44 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/model_selector/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ModelTypeId} from 'src/app/data_model/model_type'; 19 | 20 | /** An option in the model selector. */ 21 | export interface ModelTypeOption { 22 | /** This is a number not string. */ 23 | id: ModelTypeId; 24 | label: string; 25 | disabled?: boolean; 26 | } 27 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/run_progress_overlay/run_progress_overlay.component.html: -------------------------------------------------------------------------------- 1 | 16 |
17 |
18 |
19 |
20 | 21 | 22 |
23 | 24 |
25 | 26 | 27 |
29 | check_circle_filled 30 |
31 | 32 | 33 |
35 | error_filled 36 |
37 |
38 |
39 |
40 | {{task}} 41 |
42 |
43 |
44 |
45 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/run_progress_overlay/run_progress_overlay.component.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use '../../../variables.scss' as var; 19 | 20 | .container { 21 | position: absolute; 22 | top: 0; 23 | right: 0; 24 | bottom: 0; 25 | left: 0; 26 | display: flex; 27 | flex-direction: column; 28 | align-items: center; 29 | justify-content: center; 30 | background-color: rgb(255 255 255 / 85%); 31 | backdrop-filter: blur(4px); 32 | } 33 | 34 | .tasks-container { 35 | display: flex; 36 | flex-direction: column; 37 | align-items: flex-start; 38 | 39 | .task-row { 40 | display: flex; 41 | justify-content: center; 42 | height: 18px; 43 | line-height: 18px; 44 | 45 | .task-name { 46 | margin-left: var.$spacing-3x; 47 | color: var.$grey-700; 48 | font-weight: 500; 49 | font-size: 13px; 50 | } 51 | 52 | .mat-icon { 53 | width: 16px; 54 | height: 16px; 55 | font-size: 16px; 56 | line-height: 16px; 57 | } 58 | 59 | .success .mat-icon { 60 | color: #0a0; 61 | } 62 | 63 | .failed .mat-icon { 64 | color: #ef4d6a; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/components/run_progress_overlay/run_progress_overlay.module.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {CommonModule} from '@angular/common'; 19 | import {NgModule} from '@angular/core'; 20 | import {MatIconModule} from '@angular/material/icon'; 21 | import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; 22 | 23 | import {RunProgressOverlay} from './run_progress_overlay.component'; 24 | 25 | @NgModule({ 26 | declarations: [RunProgressOverlay], 27 | imports: [ 28 | CommonModule, 29 | MatProgressSpinnerModule, 30 | MatIconModule, 31 | ], 32 | exports: [RunProgressOverlay], 33 | }) 34 | export class RunProgressOverlayModule { 35 | } 36 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/data_model/backend_type.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | /** Backend ids. */ 19 | export enum BackendId { 20 | WEBGL = 'webgl', 21 | WASM = 'wasm', 22 | CPU = 'cpu', 23 | } 24 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/data_model/configuration.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {ModelTypeId} from './model_type'; 19 | 20 | export interface Configuration { 21 | /** The type of the model, e.g. TFJS, TFLite, etc. */ 22 | modelType: ModelTypeId; 23 | 24 | /** The URL of the tfjs model's model.json file. */ 25 | tfjsModelUrl?: string; 26 | } 27 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/data_model/input_type.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | /** Input type ids. */ 19 | export enum InputTypeId { 20 | RANDOM = 'random', 21 | CUSTOM_VALUE = 'custom_value', 22 | IMAGE = 'image', 23 | SAME_AS_CONFIG1 = 'same_as_config1', 24 | } 25 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/data_model/misc.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | /** An error message with title and content. */ 19 | export interface ErrorMessage { 20 | title: string; 21 | content: string; 22 | } 23 | 24 | /** Names of possible tasks in a run. */ 25 | export enum RunTask { 26 | LOAD_TFJS_MODEL1 = 'Load TJFS model in config 1', 27 | LOAD_TFJS_MODEL2 = 'Load TJFS model in config 2', 28 | LAYOUT_AND_RENDER_MODEL_GRAPH = 'Layout and render model graph', 29 | } 30 | 31 | /** Status for a task. */ 32 | export enum TaskStatus { 33 | IN_PROGRESS, 34 | SUCCESS, 35 | FAILED, 36 | } 37 | 38 | /** Status indexed by task names. */ 39 | export type RunStatus = { 40 | [task: string]: TaskStatus 41 | }; 42 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/data_model/model_type.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | /** Model type ids. */ 19 | export enum ModelTypeId { 20 | TFJS = 'tfjs', 21 | TF = 'tf', 22 | TFLITE = 'tflite', 23 | TFJS_CUSTOM_GRAPH = 'tfjs_custom_graph', 24 | SAME_AS_CONFIG1 = 'same_as_config1', 25 | } 26 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/data_model/tfjs_release.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import dateFormat from 'dateformat'; 19 | 20 | /** Stores data for a TFJS release. */ 21 | export interface TfjsRelease { 22 | /** Version string of the release, e.g. 3.12.0 */ 23 | version: string; 24 | 25 | /** Publish date, e.g. 2021-12-08 */ 26 | date: string; 27 | 28 | // Add more fields as needed. 29 | } 30 | 31 | /** Json structure for the content returned by github releases API. */ 32 | export declare interface ReleaseJson { 33 | tag_name: string; 34 | published_at: string; 35 | 36 | // Add more fields as needed. 37 | } 38 | 39 | /** Converts the given release json object to TfjsRelease. */ 40 | export function releaseJsonToTfjsRelease(json: ReleaseJson): TfjsRelease| 41 | undefined { 42 | // Example: 'tfjs-v3.12.0'. 43 | const tagName = json.tag_name; 44 | 45 | // Only keep the main tfjs releases. 46 | if (!tagName.startsWith('tfjs-v') || tagName.startsWith('tfjs-vis')) { 47 | return undefined; 48 | } 49 | 50 | // Remove 'tfjs-v' prefix. 51 | const version = tagName.replace('tfjs-v', ''); 52 | 53 | // Only keep >= 3.x releases. 54 | const majorVersion = Number(version.split('.')[0]); 55 | if (majorVersion < 3) { 56 | return undefined; 57 | } 58 | 59 | // The original date string is in the form of 2021-10-22T02:07:40Z. 60 | // Re-format it to "Fri, Oct 22, 2021". 61 | // 62 | // Prefix "UTC:" in the format string will convert the date to UTC before 63 | // applying the mask. This is needed because the date stored in published_at 64 | // is in UTC not local time. 65 | const date = dateFormat(new Date(json.published_at), 'UTC:ddd, mmm dd, yyyy'); 66 | 67 | return { 68 | version, 69 | date, 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/layout_generator/layout_generator.worker.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as dagre from 'dagre'; 4 | 5 | import {LayoutRequest, LayoutResponse, WorkerCommand, WorkerMessage} from '../common/types'; 6 | import {ModelGraph, ModelGraphLayout, ModelGraphLayoutEdge, ModelGraphNode} from '../data_model/run_results'; 7 | 8 | addEventListener('message', ({data}) => { 9 | const msg = data as WorkerMessage; 10 | switch (msg.cmd) { 11 | case WorkerCommand.LAYOUT: 12 | const req = msg as LayoutRequest; 13 | const layout = layoutModelGraph(req.modelGraph); 14 | const resp: LayoutResponse = { 15 | cmd: WorkerCommand.LAYOUT_RESULT, 16 | configIndex: req.configIndex, 17 | modelGraphLayout: layout, 18 | }; 19 | postMessage(resp); 20 | break; 21 | default: 22 | break; 23 | } 24 | }); 25 | 26 | /** 27 | * Runs dagre to layout the given model graph. The layout result (x and y 28 | * coordinates) will be stored directly inside each ModelGraphNode in 29 | * ModelGraph. 30 | */ 31 | function layoutModelGraph(modelGraph: ModelGraph): ModelGraphLayout { 32 | const graph = new dagre.graphlib.Graph(); 33 | // Separation between nodes. 34 | graph.setGraph({ 35 | nodesep: 20, 36 | ranksep: 40, 37 | // This could make certain layouts more "straight". 38 | // 39 | // See more options here: 40 | // https://github.com/dagrejs/dagre/wiki#configuring-the-layout 41 | align: 'DR', 42 | }); 43 | // We don't need to show edge labels. 44 | graph.setDefaultEdgeLabel(() => ({})); 45 | 46 | // Add all nodes and edges to the dagre graph. 47 | for (const node of Object.values(modelGraph)) { 48 | graph.setNode(node.id, node); 49 | 50 | if (node.inputNodeIds) { 51 | for (const parentNodeId of node.inputNodeIds) { 52 | if (modelGraph[parentNodeId]) { 53 | graph.setEdge(parentNodeId, node.id); 54 | } 55 | } 56 | } 57 | } 58 | 59 | // Layout. 60 | dagre.layout(graph); 61 | 62 | // Gather results. 63 | const nodes = Object.values(modelGraph); 64 | const edges: ModelGraphLayoutEdge[] = []; 65 | for (const edge of graph.edges()) { 66 | edges.push({ 67 | fromNodeId: edge.v, 68 | toNodeId: edge.w, 69 | controlPoints: graph.edge(edge).points, 70 | }); 71 | } 72 | return { 73 | nodes, 74 | edges, 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/services/github_service.ts: -------------------------------------------------------------------------------- 1 | import {HttpClient} from '@angular/common/http'; 2 | import {Injectable} from '@angular/core'; 3 | import {Observable} from 'rxjs'; 4 | 5 | import {ReleaseJson} from '../data_model/tfjs_release'; 6 | 7 | const GITHUB_RELEASES_API_ENDPOINT = 8 | 'https://api.github.com/repos/tensorflow/tfjs/releases'; 9 | 10 | /** Service to interact with github APIs. */ 11 | @Injectable({ 12 | providedIn: 'root', 13 | }) 14 | export class GithubService { 15 | constructor(private http: HttpClient) {} 16 | 17 | fetchTfjsReleases(): Observable { 18 | return this.http.get(GITHUB_RELEASES_API_ENDPOINT); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/services/tfjs_service.ts: -------------------------------------------------------------------------------- 1 | import {HttpClient} from '@angular/common/http'; 2 | import {Injectable} from '@angular/core'; 3 | import {Observable, shareReplay} from 'rxjs'; 4 | 5 | import {ModelJson} from '../data_model/run_results'; 6 | 7 | /** Service for TFJS related tasks. */ 8 | @Injectable({ 9 | providedIn: 'root', 10 | }) 11 | export class TfjsService { 12 | private modelJsonCache: {[url: string]: Observable} = {}; 13 | 14 | constructor(private http: HttpClient) {} 15 | 16 | fetchModelJson(url: string): Observable { 17 | if (!this.modelJsonCache[url]) { 18 | // ShareReplay will return the last emitted value, i.e. the response from 19 | // the http request, without sending the request again. 20 | this.modelJsonCache[url] = 21 | this.http.get(url).pipe(shareReplay(1)); 22 | } 23 | return this.modelJsonCache[url]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/services/url_service.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {Injectable} from '@angular/core'; 19 | import {Params, Router} from '@angular/router'; 20 | 21 | /** 22 | * Service for url related tasks. 23 | */ 24 | @Injectable({ 25 | providedIn: 'root', 26 | }) 27 | export class UrlService { 28 | constructor( 29 | private readonly router: Router, 30 | ) {} 31 | 32 | async updateUrlParameters(params: Params) { 33 | // Wrap router.navigate inside a setTimeout to make sure navigation happens 34 | // with update-to-date parameters. 35 | // 36 | // If router.navigate is called rapidly in succession within a tick without 37 | // using setTimeout, the second call will not have the updated query 38 | // parameters set from the first call. 39 | setTimeout(() => { 40 | return this.router.navigate([], { 41 | queryParams: { 42 | ...params, 43 | }, 44 | queryParamsHandling: 'merge', 45 | }); 46 | }); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/store/effects.ts: -------------------------------------------------------------------------------- 1 | import {HttpErrorResponse} from '@angular/common/http'; 2 | import {Injectable} from '@angular/core'; 3 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 4 | import {of} from 'rxjs'; 5 | import {catchError, map, switchMap} from 'rxjs/operators'; 6 | 7 | import {modelJsonToModelGraph} from '../data_model/run_results'; 8 | import {releaseJsonToTfjsRelease, TfjsRelease} from '../data_model/tfjs_release'; 9 | import {GithubService} from '../services/github_service'; 10 | import {TfjsService} from '../services/tfjs_service'; 11 | 12 | import {DebuggerAction, fetchTfjsModelJson, fetchTfjsModelJsonFail, fetchTfjsModelJsonSuccess, fetchTfjsReleasesFail, fetchTfjsReleasesSuccess} from './actions'; 13 | 14 | /** Effects for github related tasks. */ 15 | @Injectable() 16 | export class GithubEffects { 17 | constructor( 18 | private actions$: Actions, 19 | private githubService: GithubService, 20 | ) {} 21 | 22 | /** Fetch TFJS releaes using GithubService. */ 23 | fetchTfjsReleases$ = createEffect( 24 | () => this.actions$.pipe( 25 | ofType(DebuggerAction.FETCH_TFJS_RELEASES), 26 | switchMap( 27 | () => this.githubService.fetchTfjsReleases().pipe( 28 | map(jsonArray => { 29 | const releases = 30 | jsonArray.map(json => releaseJsonToTfjsRelease(json)) 31 | .filter(release => release != null) as 32 | TfjsRelease[]; 33 | return fetchTfjsReleasesSuccess({releases}); 34 | }), 35 | catchError((error: HttpErrorResponse) => { 36 | return of(fetchTfjsReleasesFail({error})); 37 | }))), 38 | )); 39 | } 40 | 41 | /** Effects for TFJS related tasks. */ 42 | @Injectable() 43 | export class TfjsEffects { 44 | constructor( 45 | private actions$: Actions, 46 | private tfjsService: TfjsService, 47 | ) {} 48 | 49 | /** Fetch TFJS model json file using TfjsService. */ 50 | fetchTfjsModelJson$ = createEffect( 51 | () => this.actions$.pipe( 52 | ofType(fetchTfjsModelJson), 53 | switchMap( 54 | (action) => 55 | this.tfjsService.fetchModelJson(action.url) 56 | .pipe( 57 | map(modelJson => { 58 | const modelGraph = modelJsonToModelGraph(modelJson); 59 | return fetchTfjsModelJsonSuccess( 60 | {configIndex: action.configIndex, modelGraph}); 61 | }), 62 | catchError((error: HttpErrorResponse) => { 63 | return of(fetchTfjsModelJsonFail( 64 | {configIndex: action.configIndex, error})); 65 | }))), 66 | )); 67 | } 68 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/store/selectors.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {getSelectors, RouterReducerState} from '@ngrx/router-store'; 19 | import {createFeatureSelector, createSelector} from '@ngrx/store'; 20 | 21 | import {ConfigIndex, UrlParamKey} from '../common/types'; 22 | import {appendConfigIndexToKey} from '../common/utils'; 23 | 24 | import {AppState} from './state'; 25 | 26 | const selectRouter = createFeatureSelector('router'); 27 | const selectMainState = createFeatureSelector('main'); 28 | const selectQueryParams = getSelectors(selectRouter).selectQueryParams; 29 | 30 | /** 31 | * Selector to select the value for the given url parameter key and config 32 | * index. 33 | */ 34 | export const selectConfigValueFromUrl = 35 | (configIndex: ConfigIndex, paramKey: UrlParamKey) => 36 | createSelector(selectQueryParams, (params) => { 37 | if (!params) { 38 | return undefined; 39 | } 40 | const key = appendConfigIndexToKey(paramKey, configIndex); 41 | return params[key]; 42 | }); 43 | 44 | /** Selector to select the currently loaded TFJS releases. */ 45 | export const selectTfjsReleases = createSelector(selectMainState, (state) => { 46 | return state.tfjsReleases; 47 | }); 48 | 49 | /** Selector to select the current error message. */ 50 | export const selectErrorMessage = createSelector(selectMainState, (state) => { 51 | return state.errorMessage; 52 | }); 53 | 54 | /** Selector to select the configs run trigger. */ 55 | export const selectRunCurrentConfigsTrigger = 56 | createSelector(selectMainState, (state) => { 57 | return state.runCurrentConfigsTrigger; 58 | }); 59 | 60 | /** Selector to select current configs. */ 61 | export const selectCurrentConfigs = createSelector(selectMainState, (state) => { 62 | return state.configs; 63 | }); 64 | 65 | /** Selector to select model graph for the given config index. */ 66 | export const selectModelGraph = (configIndex: ConfigIndex) => 67 | createSelector(selectMainState, (state) => { 68 | if (configIndex === 0) { 69 | return state.runResults.modelGraph1; 70 | } else if (configIndex === 1) { 71 | return state.runResults.modelGraph2; 72 | } 73 | return undefined; 74 | }); 75 | 76 | /** Selector to select run status. */ 77 | export const selectRunStatus = createSelector(selectMainState, (state) => { 78 | return state.runStatus; 79 | }); 80 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/store/state.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {Configuration} from '../data_model/configuration'; 19 | import {ErrorMessage, RunStatus} from '../data_model/misc'; 20 | import {ModelTypeId} from '../data_model/model_type'; 21 | import {RunResults} from '../data_model/run_results'; 22 | import {TfjsRelease} from '../data_model/tfjs_release'; 23 | 24 | export interface Configs { 25 | config1: Configuration; 26 | config2: Configuration; 27 | } 28 | 29 | /** The main app state. */ 30 | export interface AppState { 31 | configs: Configs; 32 | tfjsReleases: TfjsRelease[]; 33 | 34 | /** 35 | * Any new (empty) object that is set to this field will trigger a run for the 36 | * currently stored configs. 37 | */ 38 | runCurrentConfigsTrigger?: {}; 39 | 40 | /** Stores the results for the latest run. */ 41 | runResults: RunResults; 42 | 43 | /** 44 | * Stores the status of various tasks (e.g. loading models, running 45 | * inferences, etc) during a run. 46 | * 47 | * This will mainly be used to render an overlay that shows progress during a 48 | * run. The overlay will be hidden if this value is set to undefined. 49 | */ 50 | runStatus?: RunStatus; 51 | 52 | /** 53 | * The current error message occurred in the app. 54 | * 55 | * A panel with the error message will be displayed from the main app 56 | * component. 57 | */ 58 | errorMessage?: ErrorMessage; 59 | } 60 | 61 | /** The initial app state. */ 62 | export const initialState: AppState = { 63 | configs: { 64 | config1: { 65 | modelType: ModelTypeId.TFJS, 66 | }, 67 | config2: { 68 | modelType: ModelTypeId.SAME_AS_CONFIG1, 69 | } 70 | }, 71 | tfjsReleases: [], 72 | runResults: {}, 73 | }; 74 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/app/store/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {RunStatus, RunTask, TaskStatus} from '../data_model/misc'; 19 | import {ModelTypeId} from '../data_model/model_type'; 20 | 21 | import {Configs} from './state'; 22 | 23 | /** Gets tasks in a run given its configs. */ 24 | export function getRunTasksFromConfigs(configs: Configs): RunTask[] { 25 | // TODO: for now we only handle loading one TFJS model from config1. Add more 26 | // as needed in the future. 27 | if (configs.config1.modelType === ModelTypeId.TFJS && 28 | configs.config2.modelType === ModelTypeId.SAME_AS_CONFIG1) { 29 | return [ 30 | RunTask.LOAD_TFJS_MODEL1, 31 | RunTask.LAYOUT_AND_RENDER_MODEL_GRAPH, 32 | ]; 33 | } 34 | return []; 35 | } 36 | 37 | /** Checks whether all the run tasks are done successfully. */ 38 | export function checkAllTasksDone(runStatus: RunStatus): boolean { 39 | for (const task of Object.keys(runStatus)) { 40 | if (runStatus[task] !== TaskStatus.SUCCESS) { 41 | return false; 42 | } 43 | } 44 | return true; 45 | } 46 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/toolings/tfjs-debugger/src/assets/.gitkeep -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/assets/GoogleSans-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/toolings/tfjs-debugger/src/assets/GoogleSans-Medium.ttf -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/assets/GoogleSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/toolings/tfjs-debugger/src/assets/GoogleSans-Regular.ttf -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | export const environment = { 19 | production: true 20 | }; 21 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // This file can be replaced during build by using the `fileReplacements` array. 19 | // `ng build` replaces `environment.ts` with `environment.prod.ts`. 20 | // The list of file replacements can be found in `angular.json`. 21 | 22 | export const environment = { 23 | production: false 24 | }; 25 | 26 | /* 27 | * For easier debugging in development mode, you can import the following file 28 | * to ignore zone related error stack frames such as `zone.run`, 29 | * `zoneDelegate.invokeTask`. 30 | * 31 | * This import should be commented out in production mode because it will have a 32 | * negative impact on performance if an error is thrown. 33 | */ 34 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 35 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/index.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | TFJS Debugger 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {enableProdMode} from '@angular/core'; 19 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; 20 | 21 | import {AppModule, DevAppModule} from './app/app/app.module'; 22 | import {environment} from './environments/environment'; 23 | 24 | // Load AppModule in production mode. 25 | if (environment.production) { 26 | enableProdMode(); 27 | platformBrowserDynamic().bootstrapModule(AppModule).catch( 28 | err => console.error(err)); 29 | } 30 | // Load DevAppModule in dev mode. 31 | // 32 | // DevAppModule has extra modules (e.g. StoreDevtoolsModule) registered for 33 | // debugging purpose. 34 | else { 35 | platformBrowserDynamic() 36 | .bootstrapModule(DevAppModule) 37 | .catch(err => console.error(err)); 38 | } 39 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/styles.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | @use 'variables' as var; 19 | @use 'theme' as theme; 20 | 21 | body { 22 | height: 100%; 23 | margin: 0; 24 | font-family: var.$font-face; 25 | overscroll-behavior-y: none; 26 | } 27 | 28 | html { 29 | height: 100%; 30 | overscroll-behavior-y: none; 31 | } 32 | 33 | //////////////////////////////////////////////////////////////////////////////// 34 | // Styles that are applied to all elements in the app. 35 | 36 | // Common styles for certain controls. 37 | mat-form-field.mat-form-field-type-mat-select, 38 | mat-form-field.mat-form-field-type-mat-input { 39 | .mat-form-field-wrapper { 40 | padding: 0; 41 | } 42 | } 43 | 44 | // mat-select 45 | mat-form-field.mat-form-field-type-mat-select { 46 | .mat-form-field-infix { 47 | padding-top: 11px; 48 | padding-bottom: 7px; 49 | border-top-width: 0; 50 | } 51 | 52 | .mat-select-arrow-wrapper { 53 | transform: none; 54 | } 55 | } 56 | 57 | mat-select.same-as-config1-selected .mat-select-value-text { 58 | font-style: italic; 59 | } 60 | 61 | // mat-input 62 | mat-form-field.mat-form-field-type-mat-input { 63 | .mat-form-field-infix { 64 | padding-top: 4px; 65 | padding-bottom: 4px; 66 | border-top-width: 0; 67 | } 68 | 69 | .mat-form-field-label { 70 | color: var.$grey-400; 71 | } 72 | 73 | input { 74 | color: var.$grey-800; 75 | } 76 | 77 | .mat-form-field-underline { 78 | bottom: 0; 79 | background-color: var.$grey-300; 80 | } 81 | } 82 | 83 | // mat-option 84 | mat-option.mat-selected { 85 | background: theme.$primary-color !important; 86 | 87 | .mat-option-text { 88 | color: var.$grey-900; 89 | } 90 | } 91 | 92 | .extra-components-container { 93 | margin-top: var.$spacing-2x; 94 | padding-left: 10px; 95 | border-left: 1px solid var.$grey-300; 96 | } 97 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import 'zone.js/testing'; 19 | 20 | import {getTestBed} from '@angular/core/testing'; 21 | import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; 22 | 23 | declare const require: { 24 | context(path: string, deep?: boolean, filter?: RegExp): 25 | {keys(): string[];(id: string): T;}; 26 | }; 27 | 28 | // First, initialize the Angular testing environment. 29 | getTestBed().initTestEnvironment( 30 | BrowserDynamicTestingModule, 31 | platformBrowserDynamicTesting(), 32 | {teardown: {destroyAfterEach: true}}, 33 | ); 34 | 35 | // Then we find all the tests. 36 | const context = require.context('./', true, /\.spec\.ts$/); 37 | // And load the modules. 38 | context.keys().map(context); 39 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/theme.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // Related docs: 19 | // 20 | // https://material.angular.io/guide/theming 21 | // https://material.angular.io/guide/typography 22 | // https://material.io/archive/guidelines/style/color.html#color-color-palette 23 | // https://github.com/angular/components/blob/master/src/material/core/theming/_palette.scss 24 | 25 | @use '@angular/material' as mat; 26 | @use 'variables' as var; 27 | @import '@angular/material/theming'; 28 | 29 | @include mat.core(); 30 | 31 | // Theme colors and font. 32 | $tfjs-debugger-primary: mat.define-palette(mat.$amber-palette, 500); 33 | $tfjs-debugger-accent: mat.define-palette(mat.$blue-grey-palette, 800); 34 | $tfjs-debugger-typography: mat.define-typography-config( 35 | $font-family: var.$font-face, 36 | ); 37 | 38 | // Set up theme. 39 | $tfjs-debugger-theme: mat.define-light-theme( 40 | ( 41 | color: ( 42 | accent: $tfjs-debugger-accent, 43 | primary: $tfjs-debugger-primary, 44 | ), 45 | typography: $tfjs-debugger-typography, 46 | ) 47 | ); 48 | @include mat.all-component-themes($tfjs-debugger-theme); 49 | 50 | // Export theme colors that can be used in components. 51 | $primary-color: mat-color($tfjs-debugger-primary); 52 | $accent-color: mat-color($tfjs-debugger-accent); 53 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/src/variables.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | // Text styles. 19 | $font-face: 'Google Sans', sans-serif; 20 | $font-size-smaller: 12px; 21 | $font-size-small: 13px; 22 | $font-size-normal: 14px; 23 | $font-size-large: 16px; 24 | 25 | // Colors. 26 | $grey-50: #fafafa; 27 | $grey-100: #f5f5f5; 28 | $grey-200: #eee; 29 | $grey-300: #e0e0e0; 30 | $grey-400: #bdbdbd; 31 | $grey-500: #9e9e9e; 32 | $grey-600: #757575; 33 | $grey-700: #616161; 34 | $grey-800: #424242; 35 | $grey-900: #212121; 36 | 37 | // Spacings. 38 | $spacing-1x: 4px; 39 | $spacing-2x: 8px; 40 | $spacing-3x: 12px; 41 | $spacing-4x: 16px; 42 | $spacing-5x: 20px; 43 | $spacing-6x: 24px; 44 | 45 | // Sizes. 46 | $config-header-height: 28px; 47 | 48 | // Shadows 49 | $card-shadow: 0 1.8px 1.8px -13px rgb(0 0 0 / 8%), 50 | 0 14px 14px -13px rgb(0 0 0 / 16%); 51 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "forceConsistentCasingInFileNames": true, 6 | "strict": true, 7 | "noImplicitReturns": true, 8 | "noFallthroughCasesInSwitch": true, 9 | "sourceMap": true, 10 | "declaration": false, 11 | "downlevelIteration": true, 12 | "experimentalDecorators": true, 13 | "moduleResolution": "node", 14 | "importHelpers": true, 15 | "target": "es2017", 16 | "module": "es2020", 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "enableI18nLegacyMessageIdFormat": false, 24 | "strictInjectionParameters": true, 25 | "strictInputAccessModifiers": true, 26 | "strictTemplates": true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine" 7 | ] 8 | }, 9 | "files": [ 10 | "src/test.ts", 11 | "src/polyfills.ts" 12 | ], 13 | "include": [ 14 | "src/**/*.spec.ts", 15 | "src/**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/tsconfig.worker.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/worker", 6 | "lib": [ 7 | "es2018", 8 | "webworker" 9 | ], 10 | "types": [] 11 | }, 12 | "include": [ 13 | "src/**/*.worker.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /toolings/tfjs-debugger/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json" 3 | } 4 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint-no-circular-imports"], 3 | "rulesDirectory": ".tslint", 4 | "rules": { 5 | "array-type": [true, "array-simple"], 6 | "arrow-return-shorthand": true, 7 | "ban": [true, 8 | ["fit"], 9 | ["fdescribe"], 10 | ["xit"], 11 | ["xdescribe"], 12 | ["fitAsync"], 13 | ["xitAsync"], 14 | ["fitFakeAsync"], 15 | ["xitFakeAsync"] 16 | ], 17 | "ban-types": [true, 18 | ["Object", "Use {} instead."], 19 | ["String", "Use 'string' instead."], 20 | ["Number", "Use 'number' instead."], 21 | ["Boolean", "Use 'boolean' instead."] 22 | ], 23 | "no-return-await": true, 24 | "class-name": true, 25 | "curly": true, 26 | "interface-name": [true, "never-prefix"], 27 | "jsdoc-format": true, 28 | "forin": false, 29 | "label-position": true, 30 | "max-line-length": { 31 | "options": {"limit": 80, "ignore-pattern": "^import |^export |https?://"} 32 | }, 33 | "new-parens": true, 34 | "no-angle-bracket-type-assertion": true, 35 | "no-any": true, 36 | "no-construct": true, 37 | "no-consecutive-blank-lines": true, 38 | "no-debugger": true, 39 | "no-default-export": true, 40 | "no-imports-from-dist": true, 41 | "no-inferrable-types": true, 42 | "no-namespace": [true, "allow-declarations"], 43 | "no-reference": true, 44 | "no-require-imports": true, 45 | "no-string-throw": true, 46 | "no-unused-expression": true, 47 | "no-var-keyword": true, 48 | "no-unnecessary-type-assertion": true, 49 | "object-literal-shorthand": true, 50 | "only-arrow-functions": [true, "allow-declarations", "allow-named-functions"], 51 | "prefer-const": true, 52 | "quotemark": [true, "single"], 53 | "radix": true, 54 | "restrict-plus-operands": true, 55 | "semicolon": [true, "always", "ignore-bound-class-methods"], 56 | "switch-default": true, 57 | "triple-equals": [true, "allow-null-check"], 58 | "use-isnan": true, 59 | "use-default-type-parameter": true, 60 | "variable-name": [ 61 | true, 62 | "check-format", 63 | "ban-keywords", 64 | "allow-leading-underscore", 65 | "allow-trailing-underscore" 66 | ] 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test_model/ 3 | *~ 4 | #*# 5 | yarn-error.log -------------------------------------------------------------------------------- /webnn-tflite-delegate/README.md: -------------------------------------------------------------------------------- 1 | # WebNN Delegate for tfjs-tflite-node 2 | The `webnn-tflite-delegate` package adds support for [Web Neural Network API](https://www.w3.org/TR/webnn/) (WebNN API) to [tfjs-tflite-node](https://www.npmjs.com/package/tfjs-tflite-node). 3 | 4 | ## Dependencies 5 | 6 | This package takes dependencies on the WebNN API and implementation of [WebNN-native](https://github.com/webmachinelearning/webnn-native). In this package, the WebNN-native uses a specific [commit](https://github.com/webmachinelearning/webnn-native/commit/9d93acffb3eb8fd64d52ba08115de40fcbbd8a0d) and the backend implementation of WebNN-native uses [OpenVINO 2021.4 version](https://docs.openvino.ai/2021.4/get_started.html). 7 | 8 | ## Installing 9 | 10 | Follow the [instructions here](https://docs.openvino.ai/2021.4/get_started.html) to install OpenVINO 2021.4 on [Linux (x64)](https://registrationcenter-download.intel.com/akdlm/irc_nas/18319/l_openvino_toolkit_p_2021.4.752.tgz) or [Windows (x64)](https://registrationcenter-download.intel.com/akdlm/irc_nas/18320/w_openvino_toolkit_p_2021.4.752.exe). 11 | 12 | 13 | After OpenVINO is installed, you can install the `webnn-tflite-delegate` package with `npm i --save webnn-tflite-delegate`. 14 | 15 | ## Usage 16 | Register the WebNN delegate while loading a TFLite model in `tfjs-tflite-node` by adding it to the list of delegates in the TFLite options: 17 | 18 | ```typescript 19 | const model = await loadTFLiteModel('./mobilenetv2.tflite', { 20 | delegates: [new WebNNDelegate({webnnDevice: WebNNDevice.CPU})], 21 | }); 22 | 23 | ``` 24 | Before running model with this package, set following environment variables: 25 | 26 | - On Linux, run `./setupvars.sh` to set environment variables for OpenVINO. 27 | - On Windows, run `.\setupvars.bat` to set environment variables for OpenVINO and set the path of dependent WebNN native dll libraries (current location is `./cc_lib/win32_x64/`) to `PATH`. 28 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/linux_x64/libngraph_c_api.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/linux_x64/libngraph_c_api.so -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/linux_x64/libwebnn_native.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/linux_x64/libwebnn_native.so -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/linux_x64/libwebnn_proc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/linux_x64/libwebnn_proc.so -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/linux_x64/webnn_external_delegate_obj.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/linux_x64/webnn_external_delegate_obj.so -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/win32_x64/ngraph_c_api.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/win32_x64/ngraph_c_api.dll -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/win32_x64/webnn_external_delegate_obj.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/win32_x64/webnn_external_delegate_obj.dll -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/win32_x64/webnn_native.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/win32_x64/webnn_native.dll -------------------------------------------------------------------------------- /webnn-tflite-delegate/cc_lib/win32_x64/webnn_proc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/cc_lib/win32_x64/webnn_proc.dll -------------------------------------------------------------------------------- /webnn-tflite-delegate/jasmine-integration.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_files": [ 3 | "dist/integration_test/*_test.js" 4 | ], 5 | "env": { 6 | "stopSpecOnExpectationFailure": false, 7 | "random": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_files": [ 3 | "dist/*_test.js" 4 | ], 5 | "env": { 6 | "stopSpecOnExpectationFailure": false, 7 | "random": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webnn-tflite-delegate", 3 | "version": "0.0.3", 4 | "description": "A tflite delegate based on Web Neural Network API (WebNN API).", 5 | "main": "dist/index.js", 6 | "license": "Apache-2.0", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/tensorflow/sig-tfjs/tree/main/webnn-tflite-delegate" 10 | }, 11 | "homepage": "https://github.com/tensorflow/sig-tfjs/blob/main/webnn-tflite-delegate/README.md", 12 | "scripts": { 13 | "build": "tsc", 14 | "test-dev": "jasmine --config=jasmine.json", 15 | "test": "yarn build && yarn test-dev", 16 | "test-integration-dev": "jasmine --config=jasmine-integration.json", 17 | "test-integration": "yarn build && yarn test-integration-dev", 18 | "lint": "tslint -p . -t verbose" 19 | }, 20 | "devDependencies": { 21 | "@tensorflow/tfjs-backend-cpu": "^3.15.0", 22 | "@tensorflow/tfjs-core": "^3.15.0", 23 | "tfjs-tflite-node": "^0.0.2", 24 | "@types/jasmine": "^4.0.0", 25 | "@types/node": "^17.0.21", 26 | "jasmine": "^4.0.2", 27 | "jpeg-js": "^0.4.3", 28 | "tslint": "^6.1.3", 29 | "tslint-no-circular-imports": "^0.7.0", 30 | "typescript": "^4.5.4" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/setupvars.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: @license 4 | :: Copyright 2022 Google LLC. All Rights Reserved. 5 | :: Licensed under the Apache License, Version 2.0 (the "License"); 6 | :: you may not use this file except in compliance with the License. 7 | :: You may obtain a copy of the License at 8 | :: 9 | :: http://www.apache.org/licenses/LICENSE-2.0 10 | :: 11 | :: Unless required by applicable law or agreed to in writing, software 12 | :: distributed under the License is distributed on an "AS IS" BASIS, 13 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | :: See the License for the specific language governing permissions and 15 | :: limitations under the License. 16 | :: ============================================================================= 17 | 18 | 19 | set OPENVINO_SETVARS_PATH=%ProgramFiles(x86)%\Intel\openvino_2021\bin\setupvars.bat 20 | set WEBNN_LIBS_PATH=%~dp0cc_lib\win32_x64\ 21 | 22 | echo Setup OpenVINO environment... 23 | if exist "%OPENVINO_SETVARS_PATH%" ( 24 | call "%OPENVINO_SETVARS_PATH%" 25 | echo Setup OpenVINO environment...Done 26 | ) else ( 27 | echo Setup OpenVINO environment...Failed 28 | echo To fix, run the following command: ^\bin\setupvars.bat 29 | echo where INSTALL_DIR is the OpenVINO installation directory. 30 | ) 31 | 32 | echo Set path of WebNN native libs to PATH... 33 | echo Path of WebNN native libs: %WEBNN_LIBS_PATH% 34 | call set PATH=%PATH%;%WEBNN_LIBS_PATH% 35 | echo Set path of WebNN native libs to PATH...Done 36 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/setupvars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # @license 4 | # Copyright 2022 Google LLC. All Rights Reserved. 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ============================================================================= 17 | 18 | 19 | OPENVINO_SETVARS_PATH="/opt/intel/openvino_2021/bin/setupvars.sh" 20 | 21 | printf "\nSetup OpenVINO environment...\n" 22 | 23 | if [ -e "$OPENVINO_SETVARS_PATH" ]; then 24 | source "$OPENVINO_SETVARS_PATH" 25 | printf "Setup OpenVINO environment...Done\n" 26 | else 27 | printf "Setup OpenVINO environment...Failed 28 | To fix, run the following command: source /bin/setupvars.sh 29 | where INSTALL_DIR is the OpenVINO installation directory.\n" 30 | exit 1 31 | fi 32 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import type {TFLiteDelegatePlugin} from 'tfjs-tflite-node'; 19 | import * as os from 'os'; 20 | import * as path from 'path'; 21 | 22 | const libNames = new Map([ 23 | ['linux', path.join(__dirname, '../cc_lib/linux_x64/webnn_external_delegate_obj.so')], 24 | ['win32', path.join(__dirname, '../cc_lib/win32_x64/webnn_external_delegate_obj.dll')], 25 | ]); 26 | 27 | export enum WebNNDevice { 28 | DEFAULT = '0', 29 | GPU = '1', 30 | CPU = '2', 31 | } 32 | 33 | export interface WebNNOptions { 34 | webnnDevice?: WebNNDevice; 35 | } 36 | 37 | export class WebNNDelegate implements TFLiteDelegatePlugin { 38 | readonly name = 'WebNNDelegate'; 39 | readonly tfliteVersion = '2.7'; 40 | readonly node: TFLiteDelegatePlugin['node']; 41 | readonly options: Array<[string, string]> = []; 42 | 43 | constructor(options: WebNNOptions = {}, 44 | libPath?: string, platform = os.platform()) { 45 | if (!libPath) { 46 | libPath = libNames.get(platform); 47 | if (!libPath) { 48 | throw new Error(`Unknown platform ${platform}`); 49 | } 50 | } 51 | 52 | if (options.webnnDevice !== undefined) { 53 | this.options.push(['webnn_device', options.webnnDevice]); 54 | } 55 | 56 | this.node = { 57 | path: libPath, 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/src/index_test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import '@tensorflow/tfjs-backend-cpu'; 19 | import {WebNNDelegate, WebNNDevice} from './index'; 20 | import * as path from 'path'; 21 | 22 | describe('webnn delegate', () => { 23 | it('has the name "WebNNDelegate"', () => { 24 | expect(new WebNNDelegate().name).toEqual('WebNNDelegate'); 25 | }); 26 | 27 | it('has a TfLite version string', () => { 28 | expect(new WebNNDelegate().tfliteVersion).toBeDefined(); 29 | }); 30 | 31 | it('stores options', () => { 32 | const webnnDelegate = new WebNNDelegate({ 33 | webnnDevice: WebNNDevice.GPU, 34 | }); 35 | expect(webnnDelegate.options).toEqual([['webnn_device', WebNNDevice.GPU]]); 36 | }); 37 | 38 | it('allows manually setting lib path', () => { 39 | const libPath = 'some lib path'; 40 | const webnnDelegate = new WebNNDelegate({}, libPath); 41 | expect(webnnDelegate.node.path).toEqual(libPath); 42 | }); 43 | 44 | it('sets the lib path automatically based on platorm', () => { 45 | const webnnLinux = new WebNNDelegate({}, undefined, 'linux'); 46 | const webnnWindows = new WebNNDelegate({}, undefined, 'win32'); 47 | 48 | const pathPrefix = path.join(__dirname, '../cc_lib'); 49 | expect(webnnLinux.node.path).toEqual( 50 | path.join(pathPrefix, 'linux_x64/webnn_external_delegate_obj.so')); 51 | expect(webnnWindows.node.path).toEqual( 52 | path.join(pathPrefix, 'win32_x64/webnn_external_delegate_obj.dll')); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/src/integration_test/index_test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2022 Google LLC. All Rights Reserved. 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ============================================================================= 16 | */ 17 | 18 | import {WebNNDelegate, WebNNDevice} from '../index'; 19 | import {loadTFLiteModel} from 'tfjs-tflite-node'; 20 | import type {TFLiteModel} from 'tfjs-tflite-node/dist/tflite_model'; 21 | import * as fs from 'fs'; 22 | import * as tf from '@tensorflow/tfjs-core'; 23 | import '@tensorflow/tfjs-backend-cpu'; 24 | import * as jpeg from 'jpeg-js'; 25 | 26 | describe('webnn delegate', () => { 27 | const modelPath = './test_model/mobilenetv2.tflite'; 28 | let model: TFLiteModel; 29 | let wine: tf.Tensor; 30 | let labels: string[]; 31 | 32 | beforeEach(async () => { 33 | model = await loadTFLiteModel(modelPath, { 34 | delegates: [new WebNNDelegate({webnnDevice: WebNNDevice.CPU})], 35 | }); 36 | 37 | // Load the input image of a wine. 38 | const wineJpeg = jpeg.decode( 39 | fs.readFileSync('./test_model/wine.jpeg')); 40 | 41 | // Create an RGB array of the wine's pixels (no Alpha channel). 42 | const {width, height, data} = wineJpeg; 43 | const wineRGB = new Float32Array(width * height * 3); 44 | let pixelIndex = 0; 45 | for (let i = 0; i < width; i++) { 46 | for (let j = 0; j < height; j++) { 47 | const valStartIndex = pixelIndex * 4; 48 | const inputIndex = pixelIndex * 3; 49 | wineRGB[inputIndex] = (data[valStartIndex] - 127.5) / 127.5; 50 | wineRGB[inputIndex + 1] = (data[valStartIndex + 1] - 127.5) / 127.5; 51 | wineRGB[inputIndex + 2] = (data[valStartIndex + 2] - 127.5) / 127.5; 52 | pixelIndex += 1; 53 | } 54 | } 55 | 56 | wine = tf.tensor(wineRGB, [1, 224, 224, 3]); 57 | labels = fs.readFileSync('./test_model/mobilenetv2_labels.txt', 'utf-8') 58 | .split(/\r?\n/); 59 | }); 60 | 61 | it('runs a mobilenetv2 model', () => { 62 | const prediction = model.predict(wine); 63 | const slice = tf.slice(prediction as tf.Tensor, [0, 1], [-1, 1000]); 64 | const argmax = tf.argMax(slice, 1); 65 | const labelIndex = argmax.dataSync()[0]; 66 | const label = labels[labelIndex]; 67 | console.log('label:', label); 68 | console.log('score: ', slice.dataSync()[labelIndex]); 69 | expect(label).toEqual('wine bottle'); 70 | }); 71 | }); 72 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/test_model/mobilenetv2.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/test_model/mobilenetv2.tflite -------------------------------------------------------------------------------- /webnn-tflite-delegate/test_model/wine.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflow/sig-tfjs/a561c87c02f6922da74dd66423d0f338abe4e1d1/webnn-tflite-delegate/test_model/wine.jpeg -------------------------------------------------------------------------------- /webnn-tflite-delegate/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "noImplicitAny": true, 5 | "sourceMap": true, 6 | "removeComments": false, 7 | "preserveConstEnums": true, 8 | "declaration": true, 9 | "target": "es6", 10 | "lib": ["esnext", "dom"], 11 | "downlevelIteration": true, 12 | "outDir": "./dist", 13 | "noUnusedLocals": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "alwaysStrict": true, 17 | "noUnusedParameters": false, 18 | "pretty": true, 19 | "noFallthroughCasesInSwitch": true, 20 | "allowUnreachableCode": false, 21 | "experimentalDecorators": true 22 | }, 23 | "include": [ 24 | "src/" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /webnn-tflite-delegate/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json" 3 | } 4 | --------------------------------------------------------------------------------