in container/neo_template_image_classification.py [0:0]
def preprocess(self, batch_data):
assert self._batch_size == len(batch_data), \
'Invalid input batch size: expected {} but got {}'.format(self._batch_size,
len(batch_data))
processed_batch_data = []
for k in range(len(batch_data)):
req_body = batch_data[k]
content_type = self._context.get_request_header(k, 'Content-type')
if content_type is None:
content_type = self._context.get_request_header(k, 'Content-Type')
if content_type is None:
raise Exception('Content type could not be deduced')
payload = batch_data[k].get('data')
if payload is None:
payload = batch_data[k].get('body')
if payload is None:
raise Exception('Nonexistent payload')
if content_type in SUPPORTED_CONTENT_TYPE:
try:
dtest = _load_image(payload, self.shape_info)
processed_batch_data.append(dtest)
except Exception as e:
raise Exception('ClientError: Loading image data failed with exception:\n' +
str(e))
else:
raise Exception('ClientError: Invalid content type. ' +
'Accepted content types are {}'.format(SUPPORTED_CONTENT_TYPE))
return processed_batch_data