File size: 898 Bytes
51a9bb2
 
 
7e86222
51a9bb2
 
 
 
 
 
477cb68
f78ab1e
51a9bb2
477cb68
 
 
51a9bb2
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import bentoml
from bentoml.io import Image, JSON
from transformers import pipeline


class PretrainedModelRunnable(bentoml.Runnable):
    SUPPORTED_RESOURCES = ("cpu",)
    SUPPORTS_CPU_MULTI_THREADING = True

    def __init__(self):
        self.object_detector = pipeline('object-detection', model="biglam/detr-resnet-50_fine_tuned_nls_chapbooks",
                                  feature_extractor="biglam/detr-resnet-50_fine_tuned_nls_chapbooks")

    @bentoml.Runnable.method(batchable=False)
    def __call__(self, input_image):
        return self.object_detector(input_image)


runner = bentoml.Runner(PretrainedModelRunnable, name="pretrained_illustration_detection")

svc = bentoml.Service('pretrained_illustration_detection', runners=[runner])


@svc.api(input=Image(), output=JSON())
async def object_detect(input_series: str) -> list:
    return await runner.async_run(input_series)