tensorflow / models

Models and examples built with TensorFlow
Other
77k stars 45.79k forks source link

object_detection_tutorial :detection wrong!! #7773

Open tonyprince6 opened 4 years ago

tonyprince6 commented 4 years ago

when i run :: model_name = 'ssd_mobilenet_v1_coco_2017_11_17' detection_model = load_model(model_name)

amazing thing happens!(and i do not knew how to deal with it..):

WARNING:tensorflow:From :11: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version. Instructions for updating: This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.

TypeError Traceback (most recent call last)

in 1 model_name = 'ssd_mobilenet_v1_coco_2017_11_17' ----> 2 detection_model = load_model(model_name) in load_model(model_name) 9 model_dir = pathlib.Path(model_dir)/"saved_model" 10 ---> 11 model = tf.saved_model.load(str(model_dir)) 12 model = model.signatures['serving_default'] 13 ~/.local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs) 322 'in a future version' if date is None else ('after %s' % date), 323 instructions) --> 324 return func(*args, **kwargs) 325 return tf_decorator.make_decorator( 326 func, new_func, 'deprecated', TypeError: load() missing 2 required positional arguments: 'tags' and 'export_dir'
tonyprince6 commented 4 years ago

my tensorflow- gpu:1.13.1 cuda:10.0 cudnn:7.3.1

ramshankerg commented 4 years ago

I too got this error, I had updated tensorflow to latest version but still the print(tf.__version__) shows 1.13.1)

ramshankerg commented 4 years ago

I solved this error, I had installed tensorflow inconda environement.Just went inside and conda install tensorflow=2.0.0 and then just re run the notebook.

tonyprince6 commented 4 years ago

thanks for your replay. I konw the reason,this example notebook must need TensorFlow2.x.x!

afeyzadogan commented 4 years ago

I solved this error, I had installed tensorflow inconda environement.Just went inside and conda install tensorflow=2.0.0 and then just re run the notebook.

hi what is your cuda and cudnn version

irfan798 commented 4 years ago

There is a version conflict between Object Detection Readme and Object Detection Tutorial

Despite Readme specifically says TensorFlow version 1.15 is required and version 2 is not supported, object_detection_tutorial.ipynb uses Tensorflow 2 TensorFlow Requirement: 1.15 TensorFlow 2 Not Supported

And on installation.md it says required version of Tensorflow is 1.15

I quote:

Dependencies

Tensorflow Object Detection API depends on the following libraries:

  • Protobuf 3.0.0
  • Python-tk
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the "tensorflow/models/research/" checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow (1.15.0)
  • Cython
  • contextlib2
  • cocoapi

But Object Detection Tutorial installs Tensorflow 2 with

pip install -U --pre tensorflow=="2.*"

For Tutorial to work with Tensorflow Version 1.15

You need to change load model function from: model = tf.saved_model.load(str(model_dir)) to model = tf.saved_model.load_v2(str(model_dir)) or model = tf.compat.v2.saved_model.load(str(model_dir)) which works for both Tensorflow 1 and 2

Eager Execution

Without running session we can't get numeric results on Tensorflow 1, so you will see this error:

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

on line:

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

Since this line expects a numeric value you need to enable eager execution just after imports with

tf.compat.v1.enable_eager_execution()

ZOUYIyi commented 4 years ago

There is a version conflict between Object Detection Readme and Object Detection Tutorial

Despite Readme specifically says TensorFlow version 1.15 is required and version 2 is not supported, object_detection_tutorial.ipynb uses Tensorflow 2 TensorFlow Requirement: 1.15 TensorFlow 2 Not Supported

And on installation.md it says required version of Tensorflow is 1.15

I quote:

Dependencies

Tensorflow Object Detection API depends on the following libraries:

  • Protobuf 3.0.0
  • Python-tk
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the "tensorflow/models/research/" checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow (1.15.0)
  • Cython
  • contextlib2
  • cocoapi

But Object Detection Tutorial installs Tensorflow 2 with

pip install -U --pre tensorflow=="2.*"

For Tutorial to work with Tensorflow Version 1.15

You need to change load model function from: model = tf.saved_model.load(str(model_dir)) to model = tf.saved_model.load_v2(str(model_dir)) or model = tf.compat.v2.saved_model.load(str(model_dir)) which works for both Tensorflow 1 and 2

Eager Execution

Without running session we can't get numeric results on Tensorflow 1, so you will see this error:

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

on line:

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

Since this line expects a numeric value you need to enable eager execution just after imports with

tf.compat.v1.enable_eager_execution()

I tried your solution,but it says: INFO:tensorflow:Saver not created because there are no variables in the graph to restore

irfan798 commented 4 years ago

@ZOUYIyi detection should work despite the info message, it's probably about saving the session while training

You can check this version of tutorial

https://github.com/irfan798/models/blob/master/research/object_detection/object_detection_tutorial.ipynb

AhmadShaik commented 3 years ago

For tensorflow 1.15, load and model inference try this

import tensorflow as tf
from tensorflow.python.saved_model import tag_constants
model = tf.saved_model.load_v2(
    model_path, tags=[tag_constants.SERVING]
)

For tensorflow 2.3, load and model inference try this

import tensorflow as tf
from tensorflow.python.saved_model import tag_constants
model = tf.saved_model.load(input_saved_model_dir, tags=[tag_constants.SERVING])
)
Petros626 commented 1 year ago

There is a version conflict between Object Detection Readme and Object Detection Tutorial

Despite Readme specifically says TensorFlow version 1.15 is required and version 2 is not supported, object_detection_tutorial.ipynb uses Tensorflow 2 TensorFlow Requirement: 1.15 TensorFlow 2 Not Supported And on installation.md it says required version of Tensorflow is 1.15 I quote:

Dependencies

Tensorflow Object Detection API depends on the following libraries:

  • Protobuf 3.0.0
  • Python-tk
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the "tensorflow/models/research/" checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow (1.15.0)
  • Cython
  • contextlib2
  • cocoapi

But Object Detection Tutorial installs Tensorflow 2 with

pip install -U --pre tensorflow=="2.*"

For Tutorial to work with Tensorflow Version 1.15

You need to change load model function from: model = tf.saved_model.load(str(model_dir)) to model = tf.saved_model.load_v2(str(model_dir)) or model = tf.compat.v2.saved_model.load(str(model_dir)) which works for both Tensorflow 1 and 2

Eager Execution

Without running session we can't get numeric results on Tensorflow 1, so you will see this error:

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

on line: num_detections = int(output_dict.pop('num_detections')) Since this line expects a numeric value you need to enable eager execution just after imports with tf.compat.v1.enable_eager_execution()

I tried your solution,but it says: INFO:tensorflow:Saver not created because there are no variables in the graph to restore

just a information, it doesn't matter for the detection later, as @irfan798 mentioned.