forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
35 lines (29 loc) · 1010 Bytes
/
main.py
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
28
29
30
31
32
33
34
35
# Copyright (C) 2021-2022 Intel Corporation
# Copyright (C) 2022-2024 CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT
import json
import base64
from PIL import Image
import io
from model_handler import ModelHandler
def init_context(context):
context.logger.info("Init context... 0%")
model = ModelHandler() # pylint: disable=no-value-for-parameter
context.user_data.model = model
context.logger.info("Init context...100%")
def handler(context, event):
context.logger.info("call handler")
data = event.body
pos_points = data["pos_points"]
neg_points = data["neg_points"]
threshold = data.get("threshold", 0.5)
buf = io.BytesIO(base64.b64decode(data["image"]))
image = Image.open(buf).convert('RGB')
mask = context.user_data.model.handle(image, pos_points, neg_points, threshold)
return context.Response(
body=json.dumps({ 'mask': mask.tolist() }),
headers={},
content_type='application/json',
status_code=200
)