def transformation()

in source/containers/face-comparison/recognizer/predictor.py [0:0]


def transformation():
    """
    Do an inference on a single batch of data. In this sample server, we take image data as base64 formation,
    decode it for internal use and then convert the predictions to json format

    :return:
    """
    t_start = time.time()

    if flask.request.content_type == 'application/json':
        request_body = flask.request.data.decode('utf-8')
        request_body = json.loads(request_body)
        source_image_base64 = request_body['source_image_bytes']
        target_image_base64 = request_body['target_image_bytes']
    else:
        return flask.Response(
            response='Face comparison only supports application/json data',
            status=415,
            mimetype='text/plain')

    # inference
    body = FaceRecognizerService.predict(
        source_image_base64,
        target_image_base64,
        min_confidence_thresh=0.65
    )

    t_end = time.time()
    print('Time consumption = {} second'.format(t_end - t_start))
    print('Response = {}'.format(body))

    return flask.Response(response=json.dumps(body), status=200, mimetype='application/json')