From 2e680ddc2bfb81ac78491efd02ffe0de5e3b2e25 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 17 Oct 2020 06:30:00 -0400 Subject: [PATCH] refactored package file layout --- README.md | 18 +- src/config.js => config.js | 0 demo/{demo-esm.js => browser.js} | 3 +- demo/demo-iife.html | 422 ---------------------- demo/index.html | 27 ++ demo/{demo-node.js => node.js} | 2 +- demo/{demo-esm-webworker.js => worker.js} | 0 favicon.ico | Bin 0 -> 5063 bytes package.json | 15 +- src/index.js | 2 +- 10 files changed, 42 insertions(+), 447 deletions(-) rename src/config.js => config.js (100%) rename demo/{demo-esm.js => browser.js} (99%) delete mode 100644 demo/demo-iife.html create mode 100644 demo/index.html rename demo/{demo-node.js => node.js} (98%) rename demo/{demo-esm-webworker.js => worker.js} (100%) create mode 100644 favicon.ico 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 0000000000000000000000000000000000000000..1cbc04490dd7488fa515a98e243c113ac220d2f6 GIT binary patch literal 5063 zcmdUzc{J2-7r?*sov}BTM6!g!Sh7U6Aw-3gWyq4rnx%+|hViq_P?RW3ekh_WHA0hp z2~)DK{bY%ek!>^>M%kBlI`2R4Iq#qEU+?#OzUO)FbHC@F=iGDe=ef@X00`^-^FRP8 z;JqLK2(#u7tu0OA+@jp9Dcs!bJnE13&&SEm8qh&+ya7NEXMX;i9d2xCB0L%GmD9G$ zU@X13ESF_o>!U7{%*D9~a{YiGvCqHS{dXwZ?v}&#s#8#|b9U;4-^_Lul{!)ae_Yw`->;uG*~O)9-@l}yyS>u7;`!4&YpV~X5Q)}%LdJR`6e>Y@BO-A8C0|rX>j$3 z?cI%q*A2S;y7NmL*;$|jh!Dwv5;0DOY_qaTK z`vz{VxTvIJY5uEfi29lQ^Lu@iGcBsv#Y8icomClF=d!v3z~Q~}cXoddYqSQXCWsnJ?F7D(&aJ4{7VbDq}x z3R=`1fbPN^ZSg)#BZl-kCvUxae_e%S3u0;=LiHo-SN^a%q6+$v1EJwuA%j)E_HyUE ztIt9W5})VzZdQ@6k`1Q%sVECy3{FxJ;ec#WdB(n~XtU zh8t3C;SBm6P+GvZc$N(PVba4lowl+P(eYpPMzDS@jfU*bDSU2iMOh_#eVCH~zj zefg5~XpiS0dVX#MKh*2*T*HV1Fc)`J*wZeG@9<;JUfX)x$)Oe)T+vw?x-R(};TJ&v z+$*LwhUfF%`%&m&i!Xc}UHj7UMqBxB@^{dz;|u?K_WjkXU6TtIzd6Z1y?adbb&1y# z)$})Kzw~%XI38B3=_d3upPe-$awB4*z22yV+Dk#CDytbEIk8VoF-p(RN(o*OT)F=b zjkbv1m+xy0YB3HHUAf=buQ23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z71K|gieJk`JZe!h0Yc$&Dh z!(Yc2?ayG)rAR!3>atj0PmEB(L$PfYYbyDw8i+F_pt8Zo-UjvPjq??$-^i7u4N@rhJ(`_zWde#qay@myFl zwU&?Y4z}FC-D=UwPPpp5USSSD>5tZt!1aE^H@=+{j1j`vLnn>+vQ*X*i-nFr5AL@;ma9KUb*?Q9+4xj+A!#RobP(O2bvuV@AXL#xR;S)88SI8| zlcO_(^QWK3%#JoOX-nIZJqv#99qE^FoTasshtRy2yS9^3po=j3teqt{=yPH1rO{_{H0@fRwA0>woTDgG@tMkI`MSguVmF+--nG>U%!wSYOvTvDX$cCOBI`k zNJ96yGkMO~GjYc<1oAi>Ew*+x;!9^D4LWIcVIC#B@19lF=L-JJ*^jvbRbeZm>@d9Z z4CoP>eF}k6S|DG{#Pk5y5iQkQ5fdEtAHbSZbfBZbnFn*46-D}aLOKGO;7oZGqBzsG ziFQ$vBs2=>6Do!ied4%dO%RuLA0|!eXwb9Y`3={^6LXPf@2yANFn{Z20D;gxh_~%` z4PPU%C#&){$4A4nm8RieR!@ae(;+%kyQ%ZZZD? D<0%g1 literal 0 HcmV?d00001 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;