Tensorflow对象检测:如何批量检测
Tensorflow object detection: how to detect on batch
我正在尝试使用 tensorflow detection tutorial 对批次执行检测,
但是下面的代码给我 setting an array element with a sequence.
错误。
# load multiple images
np_images = []
for img_path in img_paths:
img = Image.open(image_path)
image_np = load_image_into_numpy_array(img)
image_np_expanded = np.expand_dims(image_np, axis=0)
np_images.append(image_np)
#Get input and output tensors
image_tensor = det_graph.get_tensor_by_name('image_tensor:0')
boxes = det_graph.get_tensor_by_name('detection_boxes:0')
scores = det_graph.get_tensor_by_name('detection_scores:0')
classes = det_graph.get_tensor_by_name('detection_classes:0')
num_detections = det_graph.get_tensor_by_name('num_detections:0')
# detect on batch of images
detection_results = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: np_images})
如何正确输入一组图片?
feed_dict 中的 image_tensor 应具有维度 [batch_size, x, y, 3],其中 (x,y) 是每个图像的大小。如果您的图像大小都不同,则无法创建这样的 numpy 数组。您可以调整图像大小来解决此问题。
# If the NN was trained on (300,300) size images
IMAGE_SIZE = (300, 300)
for img_path in img_paths:
img = Image.open(image_path).resize(IMAGE_SIZE)
image_np = load_image_into_numpy_array(img)
np_images.append(image_np)
...
detection_results = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: np.array(np_images)})
我正在尝试使用 tensorflow detection tutorial 对批次执行检测,
但是下面的代码给我 setting an array element with a sequence.
错误。
# load multiple images
np_images = []
for img_path in img_paths:
img = Image.open(image_path)
image_np = load_image_into_numpy_array(img)
image_np_expanded = np.expand_dims(image_np, axis=0)
np_images.append(image_np)
#Get input and output tensors
image_tensor = det_graph.get_tensor_by_name('image_tensor:0')
boxes = det_graph.get_tensor_by_name('detection_boxes:0')
scores = det_graph.get_tensor_by_name('detection_scores:0')
classes = det_graph.get_tensor_by_name('detection_classes:0')
num_detections = det_graph.get_tensor_by_name('num_detections:0')
# detect on batch of images
detection_results = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: np_images})
如何正确输入一组图片?
feed_dict 中的 image_tensor 应具有维度 [batch_size, x, y, 3],其中 (x,y) 是每个图像的大小。如果您的图像大小都不同,则无法创建这样的 numpy 数组。您可以调整图像大小来解决此问题。
# If the NN was trained on (300,300) size images
IMAGE_SIZE = (300, 300)
for img_path in img_paths:
img = Image.open(image_path).resize(IMAGE_SIZE)
image_np = load_image_into_numpy_array(img)
np_images.append(image_np)
...
detection_results = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: np.array(np_images)})