kandi background
Explore Kits

facenet | Face recognition using Tensorflow | Computer Vision library

 by   davidsandberg Python Version: Current License: MIT

 by   davidsandberg Python Version: Current License: MIT

Download this library from

kandi X-RAY | facenet Summary

facenet is a Python library typically used in Institutions, Learning, Education, Artificial Intelligence, Computer Vision, Tensorflow, OpenCV applications. facenet has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
Face recognition using Tensorflow
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • facenet has a medium active ecosystem.
  • It has 11982 star(s) with 4648 fork(s). There are 581 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 478 open issues and 615 have been closed. On average issues are closed in 93 days. There are 44 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of facenet is current.
facenet Support
Best in #Computer Vision
Average in #Computer Vision
facenet Support
Best in #Computer Vision
Average in #Computer Vision

quality kandi Quality

  • facenet has 0 bugs and 0 code smells.
facenet Quality
Best in #Computer Vision
Average in #Computer Vision
facenet Quality
Best in #Computer Vision
Average in #Computer Vision

securitySecurity

  • facenet has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • facenet code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
facenet Security
Best in #Computer Vision
Average in #Computer Vision
facenet Security
Best in #Computer Vision
Average in #Computer Vision

license License

  • facenet is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
facenet License
Best in #Computer Vision
Average in #Computer Vision
facenet License
Best in #Computer Vision
Average in #Computer Vision

buildReuse

  • facenet releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • facenet saves you 3130 person hours of effort in developing the same functionality from scratch.
  • It has 6737 lines of code, 312 functions and 73 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
facenet Reuse
Best in #Computer Vision
Average in #Computer Vision
facenet Reuse
Best in #Computer Vision
Average in #Computer Vision
Top functions reviewed by kandi - BETA

kandi has reviewed facenet and discovered the below as its top functions. This is intended to give you an instant insight into facenet implemented functionality, and help decide if they suit your requirements.

  • Bulk detect face detection
  • Inception resnet v2 .
  • Detect the face of the image .
  • Simulate the face recognition algorithm .
  • Inception resnet v1d .
  • Evaluate LFW .
  • Train model .
  • Main function .
  • Generate inception layer .
  • Performs inference on images .

facenet Key Features

Face recognition using Tensorflow

Sorting a tensor list in ascending order

copy iconCopydownload iconDownload
namestodistance = [('Alice', .1), ('Bob', .3), ('Carrie', .2)]
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])
namestodistance = list(map(lambda x: (x[0], x[1].item()), namestodistance)
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])
-----------------------
namestodistance = [('Alice', .1), ('Bob', .3), ('Carrie', .2)]
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])
namestodistance = list(map(lambda x: (x[0], x[1].item()), namestodistance)
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])

Can't open "face_detector\deploy.prototxt" in function 'cv::dnn::ReadProtoFromTextFile'

copy iconCopydownload iconDownload
import os

prototxtPath = os.path.join(os.getcwd(), 'face_detector', 'deploy.prototxt')
weightsPath = os.path.join(os.getcwd(), 'face_detector', 'res10_300x300_ssd_iter_140000.caffemodel')

faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)

print("[INFO] starting video stream...")
vs = VideoStream(src=0).start()

How to set up a environment for python application development in Docker Desktop

copy iconCopydownload iconDownload
ADD $PWD/requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt 
ADD $PWD/ /   #This will add all your workdirectory files in container

Can DeepFace verify() accept an image array or PIL Image object?

copy iconCopydownload iconDownload
results = DeepFace.verify(np.array(PILIMAGE), ...)
-----------------------
picture= "extracted_face_picture/single_face_picture.jpg"
picture= Image.open(picture)
.
.
df.verify(picture, np.array(frame), "Facenet")
df.verify(np.array(picture),np.array(frame), "Facenet")
-----------------------
picture= "extracted_face_picture/single_face_picture.jpg"
picture= Image.open(picture)
.
.
df.verify(picture, np.array(frame), "Facenet")
df.verify(np.array(picture),np.array(frame), "Facenet")

How to store FaceNet data efficiently?

copy iconCopydownload iconDownload
#!pip install deepface
from deepface import DeepFace
img_list = ["img1.jpg", "img2.jpg", ...]

model = DeepFace.build_model("Facenet")
for img_path in img_list:
    img_embedding = DeepFace.represent(img_path, model = model)
    #store img_embedding into the redis here

Show Mask Object Detection On Screen instead of Camera

copy iconCopydownload iconDownload
img=cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)

Cannot set headers after they are sent to client

copy iconCopydownload iconDownload
if (!fs.existsSync(dir)){
        fs.mkdirSync(dir);
        success = false;
        message = 'Cannot detect the person.Please add name in the textbox provided below to save the person.';
        res.status(200).json({message: message,success:success});
        res.end();
var facialScript = new PythonShell('face_detect.py',options)
        facialScript.on('message',(response)=>{
          console.log(response);
          res.status(200).send(response);
          //res.end();
        
        })
-----------------------
if (!fs.existsSync(dir)){
        fs.mkdirSync(dir);
        success = false;
        message = 'Cannot detect the person.Please add name in the textbox provided below to save the person.';
        res.status(200).json({message: message,success:success});
        res.end();
var facialScript = new PythonShell('face_detect.py',options)
        facialScript.on('message',(response)=>{
          console.log(response);
          res.status(200).send(response);
          //res.end();
        
        })
-----------------------
let result="";
 facialScript.on('message',(response)=>{
         result=result+response;//assuming that response is string you can change this as per your convenience .
        
        })

facialScript.on("end",()=>{
res.send(result);
})

How do I make Input type and weight type same?

copy iconCopydownload iconDownload
pred = model(img.to(device))[0]
>>> x = torch.ones(1)
>>> x.to(device)
tensor([1], device='cuda:0')
>>> x.is_cuda
False
-----------------------
pred = model(img.to(device))[0]
>>> x = torch.ones(1)
>>> x.to(device)
tensor([1], device='cuda:0')
>>> x.is_cuda
False

How to execute docker health check only one time?

copy iconCopydownload iconDownload
HEALTHCHECK CMD sh -c "if [ ! -f /tmp/health.txt ]; then touch /tmp/health.txt && python api/initRequest.py || exit 0 ; else echo \"initRequest.py already executed\"; fi"

Unexpected error when loading the model: problem in predictor - ModuleNotFoundError: No module named 'torchvision'

copy iconCopydownload iconDownload
REQUIRED_PACKAGES = ['torchvision==0.5.0', 'torch @ https://download.pytorch.org/whl/cpu/torch-1.4.0%2Bcpu-cp37-cp37m-linux_x86_64.whl', 'opencv-python', 'facenet-pytorch']

Community Discussions

Trending Discussions on facenet
  • Sorting a tensor list in ascending order
  • Can't open "face_detector\deploy.prototxt" in function 'cv::dnn::ReadProtoFromTextFile'
  • PermissionError: [Errno 13] Permission denied: .deepface
  • How to set up a environment for python application development in Docker Desktop
  • Can DeepFace verify() accept an image array or PIL Image object?
  • How to store FaceNet data efficiently?
  • Show Mask Object Detection On Screen instead of Camera
  • TypeError: Cannot create initializer for non-floating point type . When running "train_tripletloss.py"
  • Cannot set headers after they are sent to client
  • How do I make Input type and weight type same?
Trending Discussions on facenet

QUESTION

Sorting a tensor list in ascending order

Asked 2021-Dec-05 at 21:29

I am working on a facial comparison app that will give me the closest n number of faces to my target face.

I have done this with dlib/face_recognition as it uses numpy arrays, however i am now trying to do the same thing with facenet/pytorch and running into an issue because it uses tensors.

I have created a database of embeddings and I am giving the function one picture to compare to them. What i would like is for it to sort the list from lowest distances to highest, and give me the lowest 5 results or so.

here is the code I am working on that is doing the comparison. at this point i am feeding it a photo and asking it to compare against the embedding database.

def face_match(img_path, data_path): # img_path= location of photo, data_path= location of data.pt 
    # getting embedding matrix of the given img
    img_path = (os.getcwd()+'/1.jpg')
    img = Image.open(img_path)
    face = mtcnn(img) # returns cropped face and probability
    emb = resnet(face.unsqueeze(0)).detach() # detech is to make required gradient false

    saved_data = torch.load('data.pt') # loading data.pt file
    embedding_list = saved_data[0] # getting embedding data
    name_list = saved_data[1] # getting list of names
    dist_list = [] # list of matched distances, minimum distance is used to identify the person
    
    for idx, emb_db in enumerate(embedding_list):
        dist = torch.dist(emb, emb_db)
        dist_list.append(dist)
    
    namestodistance = list(zip(name_list,dist_list))
    
    print(namestodistance)

face_match('1.jpg', 'data.pt')

This results in giving me all the names and their distance from the target photo in alphabetical order of the names, in the form of (Adam Smith, tensor(1.2123432)), Brian Smith, tensor(0.6545464) etc. If the 'tensor' wasn't part of every entry I think it would be no problem to sort it. I don't quite understand why its being appended to the entries. I can cut this down to the best 5 by adding [0:5] at the end of dist_list, but I can't figure out how to sort the list, I think the problem is the word tensor being in every entry.

I have tried for idx, emb_db in enumerate(embedding_list): dist = torch.dist(emb, emb_db) sorteddist = torch.sort(dist) but for whatever reason this only returns one distance value, and it isn't the smallest one.

idx_min = dist_list.index(min(dist_list)), this works fine in giving me the lowest value and then matching it to a name using namelist[idx_min], therefore giving the best match, but I would like the best 5 matches in order as opposed to just the best match.

Anyone able to solve this ?

ANSWER

Answered 2021-Dec-05 at 16:43

Unfortunately I cannot test your code, but to me it seems like you are operation on a python list of tuples. You can sort that by using a key:

namestodistance = [('Alice', .1), ('Bob', .3), ('Carrie', .2)]
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])

Of course you have to modify the anonymous function in key to return a sortable value instead of e.g. a torch.tensor.

This can be done by using key = lambda x: x[1].item().

Edit: To answer the question that crept up in the comments, we can refactor our code a little. Namely

namestodistance = list(map(lambda x: (x[0], x[1].item()), namestodistance)
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])

Source https://stackoverflow.com/questions/70232894

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install facenet

You can download it from GitHub.
You can use facenet like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Computer Vision Libraries with Highest Support
Compare Computer Vision Libraries with Highest Security
Compare Computer Vision Libraries with Permissive License
Compare Computer Vision Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.