Passing in a root_url variable and pulling config from environment variables

This commit is contained in:
Anne Carlson
2015-02-27 16:32:32 -05:00
committed by Madison May
parent a1621e8531
commit 6b9251f4f5
7 changed files with 39 additions and 37 deletions
+8 -7
View File
@@ -4,12 +4,13 @@ import requests
import numpy as np
from indicoio.utils import image_preprocess, api_handler
import indicoio.config as config
def facial_features(api_root, image, batch=False, auth=None, **kwargs):
def facial_features(image, url_root=config.api_root, batch=False, auth=None, **kwargs):
"""
Given an grayscale input image of a face, returns a 48 dimensional feature vector explaining that face.
Useful as a form of feature engineering for face oriented tasks.
Input should be in a list of list format, resizing will be attempted internally but for best
Input should be in a list of list format, resizing will be attempted internally but for best
performance, images should be already sized at 48x48 pixels.
Example usage:
@@ -27,18 +28,18 @@ def facial_features(api_root, image, batch=False, auth=None, **kwargs):
:type image: list of lists
:rtype: List containing feature responses
"""
return api_handler(image, api_root + "facialfeatures", batch=batch, auth=auth, **kwargs)
return api_handler(image, url_root + "facialfeatures", batch=batch, auth=auth, **kwargs)
def image_features(api_root, image, batch=False, auth=None, **kwargs):
def image_features(image, url_root=config.api_root, batch=False, auth=None, **kwargs):
"""
Given an input image, returns a 2048 dimensional sparse feature vector explaining that image.
Given an input image, returns a 2048 dimensional sparse feature vector explaining that image.
Useful as a form of feature engineering for image oriented tasks.
* Input can be either grayscale or rgb color and should either be a numpy array or nested list format.
* Input data should be either uint8 0-255 range values or floating point between 0 and 1.
* Large images (i.e. 1024x768+) are much bigger than needed, resizing will be done internally to 64x64 if needed.
* For ideal performance, images should be square aspect ratio but non-square aspect ratios are supported as well.
Example usage:
.. code-block:: python
@@ -60,4 +61,4 @@ def image_features(api_root, image, batch=False, auth=None, **kwargs):
:rtype: List containing features
"""
image = image_preprocess(image, batch=batch)
return api_handler(image, api_root + "imagefeatures", batch=batch, auth=auth, **kwargs)
return api_handler(image, url_root + "imagefeatures", batch=batch, auth=auth, **kwargs)
+9 -7
View File
@@ -2,12 +2,14 @@ import json
import requests
import numpy as np
from indicoio.utils import api_handler
def fer(api_root, image, batch=False, auth=None, **kwargs):
from indicoio.utils import api_handler
import indicoio.config as config
def fer(image, url_root=config.api_root, batch=False, auth=None, **kwargs):
"""
Given a grayscale input image of a face, returns a probability distribution over emotional state.
Input should be in a list of list format, resizing will be attempted internally but for best
Input should be in a list of list format, resizing will be attempted internally but for best
performance, images should be already sized at 48x48 pixels..
Example usage:
@@ -19,13 +21,13 @@ def fer(api_root, image, batch=False, auth=None, **kwargs):
>>> face = np.zeros((48,48)).tolist()
>>> emotions = fer(face)
>>> emotions
{u'Angry': 0.6340586827229989, u'Sad': 0.1764309536057839,
u'Neutral': 0.05582989039191157, u'Surprise': 0.0072685938275375344,
{u'Angry': 0.6340586827229989, u'Sad': 0.1764309536057839,
u'Neutral': 0.05582989039191157, u'Surprise': 0.0072685938275375344,
u'Fear': 0.08523385724298838, u'Happy': 0.04117802220878012}
:param image: The image to be analyzed.
:type image: list of lists
:rtype: Dictionary containing emotion probability pairs
"""
return api_handler(image, api_root + "fer", batch=batch, auth=auth, **kwargs)
return api_handler(image, url_root + "fer", batch=batch, auth=auth, **kwargs)