ageitgey / ageitgey/face_recognition

Face_recognition and Multiprocessing troubles

Open
#314 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
56.8k
Forks
13.7k
PR merge metrics
No merged PRs in 30d

Description

  • face_recognition version: 1.0
  • Python version: 3.6
  • Operating System: Arch Linux
Description

I'm trying to parallel process the comparison of facial encodings (in anticipation for a lot of faces), however when I try to use any sort of parallel processing library (i.e. multiprocessing, concurrent.futures, etc.) I get a TypeError: can't pickle cv2.VideoCapture objects. I'm incredibly confused, as I don't think I'm using any cv2 objects when I compare?

Here's the code snippets that generate the error:
(Sorry for the crazy code, I've been pulling my hair out over this issue)

import face_recognition as fr
import concurrent.futures
.......
 self.pool = concurrent.futures.ProcessPoolExecutors()
.......
#The function being called as a different proces:
def threadComparison(self, vals):
        boole = fr.compare_faces(vals[0], vals[2][0])
        val = self.RecFaces(boole)
        if val is not None:
            self.found.append(vals[1][val])

#The function handling data sorting and main processing:
def searchFace(self, encoding):
        #Pull faces from database
        values = self.fdr.select('faces', '*')
        counter = 0
        buff = []
        names = []
        bit = False
        for face in values:
            if len(self.found) > 0:
                bit = True
                break
            #Sorts facial encodings with names
            buff.append(np.array(face[1].split(' ')))
            names.append(face[0])
            #Tried debugging here, all are list, strings, etc. No cv2.VideoCapture types.
            #print(type(enc[0]))
            #print(type(buff[0]))
            #print(type(names[0]))
            if counter % 25 == 0:
                #Error generated here-------------------------
                self.pool.map(self.threadComparison, [buff,names,enc])
                #Error generated here^^^^^^^^^^^^^^^^^^^^^^^^^
                buff, names = []
            counter += 1
        self.pool.map(self.threadComparison, [buff, names, enc])
        if bit or len(found) > 0:
            print('Name: '+self.found[0])`

        else:
            print('No entry for face...')

Any help is greatly appreciated!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the TypeError from the shown ProcessPoolExecutor setup and inspect the self.pool.map calls in searchFace and threadComparison. Trace which arguments are serialized for the worker and identify the object that cannot be pickled; done means the failure is explained and a focused, reproducible resolution is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.