add canvas/image based demo to decode webp
parent
6f9db4cd09
commit
e496c9789f
|
@ -1,6 +1,6 @@
|
|||
# @vladmandic/face-api
|
||||
|
||||
Version: **1.1.11**
|
||||
Version: **1.1.12**
|
||||
Description: **FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS**
|
||||
|
||||
Author: **Vladimir Mandic <mandic00@live.com>**
|
||||
|
@ -9,7 +9,7 @@ Repository: **<git+https://github.com/vladmandic/face-api.git>**
|
|||
|
||||
## Changelog
|
||||
|
||||
### **HEAD -> master** 2021/04/10 mandic00@live.com
|
||||
### **1.1.12** 2021/04/13 mandic00@live.com
|
||||
|
||||
|
||||
### **1.1.11** 2021/04/06 mandic00@live.com
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
const fs = require('fs');
|
||||
const tf = require('@tensorflow/tfjs-node');
|
||||
const image = require('@canvas/image'); // @canvas/image can decode jpeg, png, webp
|
||||
const faceapi = require('../dist/face-api.node.js'); // this is equivalent to '@vladmandic/faceapi'
|
||||
|
||||
const modelPath = 'model/';
|
||||
const imageFile = 'demo/sample1.jpg';
|
||||
const ssdOptions = { minConfidence: 0.1, maxResults: 10 };
|
||||
|
||||
async function main() {
|
||||
const buffer = fs.readFileSync(imageFile); // read image from disk
|
||||
const canvas = await image.imageFromBuffer(buffer); // decode to canvas
|
||||
const imageData = image.getImageData(canvas); // read decoded image data from canvas
|
||||
console.log('image:', imageFile, canvas.width, canvas.height);
|
||||
|
||||
const tensor = tf.tidy(() => { // create tensor from image data
|
||||
const data = tf.tensor(Array.from(imageData.data), [canvas.height, canvas.width, 4], 'int32'); // create rgba image tensor from flat array and flip to height x width
|
||||
const channels = tf.split(data, 4, 2); // split rgba to channels
|
||||
const rgb = tf.stack([channels[0], channels[1], channels[2]], 2); // stack channels back to rgb
|
||||
const reshape = tf.reshape(rgb, [1, canvas.height, canvas.width, 3]); // move extra dim from the end of tensor and use it as batch number instead
|
||||
return reshape;
|
||||
});
|
||||
console.log('tensor:', tensor.shape, tensor.size);
|
||||
|
||||
await faceapi.nets.ssdMobilenetv1.loadFromDisk(modelPath); // load basic model only
|
||||
const optionsSSDMobileNet = new faceapi.SsdMobilenetv1Options(ssdOptions); // create options object
|
||||
const result = await faceapi.detectAllFaces(tensor, optionsSSDMobileNet); // run detection
|
||||
console.log('results:', result);
|
||||
}
|
||||
|
||||
main();
|
|
@ -849,7 +849,7 @@ function isBrowser() {
|
|||
|
||||
// src/env/isNodejs.ts
|
||||
function isNodejs() {
|
||||
return typeof global === "object" && true && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
return typeof global === "object" && typeof require === "function" && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
}
|
||||
|
||||
// src/env/index.ts
|
||||
|
@ -2080,7 +2080,7 @@ function drawFaceLandmarks(canvasArg, faceLandmarks) {
|
|||
}
|
||||
|
||||
// package.json
|
||||
var version = "1.1.11";
|
||||
var version = "1.1.12";
|
||||
|
||||
// src/xception/extractParams.ts
|
||||
function extractorsFactory2(extractWeights, paramMappings) {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1002,7 +1002,7 @@ function isBrowser() {
|
|||
|
||||
// src/env/isNodejs.ts
|
||||
function isNodejs() {
|
||||
return typeof global === "object" && true && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
return typeof global === "object" && typeof require === "function" && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
}
|
||||
|
||||
// src/env/index.ts
|
||||
|
@ -2262,7 +2262,7 @@ function drawFaceLandmarks(canvasArg, faceLandmarks) {
|
|||
}
|
||||
|
||||
// package.json
|
||||
var version = "1.1.11";
|
||||
var version = "1.1.12";
|
||||
|
||||
// src/ageGenderNet/AgeGenderNet.ts
|
||||
var tf20 = __toModule(require_tfjs_esm());
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1002,7 +1002,7 @@ function isBrowser() {
|
|||
|
||||
// src/env/isNodejs.ts
|
||||
function isNodejs() {
|
||||
return typeof global === "object" && true && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
return typeof global === "object" && typeof require === "function" && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
}
|
||||
|
||||
// src/env/index.ts
|
||||
|
@ -2262,7 +2262,7 @@ function drawFaceLandmarks(canvasArg, faceLandmarks) {
|
|||
}
|
||||
|
||||
// package.json
|
||||
var version = "1.1.11";
|
||||
var version = "1.1.12";
|
||||
|
||||
// src/ageGenderNet/AgeGenderNet.ts
|
||||
var tf20 = __toModule(require_tfjs_esm());
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1002,7 +1002,7 @@ function isBrowser() {
|
|||
|
||||
// src/env/isNodejs.ts
|
||||
function isNodejs() {
|
||||
return typeof global === "object" && true && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
return typeof global === "object" && typeof require === "function" && typeof module !== "undefined" && typeof process !== "undefined" && !!process.version;
|
||||
}
|
||||
|
||||
// src/env/index.ts
|
||||
|
@ -2262,7 +2262,7 @@ function drawFaceLandmarks(canvasArg, faceLandmarks) {
|
|||
}
|
||||
|
||||
// package.json
|
||||
var version = "1.1.11";
|
||||
var version = "1.1.12";
|
||||
|
||||
// src/ageGenderNet/AgeGenderNet.ts
|
||||
var tf20 = __toModule(require_tfjs_esm());
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
17
package.json
17
package.json
|
@ -41,18 +41,19 @@
|
|||
"tfjs"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@tensorflow/tfjs": "^3.3.0",
|
||||
"@tensorflow/tfjs-backend-wasm": "^3.3.0",
|
||||
"@tensorflow/tfjs-node": "^3.3.0",
|
||||
"@tensorflow/tfjs-node-gpu": "^3.3.0",
|
||||
"@types/node": "^14.14.37",
|
||||
"@canvas/image": "^1.0.1",
|
||||
"@tensorflow/tfjs": "^3.4.0",
|
||||
"@tensorflow/tfjs-backend-wasm": "^3.4.0",
|
||||
"@tensorflow/tfjs-node": "^3.4.0",
|
||||
"@tensorflow/tfjs-node-gpu": "^3.4.0",
|
||||
"@types/node": "^14.14.41",
|
||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||
"@typescript-eslint/parser": "^4.22.0",
|
||||
"@vladmandic/pilogger": "^0.2.16",
|
||||
"@vladmandic/pilogger": "^0.2.17",
|
||||
"canvas": "^2.7.0",
|
||||
"chokidar": "^3.5.1",
|
||||
"dayjs": "^1.10.4",
|
||||
"esbuild": "^0.11.10",
|
||||
"esbuild": "^0.11.11",
|
||||
"eslint": "^7.24.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
|
@ -61,7 +62,7 @@
|
|||
"eslint-plugin-promise": "^5.1.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"seedrandom": "^3.0.5",
|
||||
"simple-git": "^2.37.0",
|
||||
"simple-git": "^2.38.0",
|
||||
"tslib": "^2.2.0",
|
||||
"typedoc": "^0.20.35",
|
||||
"typescript": "^4.2.4"
|
||||
|
|
Loading…
Reference in New Issue