Skip to content

Commit

Permalink
Add a placeholder for MultiImageInput (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
bojiang committed Jun 16, 2020
1 parent 2f138fc commit a6e6eba
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bentoml/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bentoml.adapters.tensorflow_tensor_input import TfTensorInput
from bentoml.adapters.json_input import JsonInput
from bentoml.adapters.image_input import ImageInput
from bentoml.adapters.multi_image_input import MultiImageInput
from bentoml.adapters.legacy_image_input import LegacyImageInput
from bentoml.adapters.fastai_image_input import FastaiImageInput
from bentoml.adapters.clipper_input import (
Expand Down Expand Up @@ -49,6 +50,7 @@
"JsonInput",
'JsonSerializableOutput',
"ImageInput",
"MultiImageInput",
"LegacyImageInput",
"FastaiImageInput",
"ClipperBytesInput",
Expand Down
97 changes: 97 additions & 0 deletions bentoml/adapters/multi_image_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 2019 Atalaya Tech, Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from bentoml.adapters.base_input import BaseInputAdapter
from bentoml.adapters.image_input import get_default_accept_image_formats


class MultiImageInput(BaseInputAdapter):
"""
Warning: this is a not yet implemented, follow issue #806 for updates
Transform incoming images data from http request, cli or lambda event into numpy
array.
Args:
input_names (string[]]): A tuple of acceptable input name for HTTP request.
Default value is (image,)
accept_image_formats (string[]): A list of acceptable image formats.
Default value is loaded from bentoml config
'apiserver/default_image_input_accept_file_extensions', which is
set to ['.jpg', '.png', '.jpeg', '.tiff', '.webp', '.bmp'] by default.
List of all supported format can be found here:
https://imageio.readthedocs.io/en/stable/formats.html
pilmode (string): The pilmode to be used for reading image file into numpy
array. Default value is 'RGB'. Find more information at:
https://imageio.readthedocs.io/en/stable/format_png-pil.html
Raises:
ImportError: imageio package is required to use ImageInput
Example usage:
```
class MyService(BentoService):
@bentoml.api(input=MultiImageInput(input_names=('imageX', 'imageY')))
def predict(self, image_groups):
for image_group in image_groups:
image_array_x = image_group['imageX']
image_array_y = image_group['imageY']
```
"""

def __init__(
self,
input_names=("image",),
accept_image_formats=None,
pilmode="RGB",
is_batch_input=False,
**base_kwargs,
):
if is_batch_input:
raise ValueError('ImageInput can not accpept batch inputs')
super(MultiImageInput, self).__init__(**base_kwargs)
self.input_names = input_names
self.pilmode = pilmode
self.accept_image_formats = (
accept_image_formats or get_default_accept_image_formats()
)

def handle_batch_request(self, requests, func):
"""Handles an HTTP request, convert it into corresponding data
format that user API function is expecting, and return API
function result as the HTTP response to client
:param requests: List of flask request object
:param func: user API function
"""
raise NotImplementedError

def handle_cli(self, args, func):
"""Handles an CLI command call, convert CLI arguments into
corresponding data format that user API function is expecting, and
prints the API function result to console output
:param args: CLI arguments
:param func: user API function
"""
raise NotImplementedError

def handle_aws_lambda_event(self, event, func):
"""Handles a Lambda event, convert event dict into corresponding
data format that user API function is expecting, and use API
function result as response
:param event: AWS lambda event data of the python `dict` type
:param func: user API function
"""
raise NotImplementedError

0 comments on commit a6e6eba

Please sign in to comment.