in cvat-serverless/functions/endpoints/tf_rcnn.py [0:0]
def infer(image):
width, height = image.size
if width > 1920 or height > 1080:
image = image.resize((width // 2, height // 2), Image.ANTIALIAS)
image_np = np.array(image.getdata())[:, :3].reshape(
(image.height, image.width, -1)).astype(np.uint8)
image_np = np.expand_dims(image_np, axis=0)
client = boto3.client('runtime.sagemaker')
data = image_np.tolist()
response = client.invoke_endpoint(EndpointName=settings.TF_RCNN_ENDPOINT,
Body=json.dumps(data),
TargetContainerHostname=settings.TF_RCNN_NAME,
ContentType='application/json')
response_body = response['Body'].read()
result = json.loads(response_body.decode('utf-8'))['predictions'][0]
return (result['detection_boxes'], result['detection_scores'],
result['detection_classes'], result['num_detections'])