From f654b89e8a49a10293563419d648999df6c6a025 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 6 Jun 2021 19:00:34 -0400 Subject: [PATCH] custom build tfjs from sources --- .npmignore | 2 ++ CHANGELOG.md | 2 +- src/human.ts | 8 +++++-- src/tfjs/types.ts | 2 ++ {src/tfjs => tfjs}/tf-browser.ts | 37 ++++++++++++++++-------------- {src/tfjs => tfjs}/tf-node-gpu.ts | 0 {src/tfjs => tfjs}/tf-node-wasm.ts | 0 {src/tfjs => tfjs}/tf-node.ts | 0 tsconfig.json | 12 +++++----- 9 files changed, 37 insertions(+), 26 deletions(-) rename {src/tfjs => tfjs}/tf-browser.ts (65%) rename {src/tfjs => tfjs}/tf-node-gpu.ts (100%) rename {src/tfjs => tfjs}/tf-node-wasm.ts (100%) rename {src/tfjs => tfjs}/tf-node.ts (100%) diff --git a/.npmignore b/.npmignore index e0b54f43..64c274ec 100644 --- a/.npmignore +++ b/.npmignore @@ -4,3 +4,5 @@ samples typedoc test wiki +dist/tfjs.esm.js +dist/tfjs.esm.js.map diff --git a/CHANGELOG.md b/CHANGELOG.md index c3af11b6..fc32f19d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Repository: **** ## Changelog -### **HEAD -> main** 2021/06/05 mandic00@live.com +### **update wasm to tfjs 3.7.0** 2021/06/06 mandic00@live.com - modularize build platform - enable body segmentation and background replacement in demo diff --git a/src/human.ts b/src/human.ts index 3864a684..73377e4b 100644 --- a/src/human.ts +++ b/src/human.ts @@ -44,10 +44,14 @@ export type Input = Tensor | typeof Image | ImageData | ImageBitmap | HTMLImageE */ export type Error = { error: string }; -/** Instance of TensorFlow/JS */ +/** Instance of TensorFlow/JS + * @external + */ export type TensorFlow = typeof tf; -/** Generic Model object type, holds instance of individual models */ +/** Generic Model object type + * holds instance of individual models + */ type Model = unknown; /** diff --git a/src/tfjs/types.ts b/src/tfjs/types.ts index 2425f977..d4937c22 100644 --- a/src/tfjs/types.ts +++ b/src/tfjs/types.ts @@ -4,10 +4,12 @@ /** * TensorFlow Tensor type + * @external */ export { Tensor } from '@tensorflow/tfjs-core/dist/index'; /** * TensorFlow GraphModel type + * @external */ export { GraphModel } from '@tensorflow/tfjs-converter/dist/index'; diff --git a/src/tfjs/tf-browser.ts b/tfjs/tf-browser.ts similarity index 65% rename from src/tfjs/tf-browser.ts rename to tfjs/tf-browser.ts index 309e3345..dafff388 100644 --- a/src/tfjs/tf-browser.ts +++ b/tfjs/tf-browser.ts @@ -1,10 +1,12 @@ /** * Creates tfjs bundle used by Human browser build target + * @external */ // import from dist // modules: 1299, moduleBytes: 4230827, imports: 7, importBytes: 2478, outputBytes: 2357435 // get versions of all packages +/* import * as packageBundle from '@tensorflow/tfjs/package.json'; import * as packageCore from '@tensorflow/tfjs-core/package.json'; import * as packageData from '@tensorflow/tfjs-data/package.json'; @@ -23,19 +25,19 @@ export * as data from '@tensorflow/tfjs-data/dist/index.js'; export * from '@tensorflow/tfjs-backend-cpu/dist/index.js'; export * from '@tensorflow/tfjs-backend-webgl/dist/index.js'; export * from '@tensorflow/tfjs-backend-wasm/dist/index.js'; +*/ // import from src // modules: 1681, moduleBytes: 5711239, imports: 7, importBytes: 2701, outputBytes: 2107830 // get versions of all packages -/* -import * as packageBundle from '@tensorflow/tfjs/package.json'; -import * as packageCore from '@tensorflow/tfjs-core/package.json'; -import * as packageData from '@tensorflow/tfjs-data/package.json'; -import * as packageLayers from '@tensorflow/tfjs-layers/package.json'; -import * as packageConverter from '@tensorflow/tfjs-converter/package.json'; -import { version_cpu } from '@tensorflow/tfjs-backend-cpu/src/index'; -import { version_webgl } from '@tensorflow/tfjs-backend-webgl/src/index'; -import { version_wasm } from '@tensorflow/tfjs-backend-wasm/src/index'; +import { version as tfjsVersion } from '@tensorflow/tfjs/package.json'; +import { version as tfjsCoreVersion } from '@tensorflow/tfjs-core/package.json'; +import { version as tfjsDataVersion } from '@tensorflow/tfjs-data/package.json'; +import { version as tfjsLayersVersion } from '@tensorflow/tfjs-layers/package.json'; +import { version as tfjsConverterVersion } from '@tensorflow/tfjs-converter/package.json'; +import { version as tfjsBackendCPUVersion } from '@tensorflow/tfjs-backend-cpu/package.json'; +import { version as tfjsBackendWebGLVersion } from '@tensorflow/tfjs-backend-webgl/package.json'; +import { version as tfjsBackendWASMVersion } from '@tensorflow/tfjs-backend-wasm/package.json'; // export all export * from '@tensorflow/tfjs-core/src/index'; @@ -45,17 +47,18 @@ export * as data from '@tensorflow/tfjs-data/src/index'; export * from '@tensorflow/tfjs-backend-cpu/src/index'; export * from '@tensorflow/tfjs-backend-webgl/src/index'; export * from '@tensorflow/tfjs-backend-wasm/src/index'; +/* */ // export versions export const version = { - tfjs: packageBundle?.version || undefined, - 'tfjs-core': packageCore?.version || undefined, - 'tfjs-data': packageData?.version || undefined, - 'tfjs-layers': packageLayers?.version || undefined, - 'tfjs-converter': packageConverter?.version || undefined, - 'tfjs-backend-cpu': version_cpu || undefined, - 'tfjs-backend-webgl': version_webgl || undefined, - 'tfjs-backend-wasm': version_wasm || undefined, + tfjs: tfjsVersion, + 'tfjs-core': tfjsCoreVersion, + 'tfjs-data': tfjsDataVersion, + 'tfjs-layers': tfjsLayersVersion, + 'tfjs-converter': tfjsConverterVersion, + 'tfjs-backend-cpu': tfjsBackendCPUVersion, + 'tfjs-backend-webgl': tfjsBackendWebGLVersion, + 'tfjs-backend-wasm': tfjsBackendWASMVersion, }; // export const version = {}; diff --git a/src/tfjs/tf-node-gpu.ts b/tfjs/tf-node-gpu.ts similarity index 100% rename from src/tfjs/tf-node-gpu.ts rename to tfjs/tf-node-gpu.ts diff --git a/src/tfjs/tf-node-wasm.ts b/tfjs/tf-node-wasm.ts similarity index 100% rename from src/tfjs/tf-node-wasm.ts rename to tfjs/tf-node-wasm.ts diff --git a/src/tfjs/tf-node.ts b/tfjs/tf-node.ts similarity index 100% rename from src/tfjs/tf-node.ts rename to tfjs/tf-node.ts diff --git a/tsconfig.json b/tsconfig.json index 6cca18ac..56e91e2f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -37,8 +37,8 @@ "allowUnreachableCode": false }, "formatCodeOptions": { "indentSize": 2, "tabSize": 2 }, - "include": ["src/*", "src/***/*"], - "exclude": ["node_modules/"], + "exclude": ["node_modules/", "types/"], + "include": ["src/"], "typedocOptions": { "excludePrivate": true, "excludeExternals": true, @@ -49,10 +49,10 @@ "hideGenerator": "true", "readme": "none", "out": "typedoc", - "entryPoints": "src/human.ts", - "exclude": ["**/node_modules/**"], - "externalPattern": ["**/node_modules/**"], - "logLevel": "Info", + "entryPoints": ["src/human.ts"], + "exclude": [], + "externalPattern": ["node_modules/", "tfjs/"], + "logLevel": "Verbose", "logger": "none", "theme": "wiki/theme/" }