def pre_process(image_path):
    """
    Pre-process the input image to return a json to pass to the tf model

    Args:
        image_path (str):  Path to the jpeg image

    Returns:
        formatted_json_input (str)
    """

    image = Image.open(image_path).convert("RGB")

    image_np = plot_util.load_image_into_numpy_array(image)
    #print("image shape", image_np.shape)

    # Expand dims to create  bach of size 1
    image_tensor = np.expand_dims(image_np, 0)
    np.save("image_tensor", image)
    #print(image_np)
    formatted_json_input = json.dumps({
        "signature_name":
        "serving_default",
        "instances":
        image_tensor.tolist(),
        "model_name":
        "v1/models/faster_rcnn_resnet:predict"
    })

    return formatted_json_input
Exemple #2
0
def pre_process(image_path):

    image = Image.open(image_path).convert("RGB")
    image_np = plot_util.load_image_into_numpy_array(image)

    # Expand dims to create  bach of size 1
    image_tensor = np.expand_dims(image_np, 0)
    formatted_json_input = json.dumps({
        "signature_name": "serving_default",
        "instances": image_tensor.tolist()
    })

    return formatted_json_input
Exemple #3
0
    # Post process output
    print(f'\n\nPost-processing server response...\n')
    post_processed_data = post_process(server_response)
    print(f'Post-processing done!\n')

    # Save output on disk
    print(f'\n\nSaving output to {output_image}\n\n')
    with open(output_image, 'w+') as outfile:
        json.dump(post_processed_data, outfile)
    print(f'Output saved!\n')

    if save_output_image:
        # Save output on disk
        print('\n\nBuilding output image\n\n')
        image = Image.open(image_path).convert("RGB")
        image_np = plot_util.load_image_into_numpy_array(image)

        category_index = plot_util.load_category_index(
            path_to_labels,
            99999)  # FIXME: Magic number to replace by meaningful var

        # Visualization of the results of a detection.
        vis_util.visualize_boxes_and_labels_on_image_array(
            image_np,
            np.array(post_processed_data['detection_boxes']
                     ),  # NOTE: np.array needed for .shape property
            post_processed_data['detection_classes'],
            post_processed_data['detection_scores'],
            category_index,
            instance_masks=post_processed_data.get('detection_masks'),
            use_normalized_coordinates=True,