Example #1
0
def start_service(model_path, config_file_path):
    """

    :type model_path: str valid path of the TF model where a .pb model file is present
    :type config_file_path: str valid path of the config file in JSON format
    :return: None
    """
    with open(config_file_path) as f:
        config = json.load(f)

    pre_process_pipeline = create_pre_process_pipeline(config)
    post_process_pipeline = create_post_process_pipeline(config)

    tensorflow_prediction = Prediction(
        model_path=model_path,
        input_tensors_names=["images:0"],
        input_fields=["images"],
        output_tensors_names=["logits:0"],
        output_fields=["images"]  # replace images with results because it's more convenient for the transforms
    )

    application = TomaatApp(
        preprocess_fun=pre_process_pipeline,
        inference_fun=tensorflow_prediction,
        postprocess_fun=post_process_pipeline
    )

    service = TomaatService(
        config=config,
        app=application,
        input_interface=input_interface,
        output_interface=output_interface
    )

    if config['announce']:
        service.start_service_announcement()

    service.run()
Example #2
0
    "port": 9000,
    "announce": False,
    "api_key": "",
}

iface_in = [{'type':'fiducials','destination':'fids'}]
iface_out = [{'type':'Fiducials','field':'fids'}]

def preprocess(data_in):
    return {'fids':[data_in['fids'][0]] }

def inference(data):
    fids_np = data['fids'][0]
    fids_neg = fids_np * -1.0
    return {
        'fids_neg': fids_neg,
    }

def postprocess(output):
    fids_neg = output['fids_neg'].astype(np.float)
    return {
        'fids':[fids_neg]
    }


my_app = TomaatApp(preprocess,inference,postprocess)

my_service = TomaatService(config, my_app, iface_in, iface_out)

my_service.run()
Example #3
0
def pre_processing_mock_function(data):
    data['input_dict_field'] = \
        (np.asarray(data['input_dict_field']) + np.asarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])).astype(np.float32)

    return data


def post_processing_mock_function(data):
    data['output_dict_field'] /= 2

    return data


mock_app = TomaatApp(
    preprocess_fun=pre_processing_mock_function,
    inference_fun=pred_object,
    postprocess_fun=post_processing_mock_function
)


def test_tomaatapp_pytorch_functionality():
    data = {'input_dict_field': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}

    result = mock_app(data)

    return result


def test_tomaatapp_pytorch_functionality_answer():
    result = test_tomaatapp_pytorch_functionality()