models icon indicating copy to clipboard operation
models copied to clipboard

Object Detection model failed to predict some pics.

Open Neway6655 opened this issue 5 years ago • 5 comments

Prerequisites

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

  • [x] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • [x] I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • [x] 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/object_detection

2. Describe the bug

I found the object detection model failed to predict some pics, I am using 'centernet_hourglass104_512x512_kpts_coco17_tpu-32.config' to predict the pic has 'person' or not, I followed the instruction , but got exception as followed:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-102-7e6d0a7a9ef0> in <module>
     14 input_tensor = tf.convert_to_tensor(
     15     np.expand_dims(image_np, 0), dtype=tf.float32)
---> 16 detections, predictions_dict, shapes = detect_fn(input_tensor)
     17 
     18 label_id_offset = 1

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
    778       else:
    779         compiler = "nonXla"
--> 780         result = self._call(*args, **kwds)
    781 
    782       new_tracing_count = self._get_tracing_count()

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
    805       # In this case we have created variables on the first call, so we run the
    806       # defunned version which is guaranteed to never create variables.
--> 807       return self._stateless_fn(*args, **kwds)  # pylint: disable=not-callable
    808     elif self._stateful_fn is not None:
    809       # Release the lock early so that multiple threads can perform the call

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py in __call__(self, *args, **kwargs)
   2827     with self._lock:
   2828       graph_function, args, kwargs = self._maybe_define_function(args, kwargs)
-> 2829     return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
   2830 
   2831   @property

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _filtered_call(self, args, kwargs, cancellation_manager)
   1846                            resource_variable_ops.BaseResourceVariable))],
   1847         captured_inputs=self.captured_inputs,
-> 1848         cancellation_manager=cancellation_manager)
   1849 
   1850   def _call_flat(self, args, captured_inputs, cancellation_manager=None):

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
   1922       # No tape is watching; skip to running the function.
   1923       return self._build_call_outputs(self._inference_function.call(
-> 1924           ctx, args, cancellation_manager=cancellation_manager))
   1925     forward_backward = self._select_forward_and_backward_functions(
   1926         args,

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py in call(self, ctx, args, cancellation_manager)
    548               inputs=args,
    549               attrs=attrs,
--> 550               ctx=ctx)
    551         else:
    552           outputs = execute.execute_with_cancellation(

~/.local/lib/python3.6/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     58     ctx.ensure_initialized()
     59     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60                                         inputs, attrs, num_outputs)
     61   except core._NotOkStatusException as e:
     62     if name is not None:

InvalidArgumentError:  indices[11] = [17] does not index into shape [17,1,1]
	 [[{{node cond/then/_0/cond/ScatterNd_1}}]] [Op:__inference_detect_fn_35864]

3. Steps to reproduce

As described above, I follow the instruction but got exception for some pics, some pics are OK, but some failed, as attachments. object_detect_failed_image

4. Expected behavior

person should be detected as expected.

5. Additional context

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux 3.10.0-1062.9.1.el7.x86_64
  • Mobile device name if the issue happens on a mobile device:
  • TensorFlow installed from (source or binary): binary, pip installed.
  • TensorFlow version (use command below): tensorflow 2.3.0 tensorflow-addons 0.12.0 tensorflow-datasets 4.1.0 tensorflow-estimator 2.3.0 tensorflow-hub 0.10.0 tensorflow-model-optimization 0.5.0 tensorflow-serving-api 2.3.0
  • Python version: 3.6.8
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: no gpu used
  • GPU model and memory: no gpu used

Neway6655 avatar Feb 07 '21 04:02 Neway6655

any updates?

Neway6655 avatar Feb 18 '21 01:02 Neway6655

This should be fixed by https://github.com/tensorflow/models/commit/e5459a6bf10966a553f041bfd95daccc46be0456

The bug was due to the fact that sometimes the coordinates were negative. Please pull the latest version and let us know if this persists.

vighneshbirodkar avatar Apr 25 '21 16:04 vighneshbirodkar

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

google-ml-butler[bot] avatar Apr 25 '21 16:04 google-ml-butler[bot]

Hola, estoy ejecutando el siguiente código:

import cv2 import numpy as np import tensorflow as tf

cap = cv2.VideoCapture(0)

while True: # Read frame from camera ret, image_np = cap.read()

# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)

# Things to try:
# Flip horizontally
# image_np = np.fliplr(image_np).copy()

# Convert image to grayscale
# image_np = np.tile(
#     np.mean(image_np, 2, keepdims=True), (1, 1, 3)).astype(np.uint8)

input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections, predictions_dict, shapes = detect_fn(input_tensor)

label_id_offset = 1
image_np_with_detections = image_np.copy()

viz_utils.visualize_boxes_and_labels_on_image_array(
      image_np_with_detections,
      detections['detection_boxes'][0].numpy(),
      (detections['detection_classes'][0].numpy() + label_id_offset).astype(int),
      detections['detection_scores'][0].numpy(),
      category_index,
      use_normalized_coordinates=True,
      max_boxes_to_draw=200,
      min_score_thresh=.30,
      agnostic_mode=False)

# Display output
cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))

if cv2.waitKey(25) & 0xFF == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

Que sirve para ejecutar un modelo de deteccion de objetos utilizando una web cam. Pero al ejecutar recibo el siguiente error:

File "C:\Users\AXEL\Desktop\Tensorflow\workspace\training_demo\prueba2.py", line 23, in detections, predictions_dict, shapes = detect_fn(input_tensor) NameError: name 'detect_fn' is not defined [ WARN:1] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-ttbyx0jz\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

Alguien me puede ayudar a solucionar ese error por favor 😞

jabarragan1498 avatar Jul 20 '21 19:07 jabarragan1498

Hola, estoy ejecutando el siguiente código:

import cv2 import numpy as np import tensorflow as tf

cap = cv2.VideoCapture(0)

while True: # Read frame from camera ret, image_np = cap.read()

# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)

# Things to try:
# Flip horizontally
# image_np = np.fliplr(image_np).copy()

# Convert image to grayscale
# image_np = np.tile(
#     np.mean(image_np, 2, keepdims=True), (1, 1, 3)).astype(np.uint8)

input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections, predictions_dict, shapes = detect_fn(input_tensor)

label_id_offset = 1
image_np_with_detections = image_np.copy()

viz_utils.visualize_boxes_and_labels_on_image_array(
      image_np_with_detections,
      detections['detection_boxes'][0].numpy(),
      (detections['detection_classes'][0].numpy() + label_id_offset).astype(int),
      detections['detection_scores'][0].numpy(),
      category_index,
      use_normalized_coordinates=True,
      max_boxes_to_draw=200,
      min_score_thresh=.30,
      agnostic_mode=False)

# Display output
cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))

if cv2.waitKey(25) & 0xFF == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

Que sirve para ejecutar un modelo de deteccion de objetos utilizando una web cam. Pero al ejecutar recibo el siguiente error:

File "C:\Users\AXEL\Desktop\Tensorflow\workspace\training_demo\prueba2.py", line 23, in detections, predictions_dict, shapes = detect_fn(input_tensor) NameError: name 'detect_fn' is not defined [ WARN:1] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-ttbyx0jz\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

Alguien me puede ayudar a solucionar ese error por favor 😞

Did you clear the isssues, you faced??

Dreamcouple avatar Aug 19 '22 09:08 Dreamcouple