#python #python-3.x #numpy #tensorflow #object-detection
#питон #python-3.x #тупица #тензорный поток #обнаружение объектов
Вопрос:
С помощью кода ниже я выполняю вывод обнаружения объектов TensorFlow для изображений в каталоге. Код работает нормально, за исключением случаев, когда я пытаюсь напечатать количество объектов, обнаруженных на каждом изображении.
path = '/home/user/Downloads/test/' for image_path in os.listdir(path): input_path = os.path.join(path, image_path) print('Evaluating:', input_path) image = Image.open(input_path) img_width, img_height = image.size image_np = np.array(image.getdata()).reshape((img_height, img_width, 3)).astype(np.int32) # Run inference. start = time.time() output_dict = run_inference(detection_graph, image_np) end = time.time() # Visualization of the results of a detection. vis_util.visualize_boxes_and_labels_on_image_array( image_np, output_dict['detection_boxes'], output_dict['detection_classes'], output_dict['detection_scores'], category_index, use_normalized_coordinates=True, line_thickness=8) plt.figure(figsize=(12, 8)) plt.imshow(image_np) print("Prediction time for: " image_path " " str(end-start)) print("Found %d objects." % len(output_dict["detection_scores"]))
По какой-то причине, которую я не понимаю, он всегда печатает, что найдено 100 объектов, даже когда четко видно, что на изображении нужно обнаружить менее 100 объектов.
Вот пример:
Evaluating: /home/user/Downloads/test/P2044.png Prediction time for: P2044.png 4.666229724884033 Found 100 objects. Evaluating: /home/user/Downloads/test/P1854.jpg Prediction time for: P1854.jpg 4.627516984939575 Found 100 objects.
Что я здесь упускаю?
Комментарии:
1. Попробуйте установить
max_boxes_to_draw=100
иmin_score_thresh
на какое-то более низкое значение (по умолчанию 0,5) в функцииvisualize_boxes_and_labels_on_image_array
. Тогда вы сможете получить желаемый результат.2. Спасибо, я только что попробовал, но это все равно не работает.