Skip to content

Commit

Permalink
Merge pull request #10 from acnazarejr/readme
Browse files Browse the repository at this point in the history
Fix the setupy.py packages bug
  • Loading branch information
acnazarejr authored May 14, 2020
2 parents 6ef86c9 + 1c80969 commit 1e9548e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# FDet - Deep Learning Face Detection

![Build](https://github.com/acnazarejr/fdet/workflows/Build/badge.svg)
[![Build](https://github.com/acnazarejr/fdet/workflows/Build/badge.svg)](https://github.com/acnazarejr/fdet/actions)
[![CodeFactor](https://www.codefactor.io/repository/github/acnazarejr/fdet/badge)](https://www.codefactor.io/repository/github/acnazarejr/fdet)
[![codecov](https://codecov.io/gh/acnazarejr/fdet/branch/master/graph/badge.svg)](https://codecov.io/gh/acnazarejr/fdet)
![PyPI](https://img.shields.io/pypi/v/fdet)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fdet)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/acnazarejr/fdet)
[![Platform](https://img.shields.io/badge/os-linux%20%7C%20win%20%7C%20mac-blue)](https://pypi.org/project/fdet/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fdet)](https://pypi.org/project/fdet/)
[![PyPI](https://img.shields.io/pypi/v/fdet)](https://pypi.org/project/fdet/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/acnazarejr/fdet)](https://github.com/acnazarejr/fdet/releases)
[![GitHub](https://img.shields.io/github/license/acnazarejr/fdet)](https://github.com/acnazarejr/fdet/blob/master/LICENSE)

The `fdet` is a ready-to-use implementation of deep learning face detectors using PyTorch.

![Example](https://github.com/acnazarejr/fdet/raw/master/assets/example.jpg)

You can use it in two ways: Directly in your code, as a [python library](#python-library-usage) or by [command-line](#command-line-usage):
You can use it directly in your code, as a [python library](#python-library-usage):

```python
>>> from fdet import io, RetinaFace

>>> detector = RetinaFace(backbone='RESNET50')
>>> detector.detect(io.read_as_rgb('path_to_image.jpg'))
[{'box': [511, 47, 35, 45], 'confidence': 0.9999996423721313,
'keypoints': {'left_eye': [517, 70], 'right_eye': [530, 65], 'nose': [520, 77],
'mouth_left': [522, 87], 'mouth_right': [531, 83]}}]
```

Or through [command-line](#command-line-usage) application:

```bash
fdet retinaface -b RESNET50 -i path_to_image.jpg -o detections.json
```
Expand All @@ -33,17 +37,17 @@ Currently, there are two different detectors available on FDet:

- **MTCNN** - Joint face detection and alignment using multitask cascaded convolutional networks [[zhang:2016]](#references)
- **RetinaFace** - Single-stage dense face localisation in the wild. [[deng:2019]](#references). You can use it with two different backbones:
- MobileNet: Fast and light-weighted model (achieves high FPS)
- Resnet50: A medium-size model for better results, but slower.
- *MobileNet*: Fast and light-weighted model (achieves high FPS)
- *Resnet50*: A medium-size model for better results, but slower.

Despite the availability of different implementations of these algorithms, there are some disadvantages we found when using them. So we create this project to offer the following features, in one package:

- :star: Real-time face detection;
- :star: Support for batch detection (useful for fast detection of multiple images and videos);
- :star: Support for batch detection (useful for fast detection in multiple images and videos);
- :star: Ease of use through python library or command-line app;
- :star: Provide a unified interface to assign 'CPU' or 'GPU' devices;
- :star: Multiple GPU's support;
- :star: On-demand and automatic model weights download;
- :star: Automatic on-demand model weights download;
- :star: Compatible with Windows, Linux, and macOS systems.

## **Installation**
Expand All @@ -60,10 +64,6 @@ pip install fdet

If you want to use `fdet` from python, just import it,

```python
import fdet
```

```python
from fdet import MTCNN, RetinaFace
```
Expand All @@ -85,8 +85,9 @@ and instantiate your desired detector, with its respective parameters:
- `cuda_enable` (bool, optional): Indicates wheter CUDA, if available, should be used or not. If False, uses only CPU processing. [default: True].
- `cuda_devices` (list, optional): List of CUDA GPUs to be used. If None, uses all avaliable GPUs. [default: None]. If `cuda_enable` is False, this parameter is ignored.

The detector classes listed above have two methods to perform the face detection:

### **Singe-Image Detection**
### **Singe-Image Detection Example**

The following example illustrates the ease of use of this library to detect faces in a single-image using MTCNN and to create an output image with all detected faces drawn.

Expand Down Expand Up @@ -120,7 +121,7 @@ image = cv2.imread('example.jpg', cv2.IMREAD_COLOR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
```

### **Batch Detection**
### **Batch Detection Example**

The library is also capable of performing face detection on image batches, typically providing considerable speed-up. A batch should be structured as list of images (`numpy` arrays) of equal dimension. The returned detections list will have an additional first dimension corresponding to the batch size. Each image in the batch may have one or more faces detected.

Expand Down
2 changes: 1 addition & 1 deletion fdet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = 'Antonio C. Nazare Jr.'
__email__ = '[email protected]'
__version__ = '0.2.0'
__version__ = '0.2.1'

from fdet.mtcnn import MTCNN
from fdet.retinaface import RetinaFace
Expand Down
48 changes: 35 additions & 13 deletions fdet/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
from fdet.detector import Detector
import fdet

VALID_IMG_EXTENSTIONS = (
'.bmp',
'.pbm', '.pgm', '.ppm',
'.sr', '.ras',
'.jpeg', '.jpg', '.jpe',
'.jp2',
'.tiff', '.tif',
'.png'
)


@click.group()
@click.version_option(fdet.__version__)
def main():
Expand Down Expand Up @@ -77,6 +88,12 @@ def _common_options(func):
type=click.Path(exists=False, file_okay=False, dir_okay=True, writable=True,
readable=False, resolve_path=True, allow_dash=False, path_type=None)
),
click.option(
'--color', 'draw_color',
required=False, default='blue', show_default=True,
help='The color of detected faces drawn in output frames.',
type=str
),
click.option(
'-q', '--quiet', is_flag=True, show_default=True, help='Enables quiet mode'
)
Expand Down Expand Up @@ -161,7 +178,8 @@ def __process_batch(current_batch: Iterable[Tuple[Hashable, np.ndarray]]) -> Dic
for image_key, image_detections, img in zip(batch_keys, batch_detections, batch_images):
batch_response[image_key] = image_detections
if kwargs.get('save_frames_dir') is not None:
image_output = fdet.io.draw_detections(img, image_detections, color='white',
image_output = fdet.io.draw_detections(img, image_detections,
color=kwargs.get('draw_color'),
thickness=3)
filename = image_key if isinstance(image_key, str) else str(image_key) + '.png'
filename = os.path.join(str(kwargs.get('save_frames_dir')), filename)
Expand Down Expand Up @@ -220,8 +238,8 @@ def __process_batch(current_batch: Iterable[Tuple[Hashable, np.ndarray]]) -> Dic

def _process_input(kwargs) -> Iterable[Tuple[Hashable, Union[str, np.ndarray]]]:

input_options = [kwargs['image_file'], kwargs['video_file'],
kwargs['images_list'], kwargs['images_dir']]
input_options = [kwargs.get('image_file'), kwargs.get('video_file'),
kwargs.get('images_list'), kwargs.get('images_dir')]
not_none_sum = sum(1 for _ in filter(None.__ne__, input_options))

if not_none_sum == 0:
Expand All @@ -240,16 +258,20 @@ def _process_input(kwargs) -> Iterable[Tuple[Hashable, Union[str, np.ndarray]]]:
error_msg += "'-i' / '--image'\n"
raise click.UsageError(error_msg)

if kwargs['image_file'] is not None and kwargs['image_file']:
return [(os.path.basename(ifile), ifile) for ifile in kwargs['image_file']]
if kwargs['video_file'] is not None:
return fdet.io.VideoHandle(kwargs['video_file'])
if kwargs['images_list'] is not None:
if kwargs.get('image_file') is not None and kwargs.get('image_file'):
return [(os.path.basename(ifile), ifile) for ifile in kwargs.get('image_file')]
if kwargs.get('video_file') is not None:
return fdet.io.VideoHandle(kwargs.get('video_file'))
if kwargs.get('images_list') is not None:
return [
(os.path.basename(ifile), ifile)
for ifile in open(kwargs['images_list'], 'r').read().splitlines()
for ifile in open(kwargs.get('images_list'), 'r').read().splitlines()
]
return [
(ifile, os.path.join(kwargs['images_dir'], ifile))
for ifile in os.listdir(kwargs['images_dir'])
]

#kwargs.get('images_dir') is not None:
list_of_valid_files = list()
for ifile in os.listdir(kwargs.get('images_dir')):
image_path = os.path.join(kwargs.get('images_dir'), ifile)
if os.path.splitext(image_path)[1] in VALID_IMG_EXTENSTIONS:
list_of_valid_files.append((ifile, image_path))
return list_of_valid_files
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""The setup script"""

from setuptools import setup
from setuptools import setup, find_packages

AUTHOR = 'Antonio C. Nazare Jr.'
EMAIL = '[email protected]'
VERSION = '0.2.0'
VERSION = '0.2.1'

setup(
name='fdet',
Expand Down Expand Up @@ -42,7 +42,7 @@
long_description=open('README.md').read(),
long_description_content_type='text/markdown', # This is important!
keywords='face recognition detection biometry',
packages=['fdet'],
packages=find_packages(),
zip_safe=False,
python_requires='>=3.5',
install_requires=[line for line in open('requirements.txt').read().split('\n') if line != ''],
Expand Down

0 comments on commit 1e9548e

Please sign in to comment.