justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.54k stars 3.69k forks source link

Module For Face/Age/gender Detection Not Working in NODE.JS /Cordova Camera Upload Using Multer #388

Closed siddmegadeth closed 4 years ago

siddmegadeth commented 5 years ago

Module For Face/Age/gender Detection Not Loading In Browser from a URI

Issue : I am not able to load the module correctly for Age/gender detection using Http request. I am using express in the backend and i cannot use 15mb of file all the time. However i only need 1 model for my requirements . Due to less documentation i am not able to identify which model to load on my front end for gender/age detection to minimise bandwidth usage and speed up app.

Please suggest.

Note : I am not using TypeScript . By Making your project in TypeScript is has made transition even harder as we do not require TS for anything. and the validation messsages might have worked when conversion oj Object at JS but due to TS it has made life harder here. We hoped to use Face APi but cannot continue lie this.

Error Message with Multer


Image File :
{ fieldname: 'imageverify',
  originalname: '1567030996427.jpg',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  public_id: 'gender/imageverify-1567030997917',
  version: 1567031005,
  signature: '30f09b6a4ea72e2409dd8d0b15821f97644dfa4c',
  width: 4032,
  height: 3024,
  format: 'jpg',
  resource_type: 'image',
  created_at: '2019-08-28T22:23:25Z',
  tags: [],
  bytes: 411900,
  type: 'upload',
  etag: 'fd1291756909ab991c5afa3988391422',
  placeholder: false,
  url: 'http://res.cloudinary.com/hookup/image/upload/v1567031005/gender/imageverify-1567030997917.jpg',
  secure_url: 'https://res.cloudinary.com/hookup/image/upload/v1567031005/gender/imageverify-1567030997917.jpg',
  original_filename: 'file' }
{ lastModified: 1567031006333,
  lastModifiedDate: 2019-08-28T22:23:26.333Z,
  type: 'image/jpeg',
  size: 411900,
  name: '1567030996427.jpg' }
Promise { <pending> }
(node:34199) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: toNetInput - expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id
(node:34199) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Made Some Other Changes But does not work

log = console.log.bind(console);
async function execute(imgPath) {
        // Trying To Convert To File Imput Image Upload Format
        var obj = {};
        obj.lastModified = Date.now();
        obj.lastModifiedDate = new Date();
        obj.type = imgPath.mimetype
        obj.size = imgPath.bytes;
        obj.name = imgPath.originalname;

        log(obj);
        var returnValue = await faceapi.detectSingleFace(obj, new faceapi.SsdMobilenetv1Options()).withAgeAndGender();
        log(returnValue);
        return returnValue;
    };

    app.post('/get/picture/validator', mutlerUpload.single("imageverify"), function(req, resp, next) {

        log('/get/picture/validator');
        var image = req.files || req.file;
        //var encoded = image.buffer.toString('base64');
        log("Image File :");
        log(image);
        var returnValue = execute(image.url);
        log(returnValue);
        resp.send();
    });

If possible kindly look into it.

justadudewhohacks commented 5 years ago

await faceapi.detectSingleFace(obj, new faceapi.SsdMobilenetv1Options()).withAgeAndGender();

The obj variable you are passing into the api is not a valid input, it should either be a HTMLImageElement or a Tensor. You are just passing some self assembled javascript object in there in your code example. That's why you receive the error.

siddmegadeth commented 5 years ago

If possible can you pls help me out with creating a Obj which can be captured via device camera so that i can upload it to backend via REST API. some documentation would be appreciated for Apache Cordova based system. This Project is such a GEM . We are having limited knowledge in ML and has tried all methods to make it work. Maybe some leads would be appreciated

justadudewhohacks commented 4 years ago

If your goal is to fetch an image from an URI, take a look at this codesnippet provided by the README.