2

I am new to learning object detection using tensorflow, I am implementing a model with reference to this site https://www.mygreatlearning.com/blog/object-detection-using-tensorflow/ I have followed all steps but there are two prominent errors that come again and again,the first one is

"INFO:tensorflow:Saver not created because there are no variables in the graph to restore" when running these two commands

model_name = 'ssd_inception_v2_coco_2017_11_17'
detection_model = load_model(model_name)

another error is TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor' on running these

for image_path in TEST_IMAGE_PATHS:
    print(image_path)
    show_inference(detection_model, image_path)

this is the call stack:

models\research\object_detection\test_images\image1.jpg
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-e230477d58de> in <module>
      1 for image_path in TEST_IMAGE_PATHS:
      2     print(image_path)
----> 3     show_inference(detection_model, image_path)

<ipython-input-18-a9efdd893038> in show_inference(model, image_path)
      7     # Actual detection.
      8 
----> 9     output_dict = run_inference_for_single_image(model, image_np)
     10     # Visualization of the results of a detection.
     11     vis_util.visualize_boxes_and_labels_on_image_array(

<ipython-input-17-7172365aecd9> in run_inference_for_single_image(model, image)
     12     # Convert to numpy arrays, and take index [0] to remove the batch dimension.
     13     # We're only interested in the first num_detections.
---> 14     num_detections = int(output_dict.pop('num_detections'))
     15 
     16     #num_detections = int(tf.get_static_value(output_dict.pop('num_detections'))[0])

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'

Some answer says to remove tensor from dict but I don't know exactly ohw to remove them from dictionary if it is to be removed from there, and try downgrading or upgrading tensorflow. On commenting line 14 and using line 16 after uncommenting it gives error None is not subscriptable. I have also changed tf.gfile to tf.io.gfile . I am using tensorflow version 1.15.0 after downgrading.

1 Answer 1

1

About the first error: You probably using the following code from the blog-post you mentioned:

def load_model(model_name):
  base_url = 'http://download.tensorflow.org/models/object_detection/'
  model_file = model_name + '.tar.gz'
  model_dir = tf.keras.utils.get_file(
    fname=model_name, 
    origin=base_url + model_file,
    untar=True)
 
  model_dir = pathlib.Path(model_dir)/"saved_model"
 
  model = tf.saved_model.load(str(model_dir))
 
  return model

use a debugger to check if model is being downloaded from the url.

About the second error:

output_dict = run_inference_for_single_image(model, image_np)

seems to return a dictionary with tensors as values.

Try:

num_detections = int(output_dict.pop('num_detections').numpy())

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot ,it worked please can you tell me if possible why it gives OSError: image file is truncated (4 bytes not processed) after running on 2 test_images inside "models/research/object_detection/test_images" folder.
OSerror is also resolved thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.