import bentoml from bentoml.adapters import TfTensorInput from bentoml.frameworks.tensorflow import TensorflowSavedModelArtifact @bentoml.env(infer_pip_packages=True) @bentoml.artifacts([TensorflowSavedModelArtifact('model')]) class Tensorflow2Classifier(bentoml.BentoService): @bentoml.api(input=TfTensorInput()) def predict(self, tensor): return self.artifacts.model(tensor)
import bentoml from bentoml.adapters import JsonInput, TfTensorInput from bentoml.frameworks.tensorflow import TensorflowSavedModelArtifact @bentoml.env(infer_pip_packages=True) @bentoml.artifacts([ TensorflowSavedModelArtifact('model1'), TensorflowSavedModelArtifact('model2'), TensorflowSavedModelArtifact('model3'), ]) class Tensorflow2Classifier(bentoml.BentoService): @bentoml.api(input=TfTensorInput(), batch=True) def predict1(self, tensor): return self.artifacts.model1(tensor) @bentoml.api(input=TfTensorInput(), batch=True) def predict2(self, tensor): return self.artifacts.model2(tensor) @bentoml.api(input=JsonInput(), batch=True) def predict3(self, jsons): import tensorflow as tf tensor = tf.ragged.constant(jsons, dtype=tf.float64) return self.artifacts.model3(tensor)
import bentoml import io import tensorflow as tf import numpy as np from config import InferenceConfig, INPUT_IMAGE, INPUT_IMAGE_META, INPUT_ANCHORS from docparser import stage2_structure_parser from docparser.utils.data_utils import DocsDataset from docparser.utils.eval_utils import convert_bbox_list_to_save_format from util import ForwardModel tf.compat.v1.enable_eager_execution() # required @bentoml.env(pip_packages=['tensorflow']) @bentoml.artifacts([TensorflowSavedModelArtifact('trackable')]) class DocparserService(bentoml.BentoService): def __init__(self): super().__init__() model_config = InferenceConfig() self.preprocess_obj = ForwardModel(model_config) def preprocess(self, image): images = np.expand_dims(image, axis=0)[:,:,:,:3] molded_images, image_metas, windows = self.preprocess_obj.mold_inputs(images) molded_images = molded_images.astype(np.float32) image_shape = molded_images[0].shape for g in molded_images[1:]: assert g.shape == image_shape, \ "After resizing, all images must have the same size. Check IMAGE_RESIZE_MODE and image sizes."