Tensorflow 2.0对象检测API演示错误int()参数必须是字符串,类似字节的对象或数字,而不是“ Tensor”

我正在尝试在本地计算机上实现来自“ object_detection_tutorial.ipynb”的代码,以更改某些部分并进行调试。本教程非常混乱,我正在尽力解决遇到的任何问题,但对于此问题我一无所知。所以,我在这里。

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

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

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

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

错误int()参数必须是字符串,类似字节的对象或数字,而不是'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相关的变量时,我会看到;

输入张量

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

模型(input_tensor)

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

output_dict

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

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.
samebean 回答:Tensorflow 2.0对象检测API演示错误int()参数必须是字符串,类似字节的对象或数字,而不是“ Tensor”

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

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

本文链接:https://www.f2er.com/3168400.html

大家都在问