Tensorflow 2.0对象检测API演示错误int()参数必须是字符串,类似字节的对象或数字,而不是"Tensor" [英] Tensorflow 2.0 Object Detection API Demo Error int() argument must be a string, a bytes-like object or a number, not 'Tensor'

查看:478
本文介绍了Tensorflow 2.0对象检测API演示错误int()参数必须是字符串,类似字节的对象或数字,而不是"Tensor"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从' object_detection_tutorial实施代码.ipynb "在我的本地计算机上进行更改,然后进行一些操作.本教程非常混乱,我正尽力解决遇到的任何问题,但对于此问题我一无所知.所以,我在这里.

I'm trying to implement the code from 'object_detection_tutorial.ipynb' on my local machine to change some parts and play around. This tutorial is a huge mess and I'm trying really hard to fix any problem I came across but for this one I had no clue. So, here I am.

我正在使用Windows 10和Visual Studio 2019 Professional.任何与Tensorflow相关的软件包都是最新的,我还有另一个机器学习应用程序正在运行,没有任何问题.

I'm using Windows 10 and Visual Studio 2019 Professional. Any package related to Tensorflow is up to date and I have another Machine Learning application running with no problems.

我想指出的是,我从原始格式"ipynb"转换了此代码. (另存为.py)

I'd like to point out that, I converted this code from its original format which is 'ipynb'. (save as .py)

如果您需要任何其他信息,请问我,因为我真的需要在工作代码中理解这个概念.

If you need any extra information please ask me because I really need to understand this concept on a working code.

num_detections = int(output_dict.pop('num_detections')),此部分给出错误:

num_detections = int(output_dict.pop('num_detections')) this part gives the error:

错误int()参数必须是字符串,类似字节的对象或数字,而不是'Tensor'

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

def run_inference_for_single_image(model, image):
image = np.asarray(image)
# The input needs to be a tensor, convert it using `tf.convert_to_tensor`.
input_tensor = tf.convert_to_tensor(image)
# The model expects a batch of images, so add an axis with `tf.newaxis`.
input_tensor = input_tensor[tf.newaxis,...]

# Run inference
output_dict = model(input_tensor)

# All outputs are batches tensors.
# Convert to numpy arrays, and take index [0] to remove the batch dimension.
# We're only interested in the first num_detections.

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

output_dict = {key:value[0, :num_detections].numpy() 
               for key,value in output_dict.items()}
output_dict['num_detections'] = num_detections

# detection_classes should be ints.
output_dict['detection_classes'] = 
output_dict['detection_classes'].astype(np.int64)

# Handle models with masks:
if 'detection_masks' in output_dict:
  # Reframe the the bbox mask to the image size.
  detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks(
           output_dict['detection_masks'], output_dict['detection_boxes'],
           image.shape[0], image.shape[1])      
  detection_masks_reframed = tf.cast(detection_masks_reframed > 0.5,
                                   tf.uint8)
  output_dict['detection_masks_reframed'] = detection_masks_reframed.numpy()

return output_dict

当我打印一些与output_dict相关的变量时,我看到了;

When I print few variables related to output_dict, I see;

输入张量

Tensor("strided_slice:0", shape=(1, 636, 1024, 3), dtype=uint8)

模型(input_tensor)

model(input_tensor)

{'detection_scores': 
< tf.Tensor 'StatefulPartitionedCall_1:2' shape=(?, 100) dtype=float32 >, 
'detection_classes': 
< tf.Tensor 'StatefulPartitionedCall_1:1' shape=(?, 100) dtype=float32 >, 
'num_detections': 
< tf.Tensor 'StatefulPartitionedCall_1:3' shape=(?,) dtype=float32 >, 
'detection_boxes': 
< tf.Tensor 'StatefulPartitionedCall_1:0' shape=(?, 100, 4) dtype=float32 >
}

output_dict

output_dict

{'detection_scores': 
< tf.Tensor 'StatefulPartitionedCall:2' shape=(?, 100) dtype=float32 >, 
'detection_classes': 
< tf.Tensor 'StatefulPartitionedCall:1' shape=(?, 100) dtype=float32 >, 
'num_detections': 
< tf.Tensor 'StatefulPartitionedCall:3' shape=(?,) dtype=float32 >, 
'detection_boxes': 
< tf.Tensor 'StatefulPartitionedCall:0' shape=(?, 100, 4) dtype=float32 >
}

output_dict.pop

output_dict.pop

Tensor("StatefulPartitionedCall:3", shape=(?,), dtype=float32)

WARNING:tensorflow:Tensor._shape is private, use Tensor.shape instead. 
Tensor._shape will eventually be removed.

推荐答案

我已经解决了这个问题.显然,我的Tensorflow安装有问题.因此,我已经删除了所有相关的安装,然后重新安装了所有内容.

Guys I've fixed the problem. Apparently, I had a problem with my Tensorflow installation. So, I've deleted all the related installation and re-installed everything.

该问题应该与此相关,因为TF v2.0已经具有Tensor到int的转换.

The problem should be related to this because TF v2.0 has Tensor to int conversion already.

这篇关于Tensorflow 2.0对象检测API演示错误int()参数必须是字符串,类似字节的对象或数字,而不是"Tensor"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆