Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 与检测到的对象关联的打印类_Python_Numpy_Tensorflow_Object Detection - Fatal编程技术网

Python 与检测到的对象关联的打印类

Python 与检测到的对象关联的打印类,python,numpy,tensorflow,object-detection,Python,Numpy,Tensorflow,Object Detection,我正在运行TensorFlow的ObjectDetection部分中的默认iPython笔记本: 我能够使用下面的代码在笔记本的最后一个单元格中打印模型所做注释的坐标 with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: # Definite input and output Tensors for detection_graph image_tensor = d

我正在运行TensorFlow的ObjectDetection部分中的默认iPython笔记本:

我能够使用下面的代码在笔记本的最后一个单元格中打印模型所做注释的坐标

with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    # Definite input and output Tensors for detection_graph
    image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
    # Each box represents a part of the image where a particular object was detected.
    detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
    # Each score represent how level of confidence for each of the objects.
    # Score is shown on the result image, together with the class label.
    detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
    detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
    num_detections = detection_graph.get_tensor_by_name('num_detections:0')
    for image_path in TEST_IMAGE_PATHS:
      image = Image.open(image_path)
      # the array based representation of the image will be used later in order to prepare the
      # result image with boxes and labels on it.
      image_np = load_image_into_numpy_array(image)
      # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
      image_np_expanded = np.expand_dims(image_np, axis=0)
      # Actual detection.
      (boxes, scores, classes, num) = sess.run(
          [detection_boxes, detection_scores, detection_classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})
      # Visualization of the results of a detection.
      vis_util.visualize_boxes_and_labels_on_image_array(
          image_np,
          np.squeeze(boxes),
          np.squeeze(classes).astype(np.int32),
          np.squeeze(scores),
          category_index,
          use_normalized_coordinates=True,
          line_thickness=8)
      plt.figure(figsize=IMAGE_SIZE)
      plt.imshow(image_np)
      s_boxes = boxes[scores > 0.5]
      height = 636
      width = 1024
      s_boxes[:,0] = s_boxes[:,0]*height
      s_boxes[:,2] = s_boxes[:,2]*height
      s_boxes[:,1] = s_boxes[:,1]*width
      s_boxes[:,3] = s_boxes[:,3]*width
      for s in s_boxes:
            print(s)
      break
我得到的输出:

我试图打印与模型所做注释关联的类 因此,输出应该如下所示(给定“Dog”在“category_index”中有索引1):

我面临的主要问题是,我无法找出如何从“类”中为相应的
得分>0.5的元素编制索引

可视化\u图像\u阵列上的\u框\u和\u标签\u
功能如下:


可以像

s_class = classes[scores > 0.5]
print(s_class)

对于对象检测iPynb中的第一个示例,将返回
[18.18.]
。18对应于
类别索引中的狗

可以类似于

s_class = classes[scores > 0.5]
print(s_class)
对于对象检测iPynb中的第一个示例,将返回
[18.18.]
。18对应于
类别索引中的狗

s_class = classes[scores > 0.5]
print(s_class)