【发布时间】:2018-01-14 12:54:53
【问题描述】:
我正在执行https://github.com/tensorflow/tensorflow这个检测图像中物体的例子。
我想获取检测到的对象的计数,下面是在图像中绘制检测到的对象的代码。但我无法获得检测到的对象的数量。
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
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)
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=1)
plt.figure(figsize=IMAGE_SIZE)
plt.imshow(image_np)
这是提供实际对象检测的代码块,如下图所示:
如何获取对象计数?
【问题讨论】:
-
这给了我这些类的信息。我需要一个从 box.shape 的打印长度中得到的计数。任何方式谢谢你。
-
这是一个用于 TensorFlow 的对象计数 API:github.com/ahmetozlu/tensorflow_object_counting_api,您可以使用它来计算对象以及更多用于开发基于对象检测和计数的项目..
标签: python tensorflow machine-learning jupyter-notebook