Merge pull request #34 from IndicoDataSolutions/annie/preprocess

routing around image_preprocessing for urls
This commit is contained in:
Anne
2015-03-12 11:33:06 -04:00
5 changed files with 52 additions and 7 deletions
+3 -4
View File
@@ -1,9 +1,7 @@
import json
import requests
import numpy as np
from indicoio.utils import image_preprocess, api_handler
from indicoio.utils import image_preprocess, api_handler, is_url
import indicoio.config as config
def facial_features(image, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
@@ -60,5 +58,6 @@ def image_features(image, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
:type image: numpy.ndarray
:rtype: List containing features
"""
image = image_preprocess(image, batch=batch)
if not is_url(image, batch=batch):
image = image_preprocess(image, batch=batch)
return api_handler(image, cloud=cloud, api="imagefeatures", batch=batch, auth=auth, **kwargs)
-2
View File
@@ -1,5 +1,3 @@
import json
import requests
import numpy as np
+11 -1
View File
@@ -14,7 +14,7 @@ def api_handler(arg, cloud, api, batch=False, auth=None, **kwargs):
if cloud:
host = "%s.indico.domains" % cloud
else:
else:
# default to indico public cloud
host = config.PUBLIC_API_HOST
@@ -142,3 +142,13 @@ def image_preprocess(image, batch=False):
image = resize(image,(64,64))
image = image.tolist()
return image
def is_url(data, batch=False):
if batch and isinstance(data[0], basestring):
return True
if not batch and isinstance(data, basestring):
return True
return False
+15
View File
@@ -0,0 +1,15 @@
from indicoio.utils import is_url
def test_is_urls():
boring_image = [0]*(32**2)
boring_images = [boring_image]*100
assert not is_url(boring_image, batch=False)
assert not is_url(boring_images, batch=True)
url = 'http://picturepicture.com/picture'
urls = [url]*100
assert is_url(url, batch=False)
assert is_url(urls, batch=True)
+23
View File
@@ -50,6 +50,19 @@ class BatchAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response[0], list))
self.assertEqual(len(response[0]), 48)
# TODO: uncomment this test once the remote server is updated to
# deal with image_urls
# def test_batch_image_urls(self):
# test_data = ['http://textfac.es/static/ico/favicon.png',
# 'http://textfac.es/static/ico/favicon.png']
# response = batch_facial_features(test_data, auth=self.auth)
# self.assertTrue(isinstance(response, list))
# self.assertTrue(isinstance(response[0], list))
# self.assertEqual(len(response[0]), 48)
# TODO: add tests to test when one url is incorrect once we
# have decided how we are dealing with them
def test_batch_image_features_greyscale(self):
test_data = [np.random.rand(64, 64).tolist()]
response = batch_image_features(test_data, auth=self.auth)
@@ -165,6 +178,16 @@ class FullAPIRun(unittest.TestCase):
self.assertEqual(len(response), 48)
self.check_range(response)
# TODO: uncomment this test once the remote server is updated to
# deal with image_urls
# def test_image_url(self):
# test_face = 'http://textfac.es/static/ico/favicon.png'
# response = facial_features(test_face)
# self.assertTrue(isinstance(response, list))
# self.assertEqual(len(response), 48)
# self.check_range(response)
def test_good_image_features_greyscale(self):
test_image = np.random.rand(64, 64).tolist()
response = image_features(test_image)