From 43a541ca05f38ce0546738db1cec3da1766665e1 Mon Sep 17 00:00:00 2001 From: Chris Lee Date: Thu, 30 Jul 2015 09:56:35 -0400 Subject: [PATCH] FIX: FER No resize for detect --- indicoio/images/fer.py | 6 +++++- indicoio/utils/image.py | 6 +++--- tests/test_remote.py | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/indicoio/images/fer.py b/indicoio/images/fer.py index 87612e2..46639af 100644 --- a/indicoio/images/fer.py +++ b/indicoio/images/fer.py @@ -27,6 +27,10 @@ def fer(image, cloud=None, batch=False, api_key=None, **kwargs): :type image: list of lists :rtype: Dictionary containing emotion probability pairs """ - image = image_preprocess(image, batch=batch) + + image = image_preprocess(image, batch=batch, + size=None if kwargs.get("detect") else (48, 48) + ) + url_params = {"batch": batch, "api_key": api_key} return api_handler(image, cloud=cloud, api="fer", url_params=url_params, **kwargs) diff --git a/indicoio/utils/image.py b/indicoio/utils/image.py index 50a5eb6..14e4f2a 100644 --- a/indicoio/utils/image.py +++ b/indicoio/utils/image.py @@ -41,7 +41,8 @@ def image_preprocess(image, size=(48,48), min_axis=None, batch=False): else: raise IndicoError("Image must be a filepath, base64 encoded string, or a numpy array") - out_image = resize_image(out_image, size, min_axis) + if size or min_axis: + out_image = resize_image(out_image, size, min_axis) # convert to base64 temp_output = StringIO.StringIO() @@ -60,7 +61,7 @@ def resize_image(image, size, min_axis): warnings.warn( "An aspect ratio greater than 10:1 is not recommended", Warning - ) + ) size_arr = [0,0] size_arr[min_idx] = min_axis size_arr[other_idx] = int(min_axis * aspect) @@ -89,4 +90,3 @@ def get_element_type(_list, dimens): for _ in xrange(len(dimens)): elem = elem[0] return type(elem) - diff --git a/tests/test_remote.py b/tests/test_remote.py index 1a612f7..e0c645a 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -87,6 +87,13 @@ class BatchAPIRun(unittest.TestCase): self.assertTrue(isinstance(response, list)) self.assertTrue(isinstance(response[0], dict)) + def test_fer_detect(self): + test_data = os.path.normpath(os.path.join(DIR, "data/fear.png")) + response = fer(test_data, api_key=self.api_key, detect=True) + self.assertIsInstance(response, list) + self.assertEqual(len(response), 1) + self.assertIn("location", response[0]) + def test_batch_fer_pil_image(self): test_data = [Image.open(os.path.normpath(os.path.join(DIR, "data/fear.png")))] response = fer(test_data, api_key=self.api_key)