API обнаружения объекта Tensorflow получает метки в массиве - PullRequest
0 голосов
/ 28 апреля 2018

Я хочу получить метки из API обнаружения объектов Tensorflow и поместить их в массив вместо того, чтобы показывать их на видео

это функция обнаружения_объекта

def detect_objects(image_np, sess, detection_graph):
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
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.
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.
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')

# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
    [boxes, scores, 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)


return image_np

Ответы [ 2 ]

0 голосов
/ 26 марта 2019
    classes=output_dict['detection_classes']
    boxes =output_dict['detection_boxes']
    scores = output_dict['detection_scores']

    for i in range(min(max_boxes_to_draw, boxes.shape[0])):
          if scores is None or scores[i] > min_score_thresh :
              if classes[i] in category_index.keys():
                  class_name = category_index[classes[i]]['name']
                  print(class_name)   

Когда я дал max_boxes_to_draw = 20 min_score_thresh = 0.5 (это по умолчанию), это сработало.

Этот фрагмент кода можно найти в файле visualization_utils.py.

0 голосов
/ 25 июня 2018

После некоторого исследования это то, что я придумал

final_score = np.squeeze(scores)    
    count = 0
    for i in range(100):
        if scores is None or final_score[i] > 0.5:
                count = count + 1
    print('cpunt',count)
    printcount =0;
    for i in classes[0]:
          printcount = printcount +1
          print(category_index[i]['name'])

          if(printcount == count):
                break

это напечатает все обнаруженные объекты, если вы хотите вернуть его, вы можете добавить его к некоторой переменной и вернуть.

если вы хотите распечатать только обнаруженные объекты, добавьте print (имя_класса) в файл visualization_utils.py внутри папки util

if not agnostic_mode:
          if classes[i] in category_index.keys():
            class_name = category_index[classes[i]]['name']

            **print(class_name)** --> this line 
          else:
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...