in cvat-serverless/functions/endpoints/tf_rcnn.py [0:0]
def call(data):
buf = io.BytesIO(base64.b64decode(data["image"]))
threshold = float(data.get("threshold", 0.5))
image = Image.open(buf)
(boxes, scores, classes, num_detections) = infer(image)
results = []
for i in range(int(num_detections)):
obj_class = int(classes[i])
obj_score = scores[i]
obj_label = get_label(obj_class)
if obj_score >= threshold:
xtl = boxes[i][1] * image.width
ytl = boxes[i][0] * image.height
xbr = boxes[i][3] * image.width
ybr = boxes[i][2] * image.height
results.append({
"confidence": str(obj_score),
"label": obj_label,
"points": [xtl, ytl, xbr, ybr],
"type": "rectangle",
})
return JsonResponse(results, safe=False)