tensorflow: use native modules again

This commit is contained in:
Koushik Dutta
2021-11-06 17:57:23 -07:00
parent 64ea74b895
commit 6b736e9083
19 changed files with 463 additions and 7696 deletions

2
.gitmodules vendored
View File

@@ -11,7 +11,7 @@
path = plugins/neato/node-botvac
url = git@github.com:koush/node-botvac
[submodule "plugins/tensorflow/face-api.js"]
path = plugins/tensorflow/face-api.js
path = external/face-api.js
url = git@github.com:koush/face-api.js
[submodule "external/axios-digest-auth"]
path = external/axios-digest-auth

1
external/face-api.js vendored Submodule

Submodule external/face-api.js added at a86687eea2

View File

@@ -1 +1 @@
../face-api.js/weights/face_landmark_68_model-shard1
../../../external/face-api.js/weights/face_landmark_68_model-shard1

View File

@@ -1 +1 @@
../face-api.js/weights/face_landmark_68_model-weights_manifest.json
../../../external/face-api.js/weights/face_landmark_68_model-weights_manifest.json

View File

@@ -1 +1 @@
../face-api.js/weights/face_landmark_68_tiny_model-shard1
../../../external/face-api.js/weights/face_landmark_68_tiny_model-shard1

View File

@@ -1 +1 @@
../face-api.js/weights/face_landmark_68_tiny_model-weights_manifest.json
../../../external/face-api.js/weights/face_landmark_68_tiny_model-weights_manifest.json

View File

@@ -1 +1 @@
../face-api.js/weights/face_recognition_model-shard1
../../../external/face-api.js/weights/face_recognition_model-shard1

View File

@@ -1 +1 @@
../face-api.js/weights/face_recognition_model-shard2
../../../external/face-api.js/weights/face_recognition_model-shard2

View File

@@ -1 +1 @@
../face-api.js/weights/face_recognition_model-weights_manifest.json
../../../external/face-api.js/weights/face_recognition_model-weights_manifest.json

View File

@@ -1 +1 @@
../face-api.js/weights/ssd_mobilenetv1_model-shard1
../../../external/face-api.js/weights/ssd_mobilenetv1_model-shard1

View File

@@ -1 +1 @@
../face-api.js/weights/ssd_mobilenetv1_model-shard2
../../../external/face-api.js/weights/ssd_mobilenetv1_model-shard2

View File

@@ -1 +1 @@
../face-api.js/weights/ssd_mobilenetv1_model-weights_manifest.json
../../../external/face-api.js/weights/ssd_mobilenetv1_model-weights_manifest.json

View File

@@ -1 +0,0 @@
../../node_modules/@tensorflow/tfjs-backend-wasm/dist/tfjs-backend-wasm-simd.wasm

View File

@@ -1 +0,0 @@
../../node_modules/@tensorflow/tfjs-backend-wasm/dist/tfjs-backend-wasm-threaded-simd.wasm

View File

@@ -1 +0,0 @@
../../node_modules/@tensorflow/tfjs-backend-wasm/dist/tfjs-backend-wasm.wasm

File diff suppressed because it is too large Load Diff

View File

@@ -41,16 +41,19 @@
"dependencies": {
"@scrypted/common": "file:../../common",
"@scrypted/sdk": "file:../../sdk",
"@tensorflow-models/coco-ssd": "^2.2.2",
"@tensorflow/tfjs": "^3.11.0",
"@tensorflow/tfjs-backend-wasm": "^3.11.0",
"canvas": "^2.8.0",
"face-api.js": "file:./face-api.js",
"@koush/face-api.js": "^0.22.3",
"jpeg-js": "^0.4.3",
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.14.175",
"@types/node": "^14.17.11"
},
"optionalDependencies": {
"@tensorflow-models/coco-ssd": "^2.2.2",
"@tensorflow/tfjs": "^3.11.0",
"@tensorflow/tfjs-core": "^3.9.0",
"@tensorflow/tfjs-node-gpu": "^3.11.0"
}
}

View File

@@ -2,14 +2,13 @@ import { MixinProvider, ScryptedDeviceType, ScryptedInterface, MediaObject, Vide
import sdk from '@scrypted/sdk';
import { SettingsMixinDeviceBase } from "../../../common/src/settings-mixin";
import { AutoenableMixinProvider } from '@scrypted/common/src/autoenable-mixin-provider';
import * as tf from '@tensorflow/tfjs-core';
import { ENV, tensor3d } from '@tensorflow/tfjs-core';
import { setWasmPaths } from '@tensorflow/tfjs-backend-wasm';
import * as tf from '@tensorflow/tfjs-node-gpu';
import { ENV, tensor3d } from '@tensorflow/tfjs-node-gpu';
import * as coco from '@tensorflow-models/coco-ssd';
import path from 'path';
import fetch from 'node-fetch';
import * as faceapi from 'face-api.js';
import { FaceDetection, FaceMatcher, LabeledFaceDescriptors } from 'face-api.js';
import * as faceapi from '@koush/face-api.js';
import { FaceDetection, FaceMatcher, LabeledFaceDescriptors } from '@koush/face-api.js';
import canvas, { createCanvas } from 'canvas';
import { Canvas, Image, ImageData } from 'canvas';
import { randomBytes } from 'crypto';
@@ -42,9 +41,9 @@ function observeLoadError(promise: Promise<any>) {
}
const ssdPromise = (async () => {
setWasmPaths('wasm/')
// setWasmPaths('wasm/')
await tf.setBackend('wasm');
// await tf.setBackend('wasm');
const fdnPromise = faceapi.nets.ssdMobilenetv1.loadFromDisk('./');
observeLoadError(fdnPromise);
const flnPromise = faceapi.nets.faceLandmark68Net.loadFromDisk('./');