mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +08:00
routing around image_preprocessing for urls
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import json
|
||||
|
||||
import requests
|
||||
import numpy as np
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user