nischi / MMM-Face-Reco-DNN

Face recognition with opencv and deep neural network
MIT License
91 stars 46 forks source link

Failed reco's and pictures without anyone in front of the cam #25

Closed ChrizZz90 closed 4 years ago

ChrizZz90 commented 4 years ago

I receive failed recognitions with a really different looking person and I saw that the module saves recognized pictures without anyone in front of the cam.

Is it possible that the picture resolution 640x480px is too low to create a database? Is there a way to increase the resolution?

HorstBaerbel commented 4 years ago

See #17 for the pictures in the "unknown" folder. 640x480 should be fine. Pictures are rescaled to 500px anyway for faster face detection...

nischi commented 4 years ago

Yes thats because the OpenCV detect a face. The detection is not perfect. Which method do you use for face detection?

I think it's possible to increase the resolution, but it will be much slower. And i'm not sure it would be better recognition after that.

HorstBaerbel commented 4 years ago

Images are rescaled to 500px anyway https://github.com/nischi/MMM-Face-Reco-DNN/blob/c1ae77529d2264b365766133a14a50affb897c41/tools/facerecognition.py#L94-L97 so I suspect a higher resolution would no make much of a difference. It might be better to make sure you use the newer DNN, not the HaarCascades method and add some more training pictures and update you encodings (see README).

ChrizZz90 commented 4 years ago

I use DNN and I have lots of training pictures (400+). Maybe the problem is that I use a widescreen camera?

nischi commented 4 years ago

dnn is the recognition method (i realized that i wrote it a little bit wrong in the readme) the "detectionMethod" is the detection of the face which make some issues here. which settings do you have? hog or cnn?

ChrizZz90 commented 4 years ago

Ah alright, I use hog. So I should try cnn, right?

nischi commented 4 years ago

yes, give a try

ChrizZz90 commented 4 years ago

so I changed to cnn, created new embeddings with "python3 encode.py" and now my MM doesn't recognize anything. Do I have to add "-d cnn" by creating new embeddings?

nischi commented 4 years ago

its not necessary, should also work without. thats only how to detect faces while check your pictures. if that isnt a problem, you dont need to

ChrizZz90 commented 4 years ago

after changing the type this modul doesn't recognize anything

nischi commented 4 years ago

any error message?

ChrizZz90 commented 4 years ago

`[16:24:30.878] [ERROR] { Error: MemoryError: std::bad_alloc at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:246:21) at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:129:32) at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13) at ChildProcess.emit (events.js:182:13) at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)

----- Python Traceback -----
File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 106, in <module>
  model=args["detectionMethod"])
File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 116, in face_locations
  return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations
  return cnn_face_detector(img, number_of_times_to_upsample)

traceback: 'Traceback (most recent call last):\n File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 106, in \n model=args["detectionMethod"])\n File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 116, in face_locations\n return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]\n File "/usr/local/lib/python3.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations\n return cnn_face_detector(img, number_of_times_to_upsample)\nMemoryError: std::bad_alloc\n', executable: 'python3', options: null, script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py', args: [ '--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml', '--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle', '--usePiCamera=0', '--method=dnn', '--detectionMethod=cnn', '--interval=2000', '--output=0', '--extendDataset=True', '--dataset=modules/MMM-Face-Reco-DNN/dataset/' ], exitCode: 1 }`

nischi commented 4 years ago

phu seems like a RAM issue. Do you use the "old" Raspberry Pi 3?

ChrizZz90 commented 4 years ago

yes I use a Raspberry Pi 3 - 350 MB of 874 MB RAM is used when MM is running

nischi commented 4 years ago

maybe an issue with the swap file. but you shouldnt have this to high, otherwise you can burn your SD Card. I think Raspi 3 has to less power for dnn cnn

nischi commented 4 years ago

Close it because no activity here. If still a case, you can reopen it.