Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postprocessing method for exported model? #11203

Closed
3zhang opened this issue May 8, 2024 · 4 comments
Closed

Postprocessing method for exported model? #11203

3zhang opened this issue May 8, 2024 · 4 comments
Assignees
Labels
models:official models that come under official repository stale stat:awaiting response Waiting on input from the contributor type:support

Comments

@3zhang
Copy link

3zhang commented May 8, 2024

I'm following this tutorial for object detection:
https://www.tensorflow.org/tfmodels/vision/object_detection

At the end, the Visualize predictions part, the result visualized are based on the resized input. Is there any postprocessing function to convert the resized result into the result corresponding to the original image?

#Visualize predictions.
input_image_size = (HEIGHT, WIDTH)
plt.figure(figsize=(20, 20))
min_score_thresh = 0.30 # Change minimum score for threshold to see all bounding boxes confidences.

for i, serialized_example in enumerate(test_ds):
  plt.subplot(1, 3, i+1)
  decoded_tensors = tf_ex_decoder.decode(serialized_example)
  image = build_inputs_for_object_detection(decoded_tensors['image'], input_image_size)
  image = tf.expand_dims(image, axis=0)
  image = tf.cast(image, dtype = tf.uint8)
  image_np = image[0].numpy()
  result = model_fn(image)
  visualization_utils.visualize_boxes_and_labels_on_image_array(
      image_np,
      result['detection_boxes'][0].numpy(),
      result['detection_classes'][0].numpy().astype(int),
      result['detection_scores'][0].numpy(),
      category_index=category_index,
      use_normalized_coordinates=False,
      max_boxes_to_draw=200,
      min_score_thresh=min_score_thresh,
      agnostic_mode=False,
      instance_masks=None,
      line_thickness=4)
  plt.imshow(image_np)
  plt.axis('off')

plt.show()
@laxmareddyp laxmareddyp added the models:official models that come under official repository label May 8, 2024
@laxmareddyp
Copy link
Collaborator

Hi @3zhang ,

There is no mention of a specific postprocessing function to convert the resized result back to the original image in the TensorFlow object detection tutorial. However, it's likely because the bounding boxes coordinates predicted by the model are based on the resized image. You can simply scale the bounding boxes back to the original image dimensions to get the corresponding bounding boxes in the original image.

As a work around,Calculate the scaling factor between the original image size and the resized image size.
Multiply the predicted bounding box coordinates (xmin, ymin, xmax, ymax) by the scaling factor to get the coordinates in the original image.

Meanwhile we will try modify the above visualization function with few parameters changes and check the results on original image input directly instead of resized image.

Thanks.

@laxmareddyp laxmareddyp added the stat:awaiting response Waiting on input from the contributor label May 8, 2024
Copy link

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label May 16, 2024
Copy link

This issue was closed due to lack of activity after being marked stale for past 7 days.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
models:official models that come under official repository stale stat:awaiting response Waiting on input from the contributor type:support
Projects
None yet
Development

No branches or pull requests

2 participants