mirror of https://github.com/vladmandic/human
modularize build platform
parent
f654b89e8a
commit
58d46094aa
|
@ -6,3 +6,4 @@ test
|
|||
wiki
|
||||
dist/tfjs.esm.js
|
||||
dist/tfjs.esm.js.map
|
||||
types/dist/tfjs.esm.d.ts
|
||||
|
|
|
@ -9,6 +9,9 @@ Repository: **<git+https://github.com/vladmandic/human.git>**
|
|||
|
||||
## Changelog
|
||||
|
||||
### **HEAD -> main** 2021/06/06 mandic00@live.com
|
||||
|
||||
|
||||
### **update wasm to tfjs 3.7.0** 2021/06/06 mandic00@live.com
|
||||
|
||||
- modularize build platform
|
||||
|
|
|
@ -753,11 +753,19 @@ async function processDataURL(f, action) {
|
|||
image.onerror = async () => status('image loading error');
|
||||
image.onload = async () => {
|
||||
ui.background = image;
|
||||
document.getElementById('canvas').style.display = 'block';
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const overlaid = await human.segmentation(canvas, ui.background, userConfig);
|
||||
if (overlaid) ctx.drawImage(overlaid, 0, 0);
|
||||
if (document.getElementById('canvas').style.display === 'block') { // replace canvas used for video
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const overlaid = await human.segmentation(canvas, ui.background, userConfig);
|
||||
if (overlaid) ctx.drawImage(overlaid, 0, 0);
|
||||
} else {
|
||||
const canvases = document.getElementById('samples-container').children; // replace loaded images
|
||||
for (const canvas of canvases) {
|
||||
const ctx = canvas.getContext('2d');
|
||||
const overlaid = await human.segmentation(canvas, ui.background, userConfig);
|
||||
if (overlaid) ctx.drawImage(overlaid, 0, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
image.src = dataURL;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"scripts": {
|
||||
"start": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught demo/node.js",
|
||||
"dev": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught server/serve.js",
|
||||
"build": "rimraf dist/* typedoc/* types/* && node --trace-warnings --unhandled-rejections=strict --trace-uncaught server/build.js",
|
||||
"build": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught server/build.js",
|
||||
"lint": "eslint src server demo test",
|
||||
"test": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught test/test.js",
|
||||
"scan": "npx auditjs@latest ossi --dev --quiet"
|
||||
|
|
|
@ -16,10 +16,11 @@ let skipped = Number.MAX_SAFE_INTEGER;
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export async function load(config: Config | any) {
|
||||
if (!model) {
|
||||
// @ts-ignore type mismatch on GraphModel
|
||||
model = await tf.loadGraphModel(join(config.modelBasePath, config.face.age.modelPath));
|
||||
if (!model || !model.modelUrl) log('load model failed:', config.face.age.modelPath);
|
||||
else if (config.debug) log('load model:', model.modelUrl);
|
||||
} else if (config.debug) log('cached model:', model.modelUrl);
|
||||
if (!model || !model['modelUrl']) log('load model failed:', config.face.age.modelPath);
|
||||
else if (config.debug) log('load model:', model['modelUrl']);
|
||||
} else if (config.debug) log('cached model:', model['modelUrl']);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -32,6 +33,7 @@ export async function predict(image: Tensor, config: Config | any) {
|
|||
}
|
||||
skipped = 0;
|
||||
return new Promise(async (resolve) => {
|
||||
if (!model.inputs[0].shape) return;
|
||||
const resize = tf.image.resizeBilinear(image, [model.inputs[0].shape[2], model.inputs[0].shape[1]], false);
|
||||
const enhance = tf.mul(resize, [255.0]);
|
||||
tf.dispose(resize);
|
||||
|
|
|
@ -19,11 +19,12 @@ const rgb = [0.2989, 0.5870, 0.1140]; // factors for red/green/blue colors when
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export async function load(config: Config | any) {
|
||||
if (!model) {
|
||||
// @ts-ignore type mismatch on GraphModel
|
||||
model = await tf.loadGraphModel(join(config.modelBasePath, config.face.gender.modelPath));
|
||||
alternative = model.inputs[0].shape[3] === 1;
|
||||
if (!model || !model.modelUrl) log('load model failed:', config.face.gender.modelPath);
|
||||
else if (config.debug) log('load model:', model.modelUrl);
|
||||
} else if (config.debug) log('cached model:', model.modelUrl);
|
||||
alternative = model.inputs[0].shape ? model.inputs[0]?.shape[3] === 1 : false;
|
||||
if (!model || !model['modelUrl']) log('load model failed:', config.face.gender.modelPath);
|
||||
else if (config.debug) log('load model:', model['modelUrl']);
|
||||
} else if (config.debug) log('cached model:', model['modelUrl']);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -36,6 +37,7 @@ export async function predict(image: Tensor, config: Config | any) {
|
|||
}
|
||||
skipped = 0;
|
||||
return new Promise(async (resolve) => {
|
||||
if (!model.inputs[0].shape) return;
|
||||
const resize = tf.image.resizeBilinear(image, [model.inputs[0].shape[2], model.inputs[0].shape[1]], false);
|
||||
let enhance;
|
||||
if (alternative) {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
|
||||
// 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';
|
||||
|
@ -12,7 +11,7 @@ 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';
|
||||
// for backends, get version from source so it can register backend during import
|
||||
// for backends, get version from source to avoid incorrect tree shaking
|
||||
import { version_cpu } from '@tensorflow/tfjs-backend-cpu/dist/index.js';
|
||||
import { version_webgl } from '@tensorflow/tfjs-backend-webgl/dist/index.js';
|
||||
import { version_wasm } from '@tensorflow/tfjs-backend-wasm/dist/index.js';
|
||||
|
@ -28,7 +27,6 @@ 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 { version as tfjsVersion } from '@tensorflow/tfjs/package.json';
|
||||
import { version as tfjsCoreVersion } from '@tensorflow/tfjs-core/package.json';
|
||||
|
@ -40,6 +38,7 @@ import { version as tfjsBackendWebGLVersion } from '@tensorflow/tfjs-backend-web
|
|||
import { version as tfjsBackendWASMVersion } from '@tensorflow/tfjs-backend-wasm/package.json';
|
||||
|
||||
// export all
|
||||
// requires treeShaking:ignore-annotations due to tfjs misconfiguration
|
||||
export * from '@tensorflow/tfjs-core/src/index';
|
||||
export * from '@tensorflow/tfjs-layers/src/index';
|
||||
export * from '@tensorflow/tfjs-converter/src/index';
|
||||
|
|
|
@ -19,12 +19,7 @@
|
|||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"tslib": ["node_modules/tslib/tslib.d.ts"],
|
||||
"@tensorflow/tfjs-node/dist/io/file_system": ["node_modules/@tensorflow/tfjs-node/dist/io/file_system.js"],
|
||||
"@tensorflow/tfjs-core/dist/index": ["node_modules/@tensorflow/tfjs-core/dist/index.js"],
|
||||
"@tensorflow/tfjs-converter/dist/index": ["node_modules/@tensorflow/tfjs-converter/dist/index.js"]
|
||||
},
|
||||
"paths": { "tslib": ["node_modules/tslib/tslib.d.ts"] },
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": false,
|
||||
"noUnusedLocals": false,
|
||||
|
@ -37,8 +32,8 @@
|
|||
"allowUnreachableCode": false
|
||||
},
|
||||
"formatCodeOptions": { "indentSize": 2, "tabSize": 2 },
|
||||
"exclude": ["node_modules/", "types/"],
|
||||
"include": ["src/"],
|
||||
"exclude": ["node_modules/", "types/", "tfjs/", "dist/"],
|
||||
"include": ["src"],
|
||||
"typedocOptions": {
|
||||
"excludePrivate": true,
|
||||
"excludeExternals": true,
|
||||
|
|
Loading…
Reference in New Issue