tensorflow / models

Models and examples built with TensorFlow
Other
77.05k stars 45.77k forks source link

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

Open power76 opened 4 years ago

power76 commented 4 years ago

Prerequisites

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

1. The entire URL of the file you are using

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

2. Describe the bug

I have completed the object_detection_tutorial run on Colab and it worked well. But when I run locally,there is a TypeError:

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 output_dict = {key:value[0, :num_detections].numpy() 16 for key,value in output_dict.items()} TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor' I noticed that someone said he solved the problem on TF2.0. But your installation instruction requires only TensorFlow 1.15. So what 's the problem? ## 3. Steps to reproduce Steps to reproduce the behavior. ## 4. Expected behavior A clear and concise description of what you expected to happen. ## 5. Additional context Include any logs that would be helpful to diagnose the problem. ## 6. System information - OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Win7 X64 - Mobile device name if the issue happens on a mobile device: - TensorFlow installed from (source or binary):binary - TensorFlow version (use command below):1.15.0 - Python version:3.7 - Bazel version (if compiling from source): - GCC/Compiler version (if compiling from source): - CUDA/cuDNN version: - GPU model and memory:
jaijujacob commented 4 years ago

Me too facing the same issue. Any workaround?

power76 commented 4 years ago

As I can't solve the problem on TF1.15, I upgraded it to 2.0 and got work.

jinuhwang commented 4 years ago

Pretty sure it's not the best way but replacing the line to

num_detections = int(tf.get_static_value(output_dict.pop('num_detections'))[0])

did the trick for me.

ahammadmejbah commented 4 years ago

This method works for me, Try it out.

layers1= tf.compat.v1.layers.dense(tf_x, 10, tf.nn.relu) output= tf.compat.v1.layers.dense(layers1, 1)

glopezzz commented 4 years ago

num_detections = int(tf.get_static_value(output_dict.pop('num_detections'))[0])

I get this error while running your code: TypeError: 'NoneType' object is not subscriptable

Petros626 commented 1 year ago

As I can't solve the problem on TF1.15, I upgraded it to 2.0 and got work.

that's a workaround not a solution.