Coder Social home page Coder Social logo

ipazc / vrpwrp Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 5.0 1.14 MB

VRPWRP (Vision-algorithms Requests Processing Wrappers), a pip package for running deep-learning Computer Vision algorithms from the cloud.

License: MIT License

Python 100.00%

vrpwrp's Introduction

VRPWRP 0.0.7

VRPWRP (Vision-algorithm Requests Processing Wrappers) is a package that wraps an API-REST for Computer Vision deep-learning algorithms. Currently, it supports state-of-the-art face-detection and face-recognition algorithms out-of-the-box.

https://travis-ci.org/ipazc/vrpwrp.svg?branch=master https://coveralls.io/repos/github/ipazc/vrpwrp/badge.svg?branch=master Code Health

Installation

Currently it is only supported Python 3.4.1 onwards:

sudo pip3 install vrpwrp

Face detection

Face detection allows you to retrieve the location of faces inside images in the form of bounding boxes (left, top, width, height). The algorihm is a deep-learning based algorithm, composed by a cascade of Convolutional Neural Networks. It is based on the paper Zhang et al. (2016) [ZHANG2016]. The backend runs a Caffe-based MTCNN influenced by this python MTCNN version .

A simple example for retrieving the bounding boxes of faces from an image:

>>> from vrpwrp.wrappers.face_detection import FaceDetection
>>> face_detection = FaceDetection()
>>> bounding_boxes = face_detection.analyze_file("route/to/image.jpg")
>>> for bb in bounding_boxes: print(bb)
...
[162, 79, 114, 146]

FaceDetection has methods for analyzing images also from bytes, URLs and pillow images directly:

>>> bounding_boxes = face_detection.analyze_bytes(image_bytes)
>>> bounding_boxes = face_detection.analyze_url(image_url)
>>> bounding_boxes = face_detection.analyze_pil(pillow_image)
...

Face Recognition

Face recognition allows extracting the identity of a face within a given image of the face. The identity is a set of float numbers (since it is deep-learning-based, it is the output of the last convolution layer of a Convolutional Neural Network). The algorithm is based on the papers Schroff et al. (2015) [SCHROFF2015], Wen et al. (2016) [WEN2016]. and Parkhi et al. (2015) [PARKHI2015]. The backend is influenced by Facenet, using TensorFlow.

In vrpwrp, the identity of a face is also known as embeddings.

A simple example for retrieving the embeddings of a face is:

>>> from vrpwrp.wrappers.face_recognition import FaceRecognition
>>> face_recognition = FaceRecognition()
>>> face_embeddings = face_recognition.get_embeddings_from_file("route/to/image_of_face.jpg")
>>> print(face_embeddings)
[-0.05258641 -0.14807236  0.21828972  0.00097196  0.08881456  0.01356898 -0.01393933 -0.09459263 -0.07305822  0.00354048  0.1649337  -0.05636634  0.03599492 -0.02649886 ...]

Like in FaceDetection, it allows to analyze images from different sources:

>>> embeddings = face_recognition.get_embeddings_from_bytes(image_bytes)
>>> embeddings = face_recognition.get_embeddings_from_url(image_url)
>>> embeddings = face_recognition.get_embeddings_from_pil(pillow_image)
...

The embeddings of two faces can be easily compared to see how close they are:

>>> face1_embeddings = face_recognition.get_embeddings_from_file("route/to/image_of_face1.jpg")
>>> face2_embeddings = face_recognition.get_embeddings_from_file("route/to/image_of_face2.jpg")
>>> print(face1_embeddings - face2_embeddings)
0.5634614628831894

A value close to 0 indicates that two faces might be of the same person. In this example, image_of_face1.jpg and image_of_face2.jpg are likely to be of the same person. Otherwise, a value over 1.0 might indicate that two faces are not likely to be of the same person.

This might lead to a scenario where you store lot of embeddings and want to compare a single one with each of them, resulting in a loop like the following:

faces_embeddings = [emb1, emb2, ..., embN]

new_embedding = face_recognition.get_embeddings_from_file("route/to/image_of_face1.jpg")

for embedding in faces_embeddings:
     distance = embedding - new_embedding

Rather than using a loop (even if it is a list-comprehension), there is an optimized and preferred way of performing such a comparison that can be used instead:

faces_embeddings = [emb1, emb2, ..., embN]

new_embedding = face_recognition.get_embedding_from_file("route/to/image_of_face1.jpg")
distances = face_recognition.get_embeddings_distances(new_embedding, faces_embeddings)

References

[ZHANG2016]Zhang, K., Zhang, Z., Li, Z., and Qiao, Y. (2016). Joint face detection and alignment using multitask cascaded convolutional networks. IEEE Signal Processing Letters, 23(10):1499โ€“1503.
[SCHROFF2015]Schroff, F., Kalenichenko, D., & Philbin, J. (2015). Facenet: A unified embedding for face recognition and clustering. In Proceedings of the IEEE Conference on CVPR (pp. 815-823).
[WEN2016]Wen, Y., Zhang, K., Li, Z., & Qiao, Y. (2016, October). A discriminative feature learning approach for deep face recognition. In ECCV (pp. 499-515). Springer International Publishing.
[PARKHI2015]Parkhi, O. M., Vedaldi, A., & Zisserman, A. (2015, September). Deep Face Recognition. In BMVC (Vol. 1, No. 3, p. 6).

vrpwrp's People

Contributors

ipazc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vrpwrp's Issues

JSONDecodeError

Running this piece of code:

face_detection = FaceDetection()
frame = cv2.imread('image_file.jpg')
bounding_boxes = face_detection.analyze_pil(Image.fromarray(frame))  

Gives the following error (JSONDecodeError: Expecting value: line 1 column 1 (char 0)):

File "C:/Users/wsarguroh001/Downloads/Powai_Rainbow_Cropped.py", line 69, in <module>
    bounding_boxes = face_detection.analyze_pil(Image.fromarray(frame))
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\vrpwrp\wrappers\face_detection.py", line 100, in analyze_pil
    return self.analyze_bytes(image_bytes)
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\vrpwrp\wrappers\face_detection.py", line 48, in analyze_bytes
    response = self._request("PUT", data=image_bytes, is_binary=True)['bounding_boxes']
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\vrpwrp\wrappers\APIWrapper.py", line 27, in _request
    return response.json()
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\simplejson\__init__.py", line 517, in loads
    return _default_decoder.decode(s)
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\simplejson\decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\simplejson\decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\simplejson\scanner.py", line 79, in scan_once
    return _scan_once(string, idx)
  File "C:\Users\wsarguroh001\AppData\Local\Continuum\anaconda3\lib\site-packages\simplejson\scanner.py", line 70, in _scan_once
    raise JSONDecodeError(errmsg, string, idx)
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

It used to work just fine earlier. Also it works alright on another system but throws this error on mine. Tried uninstalling and reinstalling the wrapper but to no effect.

A higher version of requests lib should be required when installing this package

in an ubuntu 14.04, the default python requests lib is too low. It raises the following error:

print(dTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/dhub/datasets.py", line 38, in __init__
    self.refresh()
  File "/usr/local/lib/python3.4/dist-packages/dhub/datasets.py", line 111, in refresh
    self.datasets = {d['url_prefix']: dict(definition=d, token=self.token, token_info=self.token_info, server_info=self.server_info, owner=self) for d in self._get_json("datasets")}
  File "/usr/local/lib/python3.4/dist-packages/dhub/wrapper/api_wrapper.py", line 115, in _get_json
    return self.__do_json_request(requests.get, rel_url, extra_data, json_data).json()
  File "/usr/local/lib/python3.4/dist-packages/dhub/wrapper/api_wrapper.py", line 50, in fun
    raise last_exception
  File "/usr/local/lib/python3.4/dist-packages/dhub/wrapper/api_wrapper.py", line 43, in fun
    result = func_wrap(obj, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/dhub/wrapper/api_wrapper.py", line 100, in __do_json_request
    response = method("{}/{}".format(self.api_url, rel_url), json=json_data, params=data, timeout=TIMEOUT)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'json'

it would be a good idea to require at least requests-2.18.4

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.