Merge pull request #59 from IndicoDataSolutions/Chris/accept-pil

FIX: accept PIL Image as input
This commit is contained in:
Madison May
2015-06-05 17:22:57 -04:00
2 changed files with 14 additions and 0 deletions
+2
View File
@@ -107,6 +107,8 @@ def image_preprocess(image, size=(48,48), batch=False):
DeprecationWarning
)
outImage = process_list_image(image)
elif isinstance(image, Image.Image):
outImage = image
elif type(image).__name__ == "ndarray": # image is from numpy/scipy
out_image = Image.fromarray(image)
else:
+12
View File
@@ -62,6 +62,12 @@ class BatchAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list))
self.assertTrue(isinstance(response[0], dict))
def test_batch_fer_pil_image(self):
test_data = [Image.open(os.path.normpath(os.path.join(DIR, "data/fear.png")))]
response = batch_fer(test_data, api_key=self.api_key)
self.assertTrue(isinstance(response, list))
self.assertTrue(isinstance(response[0], dict))
def test_batch_fer_nonexistant_filepath(self):
test_data = ["data/unhappy.png"]
self.assertRaises(ValueError, batch_fer, test_data, api_key=self.api_key)
@@ -184,6 +190,12 @@ class FullAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, dict))
self.assertTrue(response['Happy'] > 0.5)
def test_happy_fer_pil(self):
test_face = Image.open(os.path.normpath(os.path.join(DIR, "data/happy.png"))).convert('L');
response = fer(test_face)
self.assertTrue(isinstance(response, dict))
self.assertTrue(response['Happy'] > 0.5)
def test_fear_fer(self):
test_face = self.load_image("data/fear.png", as_grey=True)
response = fer(test_face)