diff --git a/README.md b/README.md index b15f6f0f..c84b8c0c 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,7 @@ There are multiple ways to use `Human` library, pick one that suits you: - `dist/human.js`: IIFE format minified bundle with TFJS for Browsers - `dist/human.esm.js`: ESM format minified bundle with TFJS for Browsers - `dist/human.esm-nobundle.js`: ESM format non-minified bundle without TFJS for Browsers -- `dist/human.cjs`: CommonJS format minified bundle with TFJS for NodeJS -- `dist/human-nobundle.cjs`: CommonJS format non-minified bundle without TFJS for NodeJS +- `dist/human.cjs`: CommonJS format non-minified bundle without TFJS for NodeJS All versions include `sourcemap` @@ -116,21 +115,13 @@ Entry point is bundle in CJS format `dist/human.node.js` You also need to install and include `tfjs-node` or `tfjs-node-gpu` in your project so it can register an optimized backend Install with: -```shell - npm install @vladmandic/human -``` -And then use with: -```js - const human = require('@vladmandic/human'); // points to @vladmandic/human/dist/human.cjs -``` -or ```shell npm install @vladmandic/human @tensorflow/tfjs-node ``` And then use with: ```js const tf = require('@tensorflow/tfjs-node'); // can also use '@tensorflow/tfjs-node-gpu' if you have environment with CUDA extensions - const human = require('@vladmandic/human/dist/human-nobundle.cjs'); + const human = require('@vladmandic/human'); // points to @vladmandic/human/dist/human.cjs ``` @@ -164,11 +155,10 @@ If your application resides in a different folder, modify `modelPath` property i Demos are included in `/demo`: Browser: -- `demo-esm`: Full demo using Browser with ESM module, includes selectable backends and webworkers -- `demo-iife`: Older demo using Browser with IIFE module +- `index.html`, `browser.js`, `worker.js`: Full demo using Browser with ESM module, includes selectable backends and webworkers NodeJS: -- `demo-node`: Demo using NodeJS with CJS module +- `node.js`: Demo using NodeJS with CJS module This is a very simple demo as althought `Human` library is compatible with NodeJS execution and is able to load images and models from local filesystem, diff --git a/src/config.js b/config.js similarity index 100% rename from src/config.js rename to config.js diff --git a/demo/demo-esm.js b/demo/browser.js similarity index 99% rename from demo/demo-esm.js rename to demo/browser.js index 7a505050..a178d1e3 100644 --- a/demo/demo-esm.js +++ b/demo/browser.js @@ -11,6 +11,7 @@ const ui = { columns: 3, busy: false, facing: 'user', + worker: 'worker.js', }; const config = { @@ -243,7 +244,7 @@ function webWorker(input, image, canvas) { if (!worker) { // create new webworker and add event handler only once log('Creating worker thread'); - worker = new Worker('demo-esm-webworker.js', { type: 'module' }); + worker = new Worker(ui.worker, { type: 'module' }); // after receiving message from webworker, parse&draw results and send new frame for processing worker.addEventListener('message', (msg) => drawResults(input, msg.data, canvas)); } diff --git a/demo/demo-iife.html b/demo/demo-iife.html deleted file mode 100644 index 0296c31c..00000000 --- a/demo/demo-iife.html +++ /dev/null @@ -1,422 +0,0 @@ - - - - - -
- - - -
Starting Human library
-
- - diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 00000000..d49c24cf --- /dev/null +++ b/demo/index.html @@ -0,0 +1,27 @@ + + + + Human + + + + + + + + + + + + + + + + + + + +
+
Human library
+ + diff --git a/demo/demo-node.js b/demo/node.js similarity index 98% rename from demo/demo-node.js rename to demo/node.js index 5771a989..a1232ea1 100644 --- a/demo/demo-node.js +++ b/demo/node.js @@ -59,7 +59,7 @@ async function detect(input, output) { image.dispose(); logger.log(result); // Draw detected data and save processed image - logger.log('Saving:', output); + logger.log('TODO Saving:', output); } async function main() { diff --git a/demo/demo-esm-webworker.js b/demo/worker.js similarity index 100% rename from demo/demo-esm-webworker.js rename to demo/worker.js diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 00000000..1cbc0449 Binary files /dev/null and b/favicon.ico differ diff --git a/package.json b/package.json index d3e89390..fc6fd969 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.3.5", "description": "human: 3D Face Detection, Iris Tracking and Age & Gender Prediction", "sideEffects": false, - "main": "dist/human-nobundle.cjs", + "main": "dist/human.cjs", "module": "dist/human.esm.js", "browser": "dist/human.esm.js", "author": "Vladimir Mandic ", @@ -37,14 +37,13 @@ "rimraf": "^3.0.2" }, "scripts": { - "start": "node --trace-warnings --trace-uncaught --no-deprecation demo/demo-node.js", + "start": "node --trace-warnings --trace-uncaught --no-deprecation demo/node.js", "lint": "eslint src/*.js demo/*.js", - "build-iife": "esbuild --bundle --platform=browser --sourcemap --target=esnext --format=iife --minify --external:fs --global-name=human --outfile=dist/human.js src/index.js", - "build-esm-bundle": "esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:fs --outfile=dist/human.esm.js src/index.js", - "build-esm-nobundle": "esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:@tensorflow --external:fs --outfile=dist/human.esm-nobundle.js src/index.js", - "build-node-bundle": "esbuild --bundle --platform=node --sourcemap --target=esnext --format=cjs --minify --outfile=dist/human.cjs src/index.js", - "build-node-nobundle": "esbuild --bundle --platform=node --sourcemap --target=esnext --format=cjs --external:@tensorflow --outfile=dist/human-nobundle.cjs src/index.js", - "build": "rimraf dist/* && npm run build-iife && npm run build-esm-bundle && npm run build-esm-nobundle && npm run build-node-bundle && npm run build-node-nobundle && ls -l dist/", + "build-iife": "esbuild --bundle --platform=browser --sourcemap --target=esnext --format=iife --minify --external:fs --global-name=human --metafile=dist/human.json --outfile=dist/human.js src/index.js", + "build-esm-bundle": "esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:fs --metafile=dist/human.esm.json --outfile=dist/human.esm.js src/index.js", + "build-esm-nobundle": "esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:@tensorflow --external:fs --metafile=dist/human.esm-nobundle.json --outfile=dist/human.esm-nobundle.js src/index.js", + "build-node": "esbuild --bundle --platform=node --sourcemap --target=esnext --format=cjs --external:@tensorflow --metafile=dist/human.cjs.json --outfile=dist/human.cjs src/index.js", + "build": "rimraf dist/* && npm run build-iife && npm run build-esm-bundle && npm run build-esm-nobundle && npm run build-node && ls -l dist/", "update": "npm update --depth 20 && npm dedupe && npm prune && npm audit", "changelog": "node changelog.js" }, diff --git a/src/index.js b/src/index.js index 2456104d..a6b10a79 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ const ssrnet = require('./ssrnet/ssrnet.js'); const emotion = require('./emotion/emotion.js'); const posenet = require('./posenet/posenet.js'); const handpose = require('./handpose/handpose.js'); -const defaults = require('./config.js').default; +const defaults = require('../config.js').default; const app = require('../package.json'); let config;