face-recognition.js icon indicating copy to clipboard operation
face-recognition.js copied to clipboard

Big Size Images makes computer slow

Open kanrio opened this issue 6 years ago • 8 comments

I am not sure if this is a library issue or machine issue (tried it on 2 powerful computers with different OS windows + ubuntu but same result). Anyways, the first try with a simple images 600x400, size around 100kb-250kb and the detecting faces result was just after 7sec which is a lot for me since I am going to detect thousands of faces.

  • Using sizes like 500-999kb takes 1-2min to detect the faces
  • Over 1MB, huge problems computer get slower and for an image 2-3MB the computer stopped working.

Well, I know I can resize the image before detecting the face, I just wanted to know this issue where is coming from, is it normal or just me ... note this only detecting fr.FaceDetector() I didn't even start to recognize faces

kanrio avatar Mar 11 '18 12:03 kanrio

Hi,

You might want to have a look at: boosting-performance.

justadudewhohacks avatar Mar 11 '18 12:03 justadudewhohacks

@justadudewhohacks

Simply install openblas (sudo apt-get install libopenblas-dev) before building dlib / installing the package.

How can I do it since I have already built the dlib without installing libopenlabs-dev, shall I remove it and resinstall again ?

kanrio avatar Mar 11 '18 12:03 kanrio

Did you build dlib manually or via the auto build when npm installing this package?

If you are using the auto build, I would do npm uninstall face-recognition && npm install face-recognition.

If you are using a manual build you also have to rebuild dlib before reinstalling the package.

justadudewhohacks avatar Mar 11 '18 12:03 justadudewhohacks

Well the dlib was built using npm installing however I tried to remove it manually but I got some issues. I did npm uninstall face-recognition && npm install face-recognition after installing libopenlabs but still have the same issue.

I tried it on another fresh ubuntu installation still have the same result any idead ?

kanrio avatar Mar 12 '18 11:03 kanrio

Could you show me the log output of cmake? With openblas installed you should find openblas being detected as follows:

61

justadudewhohacks avatar Mar 13 '18 09:03 justadudewhohacks

To be honest I think most of the taks are rather CPU intensive regardless of using OpenBLAS or not. On my Macbook Pro I get the following results with this script:

const detector = fr.FaceDetector()
const faceRectangles = detector.locateFaces(image)
  • 256 x 256px about 200ms
  • 512 x 512px about 800ms
  • 1024 x 1024px about 2000ms
  • 2048 x 2048px about 9000ms (not even a really big image)

Which all are too slow for any realtime application. I've found several ways to improve the speed:

  1. Accept the fact that for the realtime part of your application you will use downscaled versions of the original image. You can store the original image for later use.
  2. Create a smaller copy of the image (e.g. 128px) then use locateFaces. Then use locateFaces on the larger image only on the area's where an face has been found.
  3. Use a haarclassifier (either from opencv or from this library), then use locateFaces on the larger image only on this area. The haarclassifier is much faster (about 200ms on 1024x1024) on my device. (Added downside: you'll only find frontalfaces, added upside: this haar detector has a lot of recall which is fixed by then using locateFaces)
let detectorOpenCV = new cv.CascadeClassifier(cv.HAAR_FRONTALFACE_DEFAULT);
let imageGray = imageCvMat.bgrToGray()
let detect = detectorOpenCV.detectMultiScale(imageGray)
// Note: there is an async variant for these functions!
// Note: I've found this to often throw errors, so please use the version below

let detectorFr = new fr.FrontalFaceDetector() // Built in frontal detector
detectorFr.detect(imageRgb)
// Note: no async variant

Zwimber avatar Mar 26 '18 10:03 Zwimber

@Zwimber Regarding option 3, where can I find the haarclassifier from this library? I intend to use the face detection for a webcam stream which requires low latency.

thexiroy avatar Jul 04 '18 13:07 thexiroy

The CascadeClassifier comes from opencv4nodejs. You can find some examples here, how to use face-recognition.js with opencv4nodejs.

justadudewhohacks avatar Jul 04 '18 13:07 justadudewhohacks