GithubHelp home page GithubHelp logo

faceai-master's Introduction

FaceAI

A python library built to realize face detection with Deep Learning using simple and few lines of code.


Now FaceAI is an original version and only support MTCCN to detect face. Eventually, FaceAI will offer others various kind of applications about face.

Update Record

  • V0.3.0 : Add 3D face restruction module.
  • V0.2.0 : Add download pre-trained automatically from google drive.
  • V0.1.0 : Add landmarks detection module.
  • V0.0.1 : Initialize the file structure of FaceAI and add MTCCN model.

Dependencies

  • Tensorflow 1.10.0 (and later versions)

  • Numpy 1.13.1 (and later versions)

  • OpenCV

  • Matplotlib

  • easydict

  • PIL

  • scipy

Demo

  • Face Detection input image:

    output image:

    code:

    from faceai.Detection import *
    import os
    import cv2
    
    def main():
        execution_path = os.getcwd()
        model_path = ['MTCNN_model/PNet_landmark/PNet-30', 'MTCNN_model/RNet_landmark/RNet-22',
                'MTCNN_model/ONet_landmark/ONet-22']
        input_path = os.path.join(execution_path, "image.jpg")
        output_path = os.path.join(execution_path, "imagenew.jpg")
        # image_arr = cv2.imread(input_path)
        # image_arr = cv2.cvtColor(image_arr, cv2.COLOR_BGR2RGB)
        facedetector = FacesDetection()
        facedetector.setModelTypeAsMTCNN()
        facedetector.setModelPath(model_path)
        facedetector.loadModel(min_face_size=24)
    
        img,dets = facedetector.detectFacesFromImage(input_image=input_path,box_mark=True)
        cv2.imwrite("imagenew.jpg", img)
        print('the number of faces: {:0>3d}'.format((len(dets))))
    
    if __name__ == '__main__':
        main()
    
  • Face Landmarks Detection input image:

    output image:

    code:

    from faceai.Detection import *
    from faceai.Alignment import LandmarksDetection
    import os
    import cv2
    
    def main():
        execution_path = os.getcwd()
        model_path = ['MTCNN_model/PNet_landmark/PNet-30', 'MTCNN_model/RNet_landmark/RNet-22',
                    'MTCNN_model/ONet_landmark/ONet-22']
        input_path = os.path.join(execution_path, "land.jpg")
        output_path = os.path.join(execution_path, "landnew.jpg")
    
        facedetector = FacesDetection()
        facedetector.setModelTypeAsMTCNN()
        facedetector.setModelPath(model_path)
        facedetector.loadModel(min_face_size=48)
    
        img,infs = facedetector.detectFacesFromImage(input_image=input_path,box_mark=False)
        dets = []
        for inf in infs:
            dets.append(inf["detection_details"])
        print('the number of faces: {:0>3d}'.format((len(infs))))
    
        landsdetector = LandmarksDetection()
        landsdetector.setModelTypeAsDAN()
        landsdetector.setModelPath("./Model/Model")
        landsdetector.loadModel()
    
        img,lands = landsdetector.detectLandmarksFromImage(img,dets,points_mark = True)
        cv2.imshow("t",img)
        cv2.imwrite("landnew.jpg", img)
    
    if __name__ == '__main__':
        main()
    
  • 3D Face Restruction

    input image:

    output image: dense image pose image depth image

    code:

    from faceai.Detection import FacesDetection
    from faceai.Alignment import LandmarksDetection
    from faceai.ThrDFace import ThreeDimRestructure
    import os
    import cv2
    
    def main():
      execution_path = os.getcwd()
      input_path = os.path.join(execution_path, "3d.jpg")
      output_path = os.path.join(execution_path, "landnew.jpg")
    
      facedetector = FacesDetection()
      facedetector.setModelTypeAsMTCNN()
      facedetector.loadModel(detection_speed='fast',min_face_size=12)
    
      img,infs = facedetector.detectFacesFromImage(input_image=input_path,box_mark=False)
      dets = []
      for inf in infs:
          dets.append(inf["detection_details"])
      print('the number of faces: {:0>3d}'.format((len(infs))))
    
      landsdetector = ThreeDimRestructure()
      landsdetector.setModelTypeAsPRNet()
      landsdetector.loadModel()
    
      img_3d = landsdetector.restructure3DFaceFromImage(img,dets=dets,depth=True,pose=True)
      for img_ in img_3d:
          cv2.imshow("vertices",img_['img_show']['vertices'])
          cv2.imshow("pose", img_['img_show']['pose'])
          cv2.imshow("depth", img_['img_show']['depth'])
          cv2.imwrite("3d_vertices.jpg", img_['img_show']['vertices'])
          cv2.imwrite("3d_pose.jpg", img_['img_show']['pose'])
          cv2.imwrite("3d_depth.jpg", img_['img_show']['depth'])
    
    if __name__ == '__main__':
      main()
    

Installation

To install ImageAI, run the python installation instruction below in the command line:

pip install faceai-0.1.2-py2.py3-none-any.whl

Pre-trained model

if you can not download model ,please download by hand,and code will remind you where you should uncompress these file.

*mtcnn pre-trained model will download at C:/Users/Administrator/.faceai/mtcnn

References

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.