tensorflow / tensorflow/models

Inference on quantized model

Open
#9,810 1 comment 0 reactions 3 assignees View on GitHub

Nobody has claimed this yet.

models:research:odapi type:bug
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • I checked to make sure that this issue has not already been filed.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/tree/master/research/...

2. Describe the bug

The visualization tool does not generate bounding boxes.

3. Steps to reproduce

    # Load the TFLite model and allocate tensors.
    path = os.path.join(model_dir, 'quantized', "model_int8.tflite").replace('\\', '/')
    interpreter = tf.lite.Interpreter(model_path=path)
    interpreter.allocate_tensors()
    category_index = label_map_util.create_category_index_from_labelmap(path_to_label, use_display_name=True)

    # Get input and output tensors.
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()

    # Test the model on input data.
    IMAGE_PATHS = []
    for (root, dirnames, filenames) in os.walk(data_dir):
        for image in filenames:
            if image.split('.')[-1] == "jpg":
                IMAGE_PATHS.append(os.path.join(root, image))

    for image_path in IMAGE_PATHS:
        image_np = load_image_into_numpy_array(image_path)
        input_tensor = np.expand_dims(image_np, 0)
        interpreter.set_tensor(input_details[0]['index'], input_tensor)

        print('Running inference on {} ... '.format(image_path), end='')
        start_time = time.time()
        interpreter.invoke()
        end_time = time.time()
        elapsed_time = end_time - start_time
        print('Done! Took {} seconds'.format(elapsed_time))

        # The function `get_tensor()` returns a copy of the tensor data.
        # Use `tensor()` in order to get a pointer to the tensor.
        detections_boxes = interpreter.get_tensor(output_details[0]['index']).squeeze()
        detections_classes = interpreter.get_tensor(output_details[1]['index']).squeeze()
        detections_scores = interpreter.get_tensor(output_details[2]['index']).squeeze()

        matplotlib.use('TkAgg')
        label_id_offset = 1
        image_np_with_detections = get_unscaled_image(image_path)
        viz_utils.visualize_boxes_and_labels_on_image_array(
            image_np_with_detections,
            detections_boxes,
            detections_classes.astype(np.int32)+1,
            detections_scores,
            category_index,
            use_normalized_coordinates=True,
            max_boxes_to_draw=100,
            min_score_thresh=.60,
            agnostic_mode=False)
        plt.figure()
        plt.imshow(image_np_with_detections)
    plt.show()

4. Expected behavior

The pictures appear and my output tensors are not empty, but my pictures do not have the bounding boxes even if I set the set the min_threshold to very low. I'm not what I am doing wrong. It used to work using this script but I had to reinstall due to some version issues etc.

5. Additional context

Here is the content of the three detections_* variables:
detections_boxes : [[-19 -30 23 49], [-19 -33 60 48], [ 43 31 49 49], [ 45 -13 48 0], [ 46 -30 49 -18], [ 6 22 48 47], [ 45 34 49 48], [ 45 -4 49 7], [ 45 15 48 25], [ 44 -6 48 5]]
detections_classes : [-128 -128 127 127 127 127 127 127 127 127]
detection_scores: [ 62 53 -78 -85 -85 -91 -91 -91 -91 -96]

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • Mobile device name if the issue happens on a mobile device: NA
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.5.0-dev20210318
  • Python version: 3.7.10
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.