Coder Social home page Coder Social logo

iitzco / faced Goto Github PK

View Code? Open in Web Editor NEW
548.0 548.0 152.0 87.55 MB

πŸš€ 😏 Near Real Time CPU Face detection using deep learning

License: MIT License

Python 100.00%
computer-vision convolutional-neural-networks deep-learning face-detection fully-convolutional-networks python python-library tensorflow

faced's People

Contributors

iitzco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faced's Issues

Detection Score

Hi, thanks a lot for open-sourcing faced, this is awesome!

I have two questions:

  1. In the predict method, do you have any particular reason for not returning the probability as well?

`

def predict(self, frame, thresh=0.85):
    input_img = cv2.resize(frame, (YOLO_SIZE, YOLO_SIZE)) / 255.
    input_img = np.expand_dims(input_img, axis=0)

    pred = self.sess.run([self.prob, self.x_center, self.y_center, self.w, self.h], feed_dict={self.training: False, self.img: input_img})

    bboxes = self._absolute_bboxes(pred, frame, thresh)
    bboxes = self._correct(frame, bboxes)
    bboxes = self._nonmax_supression(bboxes)

    return bboxes`
  1. Related to question 1, is there a convenient way to get the prob/detection score for the predicted image?

Thank you so much.

TensorFlow 2.0

For use with TensorFlow 2.0 I changed first line of faced/detector.py from :

import tensorflow as tf

to

import tensorflow.compat.v1 as tf

and it works. I know it's not ideal, but it works.

GPU requirements

Hello!
Thanks for the project, it works for me.
But I have strange results with my GTX 1080 Ti.
For some reason when I install Tensorflow with CUDA support and check GPU usage in MSI Afterburner, it shows that 10.6 of 11 Gb video memory is used. And this is not a training mode - I just use these already trained models.
Does that mean that it really needs so much video memory or this program just fills all the memory a video card provides?
Will this work on some GT 730 4G GPU as well? Or it will be not enough video memory?
How much video memory does the module require?
Thanks!

Change Webcam

Is there a way to change the camera(like where's the videocapture)?

add the names for the person

this was my code when i used cascade file

`
import cv2
import numpy as np
import os

def f_s():

trainer = r'C:\Users\User\Documents\jarvis\face recognition\trainer'

recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read(trainer + '/trainer.yml')
cascadePath = r'C:\Users\User\Documents\jarvis\cascades\data\haarcascade_frontalface_default.xml'
faceCascade = cv2.CascadeClassifier(cascadePath)

font = cv2.FONT_HERSHEY_SIMPLEX

#iniciate id counter
id = 0

# names related to ids: example ==> mark : id=1,  etc
names = ['None','Mark'] 

# Initialize and start realtime video capture
cam = cv2.VideoCapture(0)
cam.set(3, 640) # set video widht
cam.set(4, 480) # set video height

# Define min window size to be recognized as a face
minW = 0.1*cam.get(3)
minH = 0.1*cam.get(4)



while True:
    ret, img =cam.read()
    img = cv2.flip(img, 1) # Flip vertically
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    
    faces = faceCascade.detectMultiScale( 
        gray,
        scaleFactor = 1.2,
        minNeighbors = 5,
        minSize = (int(minW), int(minH)),
    )

    for(x,y,w,h) in faces:
        cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2)
        id, confidence = recognizer.predict(gray[y:y+h,x:x+w])

        # Check if confidence is less them 100 ==> "0" is perfect match 
        if (confidence < 100):
            id = names[id]
            confidence = "  {0}%".format(round(100 - confidence))
        else:
            id = "unknown"
            confidence = "  {0}%".format(round(100 - confidence))
        
                    
        if 'Mark' == id:
            A = '18'
        else:
            print('age: unknon')

        cv2.putText(img, str(id), (x+5,y-5), font, 1, (255,255,255), 2)
        cv2.putText(img, str(confidence), (x+65,y-5), font, 1, (255,255,0), 1)   
        cv2.putText(img, str(A), (x+25,y+h+23), font, 1, (255,255,0), 1)

    cv2.imshow('face recognition',img) 
    
    
    k = cv2.waitKey(10) & 0xff # Press 'ESC' for exiting video
    if k == 27:
        break

# Do a bit of cleanup
print("\n [INFO] Exiting Program and cleanup stuff")
cam.release()
cv2.destroyAllWindows()

if name == "main":
f_s()
`

is there a way of me adding my name the way i did above in the face code thing

Memory leakage in .predict - Repeatedly calling .predict(...) results in memory leak

Im trying to call face_detector.predict(rgb_img, thresh) just about 100 times/second and each time it causes memory increment just around 1.3-8.0 Mb.

    def crop_faces_from_numpy_image(self, numpy_rgb):
        bboxes = self.face_detector.predict(numpy_rgb, self.thresh)
        cropped_images_array = []

        for bbox in bboxes:
            xc = bbox[0]
            yc = bbox[1]
            w = bbox[2]
            h = bbox[3]

            face = self.cv2_image[yc - h:yc + h, xc - w:xc + w]
            if len(face) > 0:
                resized = cv2.resize(face, dim)
                cropped_images_array.append(resized)

        return cropped_images_array
    def numpy_image_from_bytes(self, data):
        cv2img = cv2.imdecode(np.frombuffer(data, np.uint8), -1)
        self.cv2_image = cv2img
        np_rgb = cv2.cvtColor(cv2img.copy(), cv2.COLOR_BGR2RGB)
        return np_rgb
Line #    Mem usage    Increment  Occurrences   Line Contents
=============================================================
    23    796.0 MiB    796.0 MiB           1   @profile
    24                                         def crop_and_save(barr_img):
    25    797.3 MiB      1.3 MiB           1       np_arr = fd_worker.numpy_image_from_bytes(barr_img)
    26    805.3 MiB      8.0 MiB           1       cropped_arr = fd_worker.crop_faces_from_numpy_image(np_arr) - here is leakage
    27    805.5 MiB      0.2 MiB           1       fd_worker.save_images(cropped_arr)
    28    805.5 MiB      0.0 MiB           1       del np_arr
    29    805.5 MiB      0.0 MiB           1       del cropped_arr
    30    805.5 MiB      0.0 MiB           1       gc.collect()

Python 3.8

unable to install it in windows 10

Hi everyone.
I could n't install faced on my Windows , I got this error and didn't understand it .
I appreciate if you could help me to install and use it

""
C:\Users\user1\Desktop\31Dec2018\faced>pip install git+https://github.com/iitzco/faced.git
Collecting git+https://github.com/iitzco/faced.git
Cloning https://github.com/iitzco/faced.git to c:\users\user1\appdata\local\temp\pip-req-build-ei3jp_f7
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\user1\AppData\Local\Temp\pip-req-build-ei3jp_f7\setup.py", line 14, in
long_description=readme(),
File "C:\Users\user1\AppData\Local\Temp\pip-req-build-ei3jp_f7\setup.py", line 6, in readme
return f.read()
File "C:\Users\user1\Downloads\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 19: character maps to
""

Thank you

Accuracy? Is there a paper?

This work is very nice, and I was wondering if there is a paper attached with it so I can read it in more detail. Also, what was the testing accuracy on the Wider face dataset after reducing YOLO to your network?

Installation Error

Faiz ξ‚° localhost ξ‚° ~ ξ‚° GitRepos ξ‚± Faced ξ‚° πŸ”₯ ξ‚° pip3 install git+https://github.com/iitzco/faced.git
Collecting git+https://github.com/iitzco/faced.git
Cloning https://github.com/iitzco/faced.git to /tmp/pip-req-build-cqyujtbf
Collecting numpy (from faced==0.1)
Downloading https://files.pythonhosted.org/packages/3d/10/62224c551acfd3a3583ad16d1e0f1c9e9c333e74479dc51977c31836119c/numpy-1.16.0-cp37-cp37m-manylinux1_x86_64.whl (17.3MB)
100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 17.3MB 443kB/s
Collecting tensorflow (from faced==0.1)
Could not find a version that satisfies the requirement tensorflow (from faced==0.1) (from versions: )
No matching distribution found for tensorflow (from faced==0.1)

For low resolution and dark contrast images.

Hi Ivan,

I used your face_detection model on some low resolution and dark contrast images such as the ones taken through cctv feed. The results aren't good on such images, Can you suggest resources which would be good for such kind of images, I'm okay with gpu usage.

Thanks,
Aditya

Porting to πŸ¦€Rust!

Hey @iitzco

I think this is an awesome project and great example of using tensorflow in a fast, reliable and CPU backed way.

In an effort to better understand how to create Tensorflow + Rust apps I started to port faced to Rust here: https://github.com/drbh/faced-rs

I have most of the core logic completed (load and run the two models) but need to finish writing the non_max and IOU functions.

Just wanted to share the repo and thank you for the awesome project! Also I would love to hear any feedback you have - or ways that faced-rs can be improved 😁

Model in Keras or ONNX format?

Hi! This looks really promising and interesting, good work! Would it be possible to get the actual trained model either in Keras format (.h5) or in ONNX? I'd like to use the model in MATLAB, but I can only import either Keras or ONNX formats.

Actual Code for FaceDetector and FaceCorrector models?

Unless im mistaken thus repository only contains the pretrained tensorflow1.x models of the the FaceDetector (face-yolo.pb) and FaceCorrector. i was wonderign if i could have a look at the actual code, and dataset used to traij these models

how to train on new data and how to use on GPU environments?

i am beginner of deep learning and i know the previous issue solution about which is how to train on your blog but i have a question that your explanation of auxilary network is not clear. Is auxilary network concatenated by main network? or independtly? so i want to know how to train main architecture and auxilary network clearly and i have one more question that how to use on GPU environments when inference step?

How to train ?

I would like to train this model for Person detection.
Please help with the steps.

Have you tested this on Jetson TX2?

From the looks of it, nothing should prevent it from running on Jetson. But, I am curious if have some performance numbers on Jetson. Thanks

Installation Error : UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 21: character maps to <undefined>

OS: Windows 10
Python v3.6.x

E:\clients\Assets\FR_Infogen_v3\IGL\code>pip install git+https://github.com/iitzco/faced.git
Collecting git+https://github.com/iitzco/faced.git
  Cloning https://github.com/iitzco/faced.git to c:\users\diksha\appdata\local\temp\pip-req-build-5ibodt8c
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Diksha\AppData\Local\Temp\pip-req-build-5ibodt8c\setup.py", line 14, in <module>
        long_description=readme(),
      File "C:\Users\Diksha\AppData\Local\Temp\pip-req-build-5ibodt8c\setup.py", line 6, in readme
        return f.read()
      File "D:\ai\envs\face3\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 21: character maps to <undefined>

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Diksha\AppData\Local\Temp\pip-req-build-5ibodt8c\

deleted

please delete this queestion

Problem on installation

Hi I am trying to use this but I ran into a problem that when I use 'python setup.py install ' in cmd and it shows finished successfully and I can import faced in my python. However when I try to use faced directly in cmd it cannot recognize it as an valid command. I am confused about that issue. I am very grateful if anyone can help me. Thx!

Strange result

Hello!

I'm trying to run faced, and use the code from the example. But it gives out a strange wrong result.
Does this software require image preprocessing before putting them to the input?

www.imgur.com/3XUoU3d

AttributeError: 'NoneType' object has no attribute 'shape'

Hi!

Thank you for sharing this tool.
I was having this issue while running faced with an .mp4 video.

This is the terminal output:

Traceback (most recent call last):
  File "../bin/faced", line 143, in <module>
    run_video(path, t, args.save)
  File "../bin/faced", line 103, in run_video
    if frame.shape[0] == 0:
AttributeError: 'NoneType' object has no attribute 'shape'

The segment of the code that is pointing in faced is:

      ... 
      cap = cv2.VideoCapture(path)
       ...
       # Capture frame-by-frame
        ret, frame = cap.read()
        if frame.shape[0] == 0:
            break

Have you got any idea what can be happening here?
I am using a python3 conda enviroment, with tensorflow-gpu installed.

Thanks!

Awesome Stuff!

Hello good sir, I hope you are having a great day. I have this idea that I wish to share, any chance we can exchange emails? πŸ˜„

Mine is [email protected]. Cheers!

Faces misaligned?

Hi all,

Great package - much faster than many of the other options.

I'm running into an issue where, for some images, the boxes are drawn in the incorrect place. The number of boxes is correct, it just looks as though the boxes have been shifted left. See an example below.
image

(The image is just a random photo from the internet. The original image is here)

I've been over the code and I cannot see why this would occur. I've also tried resizing the image, including changing the aspect ratio, and the result is the same. Has anyone had a similar experience?

Edit: To be clearer - it only occurs on some images, not all. So I don't think it's a problem with the install.

Preparing dataset

Faced is really awesome and light! Can you tell me how is dataset shape and structure? i would like to train my yolo into just 5 classs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.