Merge pull request #107 from IndicoDataSolutions/Chris/fer-detect-no-resize

FIX: FER No resize for detect
This commit is contained in:
Madison May
2015-07-30 12:59:58 -04:00
3 changed files with 15 additions and 4 deletions
+5 -1
View File
@@ -27,6 +27,10 @@ def fer(image, cloud=None, batch=False, api_key=None, **kwargs):
:type image: list of lists :type image: list of lists
:rtype: Dictionary containing emotion probability pairs :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} url_params = {"batch": batch, "api_key": api_key}
return api_handler(image, cloud=cloud, api="fer", url_params=url_params, **kwargs) return api_handler(image, cloud=cloud, api="fer", url_params=url_params, **kwargs)
+2 -2
View File
@@ -41,7 +41,8 @@ def image_preprocess(image, size=(48,48), min_axis=None, batch=False):
else: else:
raise IndicoError("Image must be a filepath, base64 encoded string, or a numpy array") 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 # convert to base64
temp_output = StringIO.StringIO() temp_output = StringIO.StringIO()
@@ -89,4 +90,3 @@ def get_element_type(_list, dimens):
for _ in xrange(len(dimens)): for _ in xrange(len(dimens)):
elem = elem[0] elem = elem[0]
return type(elem) return type(elem)
+7
View File
@@ -87,6 +87,13 @@ class BatchAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list)) self.assertTrue(isinstance(response, list))
self.assertTrue(isinstance(response[0], dict)) 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): def test_batch_fer_pil_image(self):
test_data = [Image.open(os.path.normpath(os.path.join(DIR, "data/fear.png")))] test_data = [Image.open(os.path.normpath(os.path.join(DIR, "data/fear.png")))]
response = fer(test_data, api_key=self.api_key) response = fer(test_data, api_key=self.api_key)