batch-face


Namebatch-face JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/elliottzheng/batch-face
SummaryBatch Face Preprocessing for Modern Research
upload_time2023-05-06 11:06:43
maintainer
docs_urlNone
authorElliott Zheng
requires_python
licenseMIT
keywords face-detection pytorch retinaface face-alignment
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Batch Face for Modern Research

## 🚧Documentation under construction, check tests folder for more details. 🚧

This repo provides the out-of-box face detection and face alignment with batch input support and enables real-time application on CPU.

## Features
1. Batch input support for faster data processing.
2. Smart API.
3. Ultrafast with inference runtime acceleration.
4. Automatically download pre-trained weights.
5. Minimal dependencies.

### Requirements

- Linux, Windows or macOS
- Python 3.5+ (it may work with other versions too)
- opencv-python
- PyTorch (>=1.0) 
- ONNX (optional)

While not required, for optimal performance it is highly recommended to run the code using a CUDA enabled GPU.

## Install

The easiest way to install it is using pip:

```bash
pip install git+https://github.com/elliottzheng/batch-face.git@master
```
No extra setup needs, most of the pretrained weights will be downloaded automatically.

## Usage
You can clone the repo and run tests like this
```
python -m tests.camera
```
### Face Detection

##### Detect face and five landmarks on single image
```python
import cv2
from batch_face import RetinaFace

detector = RetinaFace(gpu_id=0)
img = cv2.imread("examples/obama.jpg")
faces = detector(img, cv=True) # set cv to False for rgb input, the default value of cv is False
box, landmarks, score = faces[0]
```
##### Running on CPU/GPU

In order to specify the device (GPU or CPU) on which the code will run one can explicitly pass the device id.
```python
from batch_face import RetinaFace
# 0 means using GPU with id 0 for inference
# default -1: means using cpu for inference
detector = RetinaFace(gpu_id=0) 
```
|      | GPU(GTX 1080TI,batch size=1) | GPU(GTX 1080TI,batch size=750) | CPU(Intel(R) Core(TM) i7-7800X CPU @ 3.50GHz) |
| ---- | ---------------------------- | ------------------------------- | --------------------------------------------- |
| FPS  | 44.02405810720893            | 96.64058005582535               | 15.452635835550483                            |
| SPF  | 0.022714852809906007         | 0.010347620010375976            | 0.0647138786315918                            |


##### Batch input for faster detection

**Detector with CUDA process batch input faster than the same amount of single input.** 

```python
import cv2
from batch_face import RetinaFace

detector = RetinaFace()
img= cv2.imread('examples/obama.jpg')[...,::-1]
all_faces = detector([img,img]) # return faces list of all images
box, landmarks, score = all_faces[0][0]
```

Note: All the input images must of the same size, for input images with different size, please use `detector.pseudo_batch_detect`.

![](./images/gpu_batch.png)

### Face Alignment
##### face alignment on single image

```python 
from batch_face import drawLandmark_multiple, LandmarkPredictor, RetinaFace

predictor = LandmarkPredictor(0)
detector = RetinaFace(0)

imgname = "examples/obama.jpg"
img = cv2.imread(imgname)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

faces = detector(img)

if len(faces) == 0:
    print("NO face is detected!")
    exit(-1)

# the first input for the predictor is a list of face boxes. [[x1,y1,x2,y2]]
results = predictor(faces, img, from_fd=True) # from_fd=True to convert results from our detection results to simple boxes

for face, landmarks in zip(faces, results):
    img = drawLandmark_multiple(img, face[0], landmarks)
```


## References

- Face Detection Network and pretrained model are from [biubug6/Pytorch_Retinaface](https://github.com/biubug6/Pytorch_Retinaface)
- Face Alignment Network and pretrained model are from [cunjian/pytorch_face_landmark](https://github.com/cunjian/pytorch_face_landmark)
- Face Reconstruction Network and pretrained model are from [cleardusk/3DDFA](https://github.com/cleardusk/3DDFA)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/elliottzheng/batch-face",
    "name": "batch-face",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "face-detection pytorch RetinaFace face-alignment",
    "author": "Elliott Zheng",
    "author_email": "admin@hypercube.top",
    "download_url": "",
    "platform": null,
    "description": "# Batch Face for Modern Research\n\n## \ud83d\udea7Documentation under construction, check tests folder for more details. \ud83d\udea7\n\nThis repo provides the out-of-box face detection and face alignment with batch input support and enables real-time application on CPU.\n\n## Features\n1. Batch input support for faster data processing.\n2. Smart API.\n3. Ultrafast with inference runtime acceleration.\n4. Automatically download pre-trained weights.\n5. Minimal dependencies.\n\n### Requirements\n\n- Linux, Windows or macOS\n- Python 3.5+ (it may work with other versions too)\n- opencv-python\n- PyTorch (>=1.0) \n- ONNX (optional)\n\nWhile not required, for optimal performance it is highly recommended to run the code using a CUDA enabled GPU.\n\n## Install\n\nThe easiest way to install it is using pip:\n\n```bash\npip install git+https://github.com/elliottzheng/batch-face.git@master\n```\nNo extra setup needs, most of the pretrained weights will be downloaded automatically.\n\n## Usage\nYou can clone the repo and run tests like this\n```\npython -m tests.camera\n```\n### Face Detection\n\n##### Detect face and five landmarks on single image\n```python\nimport cv2\nfrom batch_face import RetinaFace\n\ndetector = RetinaFace(gpu_id=0)\nimg = cv2.imread(\"examples/obama.jpg\")\nfaces = detector(img, cv=True) # set cv to False for rgb input, the default value of cv is False\nbox, landmarks, score = faces[0]\n```\n##### Running on CPU/GPU\n\nIn order to specify the device (GPU or CPU) on which the code will run one can explicitly pass the device id.\n```python\nfrom batch_face import RetinaFace\n# 0 means using GPU with id 0 for inference\n# default -1: means using cpu for inference\ndetector = RetinaFace(gpu_id=0) \n```\n|      | GPU(GTX 1080TI,batch size=1) | GPU(GTX 1080TI\uff0cbatch size=750) | CPU(Intel(R) Core(TM) i7-7800X CPU @ 3.50GHz) |\n| ---- | ---------------------------- | ------------------------------- | --------------------------------------------- |\n| FPS  | 44.02405810720893            | 96.64058005582535               | 15.452635835550483                            |\n| SPF  | 0.022714852809906007         | 0.010347620010375976            | 0.0647138786315918                            |\n\n\n##### Batch input for faster detection\n\n**Detector with CUDA process batch input faster than the same amount of single input.** \n\n```python\nimport cv2\nfrom batch_face import RetinaFace\n\ndetector = RetinaFace()\nimg= cv2.imread('examples/obama.jpg')[...,::-1]\nall_faces = detector([img,img]) # return faces list of all images\nbox, landmarks, score = all_faces[0][0]\n```\n\nNote: All the input images must of the same size, for input images with different size, please use `detector.pseudo_batch_detect`.\n\n![](./images/gpu_batch.png)\n\n### Face Alignment\n##### face alignment on single image\n\n```python \nfrom batch_face import drawLandmark_multiple, LandmarkPredictor, RetinaFace\n\npredictor = LandmarkPredictor(0)\ndetector = RetinaFace(0)\n\nimgname = \"examples/obama.jpg\"\nimg = cv2.imread(imgname)\nimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\nfaces = detector(img)\n\nif len(faces) == 0:\n    print(\"NO face is detected!\")\n    exit(-1)\n\n# the first input for the predictor is a list of face boxes. [[x1,y1,x2,y2]]\nresults = predictor(faces, img, from_fd=True) # from_fd=True to convert results from our detection results to simple boxes\n\nfor face, landmarks in zip(faces, results):\n    img = drawLandmark_multiple(img, face[0], landmarks)\n```\n\n\n## References\n\n- Face Detection Network and pretrained model are from [biubug6/Pytorch_Retinaface](https://github.com/biubug6/Pytorch_Retinaface)\n- Face Alignment Network and pretrained model are from [cunjian/pytorch_face_landmark](https://github.com/cunjian/pytorch_face_landmark)\n- Face Reconstruction Network and pretrained model are from [cleardusk/3DDFA](https://github.com/cleardusk/3DDFA)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Batch Face Preprocessing for Modern Research",
    "version": "1.4.0",
    "project_urls": {
        "Documentation": "https://github.com/elliottzheng/batch-face",
        "Homepage": "https://github.com/elliottzheng/batch-face",
        "Source": "https://github.com/elliottzheng/batch-face",
        "Tracker": "https://github.com/elliottzheng/batch-face/issues"
    },
    "split_keywords": [
        "face-detection",
        "pytorch",
        "retinaface",
        "face-alignment"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b5827d3a2a50c5fa1ebb85926dd3a0e1341ae87721610db3a977e2a209d264b",
                "md5": "ef9ea46f5e34fdf8f2ed4053d0c797dc",
                "sha256": "90d3778db95f6b019ab594a4906f4f1073394107fb5bfb3a4056becd1aa12f56"
            },
            "downloads": -1,
            "filename": "batch_face-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ef9ea46f5e34fdf8f2ed4053d0c797dc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 30619180,
            "upload_time": "2023-05-06T11:06:43",
            "upload_time_iso_8601": "2023-05-06T11:06:43.441401Z",
            "url": "https://files.pythonhosted.org/packages/7b/58/27d3a2a50c5fa1ebb85926dd3a0e1341ae87721610db3a977e2a209d264b/batch_face-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-06 11:06:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "elliottzheng",
    "github_project": "batch-face",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "batch-face"
}
        
Elapsed time: 0.07450s