mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +08:00
Fix preprocessing for batch image features
This commit is contained in:
@@ -59,5 +59,5 @@ def image_features(api_root, image, batch=False, auth=None, **kwargs):
|
||||
:type image: numpy.ndarray
|
||||
:rtype: List containing features
|
||||
"""
|
||||
image = image_preprocess(image)
|
||||
image = image_preprocess(image, batch=batch)
|
||||
return api_handler(image, api_root + "imagefeatures", batch=batch, auth=auth, **kwargs)
|
||||
|
||||
@@ -120,11 +120,13 @@ def normalize(array, distribution=1, norm_range=(0, 1), **kwargs):
|
||||
return dict(zip(keys, norm_array))
|
||||
return norm_array
|
||||
|
||||
def image_preprocess(image):
|
||||
def image_preprocess(image, batch=False):
|
||||
"""
|
||||
Takes an image and prepares it for sending to the api including
|
||||
resizing and image data/structure standardizing.
|
||||
"""
|
||||
if batch:
|
||||
return [image_preprocess(img, batch=False) for img in image]
|
||||
if isinstance(image,list):
|
||||
image = np.asarray(image)
|
||||
if type(image).__module__ != np.__name__:
|
||||
|
||||
@@ -37,6 +37,39 @@ class BatchAPIRun(unittest.TestCase):
|
||||
response = batch_political(test_data, auth=self.auth)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
|
||||
def test_batch_fer(self):
|
||||
test_data = [np.random.rand(48, 48).tolist()]
|
||||
response = batch_fer(test_data, auth=self.auth)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(isinstance(response[0], dict))
|
||||
|
||||
def test_batch_facial_features(self):
|
||||
test_data = [np.random.rand(48, 48).tolist()]
|
||||
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)
|
||||
|
||||
def test_batch_image_features_greyscale(self):
|
||||
test_data = [np.random.rand(64, 64).tolist()]
|
||||
response = batch_image_features(test_data, auth=self.auth)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(isinstance(response[0], list))
|
||||
self.assertEqual(len(response[0]), 2048)
|
||||
|
||||
def test_batch_image_features_rgb(self):
|
||||
test_data = [np.random.rand(64, 64, 3).tolist()]
|
||||
response = batch_image_features(test_data, auth=self.auth)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(isinstance(response[0], list))
|
||||
self.assertEqual(len(response[0]), 2048)
|
||||
|
||||
def test_batch_language(self):
|
||||
test_data = ['clearly an english sentence']
|
||||
response = batch_language(test_data, auth=self.auth)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(response[0]['English'] > 0.25)
|
||||
|
||||
|
||||
class FullAPIRun(unittest.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user