@digipair/skill-tensorflow 0.91.0-0 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +65 -0
- package/index.esm.js +38 -0
- package/libs/skill-tensorflow/src/lib/skill-tensorflow.d.ts +5 -0
- package/package.json +11 -22
- package/.swcrc +0 -28
- package/README.md +0 -7
- package/eslint.config.mjs +0 -22
- package/rollup.config.cjs +0 -28
- package/src/lib/skill-tensorflow.spec.ts +0 -7
- package/src/lib/skill-tensorflow.ts +0 -48
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -19
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/index.ts → libs/skill-tensorflow/src/index.d.ts} +0 -0
- /package/{src/schema.fr.json → schema.fr.json} +0 -0
- /package/{src/schema.json → schema.json} +0 -0
package/index.cjs.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var tf = require('@tensorflow/tfjs-node');
|
6
|
+
var cocoSsdModel = require('@tensorflow-models/coco-ssd');
|
7
|
+
var faceDetectionModel = require('@tensorflow-models/face-detection');
|
8
|
+
|
9
|
+
function _interopNamespace(e) {
|
10
|
+
if (e && e.__esModule) return e;
|
11
|
+
var n = Object.create(null);
|
12
|
+
if (e) {
|
13
|
+
Object.keys(e).forEach(function (k) {
|
14
|
+
if (k !== 'default') {
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
17
|
+
enumerable: true,
|
18
|
+
get: function () { return e[k]; }
|
19
|
+
});
|
20
|
+
}
|
21
|
+
});
|
22
|
+
}
|
23
|
+
n["default"] = e;
|
24
|
+
return Object.freeze(n);
|
25
|
+
}
|
26
|
+
|
27
|
+
var tf__namespace = /*#__PURE__*/_interopNamespace(tf);
|
28
|
+
var cocoSsdModel__namespace = /*#__PURE__*/_interopNamespace(cocoSsdModel);
|
29
|
+
var faceDetectionModel__namespace = /*#__PURE__*/_interopNamespace(faceDetectionModel);
|
30
|
+
|
31
|
+
let TensorflowService = class TensorflowService {
|
32
|
+
async base64ToImage(base64) {
|
33
|
+
const data = base64.replace(/^data:image\/\w+;base64,/, '');
|
34
|
+
const buffer = Buffer.from(data, 'base64');
|
35
|
+
return buffer;
|
36
|
+
}
|
37
|
+
async cocoSsd(params, _pinsSettingsList, _context) {
|
38
|
+
const { image, base = 'lite_mobilenet_v2', modelUrl } = params;
|
39
|
+
const model = await cocoSsdModel__namespace.load({
|
40
|
+
base,
|
41
|
+
modelUrl
|
42
|
+
});
|
43
|
+
const imageLoaded = await this.base64ToImage(image);
|
44
|
+
const imageData = tf__namespace.node.decodeImage(imageLoaded, 3);
|
45
|
+
const predictions = await model.detect(imageData);
|
46
|
+
return predictions;
|
47
|
+
}
|
48
|
+
async faceDetection(params, _pinsSettingsList, _context) {
|
49
|
+
const { image, runtime = 'mediapipe' } = params;
|
50
|
+
const model = faceDetectionModel__namespace.SupportedModels.MediaPipeFaceDetector;
|
51
|
+
const imageLoaded = await this.base64ToImage(image);
|
52
|
+
const imageData = tf__namespace.node.decodeImage(imageLoaded, 3);
|
53
|
+
const detectorConfig = {
|
54
|
+
runtime
|
55
|
+
};
|
56
|
+
const detector = await faceDetectionModel__namespace.createDetector(model, detectorConfig);
|
57
|
+
const faces = await detector.estimateFaces(imageData);
|
58
|
+
return faces;
|
59
|
+
}
|
60
|
+
};
|
61
|
+
const cocoSsd = (params, pinsSettingsList, context)=>new TensorflowService().cocoSsd(params, pinsSettingsList, context);
|
62
|
+
const faceDetection = (params, pinsSettingsList, context)=>new TensorflowService().faceDetection(params, pinsSettingsList, context);
|
63
|
+
|
64
|
+
exports.cocoSsd = cocoSsd;
|
65
|
+
exports.faceDetection = faceDetection;
|
package/index.esm.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as tf from '@tensorflow/tfjs-node';
|
2
|
+
import * as cocoSsdModel from '@tensorflow-models/coco-ssd';
|
3
|
+
import * as faceDetectionModel from '@tensorflow-models/face-detection';
|
4
|
+
|
5
|
+
let TensorflowService = class TensorflowService {
|
6
|
+
async base64ToImage(base64) {
|
7
|
+
const data = base64.replace(/^data:image\/\w+;base64,/, '');
|
8
|
+
const buffer = Buffer.from(data, 'base64');
|
9
|
+
return buffer;
|
10
|
+
}
|
11
|
+
async cocoSsd(params, _pinsSettingsList, _context) {
|
12
|
+
const { image, base = 'lite_mobilenet_v2', modelUrl } = params;
|
13
|
+
const model = await cocoSsdModel.load({
|
14
|
+
base,
|
15
|
+
modelUrl
|
16
|
+
});
|
17
|
+
const imageLoaded = await this.base64ToImage(image);
|
18
|
+
const imageData = tf.node.decodeImage(imageLoaded, 3);
|
19
|
+
const predictions = await model.detect(imageData);
|
20
|
+
return predictions;
|
21
|
+
}
|
22
|
+
async faceDetection(params, _pinsSettingsList, _context) {
|
23
|
+
const { image, runtime = 'mediapipe' } = params;
|
24
|
+
const model = faceDetectionModel.SupportedModels.MediaPipeFaceDetector;
|
25
|
+
const imageLoaded = await this.base64ToImage(image);
|
26
|
+
const imageData = tf.node.decodeImage(imageLoaded, 3);
|
27
|
+
const detectorConfig = {
|
28
|
+
runtime
|
29
|
+
};
|
30
|
+
const detector = await faceDetectionModel.createDetector(model, detectorConfig);
|
31
|
+
const faces = await detector.estimateFaces(imageData);
|
32
|
+
return faces;
|
33
|
+
}
|
34
|
+
};
|
35
|
+
const cocoSsd = (params, pinsSettingsList, context)=>new TensorflowService().cocoSsd(params, pinsSettingsList, context);
|
36
|
+
const faceDetection = (params, pinsSettingsList, context)=>new TensorflowService().faceDetection(params, pinsSettingsList, context);
|
37
|
+
|
38
|
+
export { cocoSsd, faceDetection };
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { PinsSettings } from '@digipair/engine';
|
2
|
+
import * as cocoSsdModel from '@tensorflow-models/coco-ssd';
|
3
|
+
import * as faceDetectionModel from '@tensorflow-models/face-detection';
|
4
|
+
export declare const cocoSsd: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<cocoSsdModel.DetectedObject[]>;
|
5
|
+
export declare const faceDetection: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<faceDetectionModel.Face[]>;
|
package/package.json
CHANGED
@@ -1,28 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digipair/skill-tensorflow",
|
3
|
-
"version": "0.
|
4
|
-
"type": "module",
|
5
|
-
"main": "dist/libs/skill-tensorflow/index.cjs.js",
|
6
|
-
"module": "dist/libs/skill-tensorflow/index.esm.js",
|
7
|
-
"types": "dist/libs/skill-tensorflow/index.esm.d.ts",
|
8
|
-
"exports": {
|
9
|
-
"./package.json": "./libs/skill-tensorflow/package.json",
|
10
|
-
".": {
|
11
|
-
"development": "./dist/libs/skill-tensorflow/src/index.ts",
|
12
|
-
"types": "./dist/libs/skill-tensorflow/index.esm.d.ts",
|
13
|
-
"import": "./dist/libs/skill-tensorflow/index.esm.js",
|
14
|
-
"default": "./dist/libs/skill-tensorflow/index.cjs.js"
|
15
|
-
}
|
16
|
-
},
|
3
|
+
"version": "0.92.0",
|
17
4
|
"keywords": [
|
18
5
|
"digipair",
|
19
|
-
"
|
20
|
-
"
|
6
|
+
"service",
|
7
|
+
"util"
|
21
8
|
],
|
22
|
-
"nx": {
|
23
|
-
"name": "skill-tensorflow"
|
24
|
-
},
|
25
9
|
"dependencies": {
|
26
|
-
"@
|
27
|
-
|
28
|
-
|
10
|
+
"@tensorflow-models/coco-ssd": "^2.2.3",
|
11
|
+
"@tensorflow-models/face-detection": "^1.0.2",
|
12
|
+
"@tensorflow/tfjs-node": "^4.20.0",
|
13
|
+
"@mediapipe/face_detection": "^0.4.1646425229"
|
14
|
+
},
|
15
|
+
"main": "./index.cjs.js",
|
16
|
+
"module": "./index.esm.js"
|
17
|
+
}
|
package/.swcrc
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"jsc": {
|
3
|
-
"target": "es2017",
|
4
|
-
"parser": {
|
5
|
-
"syntax": "typescript",
|
6
|
-
"decorators": true,
|
7
|
-
"dynamicImport": true
|
8
|
-
},
|
9
|
-
"transform": {
|
10
|
-
"decoratorMetadata": true,
|
11
|
-
"legacyDecorator": true
|
12
|
-
},
|
13
|
-
"keepClassNames": true,
|
14
|
-
"externalHelpers": true,
|
15
|
-
"loose": true
|
16
|
-
},
|
17
|
-
"module": {
|
18
|
-
"type": "es6"
|
19
|
-
},
|
20
|
-
"sourceMaps": true,
|
21
|
-
"exclude": [
|
22
|
-
"jest.config.ts",
|
23
|
-
".*\\.spec.tsx?$",
|
24
|
-
".*\\.test.tsx?$",
|
25
|
-
"./src/jest-setup.ts$",
|
26
|
-
"./**/jest-setup.ts$"
|
27
|
-
]
|
28
|
-
}
|
package/README.md
DELETED
package/eslint.config.mjs
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
import baseConfig from '../../eslint.config.mjs';
|
2
|
-
|
3
|
-
export default [
|
4
|
-
...baseConfig,
|
5
|
-
{
|
6
|
-
files: ['**/*.json'],
|
7
|
-
rules: {
|
8
|
-
'@nx/dependency-checks': [
|
9
|
-
'error',
|
10
|
-
{
|
11
|
-
ignoredFiles: [
|
12
|
-
'{projectRoot}/eslint.config.{js,cjs,mjs}',
|
13
|
-
'{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
|
14
|
-
],
|
15
|
-
},
|
16
|
-
],
|
17
|
-
},
|
18
|
-
languageOptions: {
|
19
|
-
parser: await import('jsonc-eslint-parser'),
|
20
|
-
},
|
21
|
-
},
|
22
|
-
];
|
package/rollup.config.cjs
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
const { withNx } = require('@nx/rollup/with-nx');
|
2
|
-
|
3
|
-
module.exports = withNx(
|
4
|
-
{
|
5
|
-
main: 'libs/skill-tensorflow/src/index.ts',
|
6
|
-
outputPath: 'dist/libs/skill-tensorflow',
|
7
|
-
tsConfig: 'libs/skill-tensorflow/tsconfig.lib.json',
|
8
|
-
compiler: 'swc',
|
9
|
-
format: ['esm', "cjs"],
|
10
|
-
assets: [
|
11
|
-
{
|
12
|
-
input: 'libs/skill-tensorflow/',
|
13
|
-
glob: 'package.json',
|
14
|
-
output: '.'
|
15
|
-
},
|
16
|
-
{
|
17
|
-
input: 'libs/skill-tensorflow/src/',
|
18
|
-
glob: '*.json',
|
19
|
-
output: '.'
|
20
|
-
}
|
21
|
-
]
|
22
|
-
},
|
23
|
-
{
|
24
|
-
// Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
|
25
|
-
// e.g.
|
26
|
-
// output: { sourcemap: true },
|
27
|
-
}
|
28
|
-
);
|
@@ -1,48 +0,0 @@
|
|
1
|
-
import { PinsSettings } from '@digipair/engine';
|
2
|
-
import * as tf from '@tensorflow/tfjs-node';
|
3
|
-
import * as cocoSsdModel from '@tensorflow-models/coco-ssd';
|
4
|
-
import * as faceDetectionModel from '@tensorflow-models/face-detection';
|
5
|
-
import { MediaPipeFaceDetectorMediaPipeModelConfig } from '@tensorflow-models/face-detection';
|
6
|
-
|
7
|
-
class TensorflowService {
|
8
|
-
private async base64ToImage(base64: string) {
|
9
|
-
const data = base64.replace(/^data:image\/\w+;base64,/, '');
|
10
|
-
const buffer = Buffer.from(data, 'base64');
|
11
|
-
return buffer
|
12
|
-
};
|
13
|
-
|
14
|
-
async cocoSsd(params: any, _pinsSettingsList: PinsSettings[], _context: any) {
|
15
|
-
const { image, base = 'lite_mobilenet_v2', modelUrl } = params;
|
16
|
-
|
17
|
-
const model = await cocoSsdModel.load({
|
18
|
-
base,
|
19
|
-
modelUrl
|
20
|
-
});
|
21
|
-
const imageLoaded = await this.base64ToImage(image);
|
22
|
-
const imageData = tf.node.decodeImage(imageLoaded, 3);
|
23
|
-
const predictions = await model.detect(imageData as any);
|
24
|
-
|
25
|
-
return predictions;
|
26
|
-
}
|
27
|
-
|
28
|
-
async faceDetection(params: any, _pinsSettingsList: PinsSettings[], _context: any) {
|
29
|
-
const { image, runtime = 'mediapipe' } = params;
|
30
|
-
|
31
|
-
const model = faceDetectionModel.SupportedModels.MediaPipeFaceDetector;
|
32
|
-
const imageLoaded = await this.base64ToImage(image);
|
33
|
-
const imageData = tf.node.decodeImage(imageLoaded, 3);
|
34
|
-
const detectorConfig: MediaPipeFaceDetectorMediaPipeModelConfig = {
|
35
|
-
runtime, // 'mediapipe' or 'tfjs'
|
36
|
-
}
|
37
|
-
const detector = await faceDetectionModel.createDetector(model, detectorConfig);
|
38
|
-
const faces = await detector.estimateFaces(imageData as any);
|
39
|
-
|
40
|
-
return faces;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
export const cocoSsd = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
45
|
-
new TensorflowService().cocoSsd(params, pinsSettingsList, context);
|
46
|
-
|
47
|
-
export const faceDetection = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
|
48
|
-
new TensorflowService().faceDetection(params, pinsSettingsList, context);
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "../../tsconfig.base.json",
|
3
|
-
"compilerOptions": {
|
4
|
-
"rootDir": "src",
|
5
|
-
"outDir": "dist",
|
6
|
-
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
7
|
-
"emitDeclarationOnly": true,
|
8
|
-
"module": "esnext",
|
9
|
-
"moduleResolution": "node",
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
11
|
-
"types": ["node"]
|
12
|
-
},
|
13
|
-
"include": ["src/**/*.ts"],
|
14
|
-
"references": [
|
15
|
-
{
|
16
|
-
"path": "../engine/tsconfig.lib.json"
|
17
|
-
}
|
18
|
-
]
|
19
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|