Skip to content

Commit 0e61d32

Browse files
authored
Update to tf_od_predict.py
Moving the for loop into the TF Session block. Was throwing a closed session error when trying to execute sess.run() on line 61
1 parent d19d22f commit 0e61d32

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

examples/utils/tf_od_predict.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,31 @@ def tf_od_pred():
5050
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
5151
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
5252
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
53-
for image_path in test_imgs:
54-
image = Image.open(image_path)
55-
image_np = load_image_into_numpy_array(image)
56-
# the array based representation of the image will be used later in order to prepare the
57-
# result image with boxes and labels on it.
58-
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
59-
image_np_expanded = np.expand_dims(image_np, axis=0)
60-
# Actual detection.
61-
(boxes, scores, classes, num) = sess.run(
62-
[detection_boxes, detection_scores, detection_classes, num_detections],
63-
feed_dict={image_tensor: image_np_expanded})
64-
# draw_bounding_box_on_image(image, boxes, )
65-
# Visualization of the results of a detection.
66-
vis_image = vis_util.visualize_boxes_and_labels_on_image_array(
67-
image_np,
68-
np.squeeze(boxes),
69-
np.squeeze(classes).astype(np.int32),
70-
np.squeeze(scores),
71-
category_index,
72-
use_normalized_coordinates=True,
73-
line_thickness=1)
74-
print("{} boxes in {} image tile!".format(len(boxes), image_path))
75-
image_pil = Image.fromarray(np.uint8(vis_image)).convert('RGB')
76-
with tf.gfile.Open(image_path, 'w') as fid:
77-
image_pil.save(fid, 'PNG')
53+
for image_path in test_imgs:
54+
image = Image.open(image_path)
55+
image_np = load_image_into_numpy_array(image)
56+
# the array based representation of the image will be used later in order to prepare the
57+
# result image with boxes and labels on it.
58+
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
59+
image_np_expanded = np.expand_dims(image_np, axis=0)
60+
# Actual detection.
61+
(boxes, scores, classes, num) = sess.run(
62+
[detection_boxes, detection_scores, detection_classes, num_detections],
63+
feed_dict={image_tensor: image_np_expanded})
64+
# draw_bounding_box_on_image(image, boxes, )
65+
# Visualization of the results of a detection.
66+
vis_image = vis_util.visualize_boxes_and_labels_on_image_array(
67+
image_np,
68+
np.squeeze(boxes),
69+
np.squeeze(classes).astype(np.int32),
70+
np.squeeze(scores),
71+
category_index,
72+
use_normalized_coordinates=True,
73+
line_thickness=1)
74+
print("{} boxes in {} image tile!".format(len(boxes), image_path))
75+
image_pil = Image.fromarray(np.uint8(vis_image)).convert('RGB')
76+
with tf.gfile.Open(image_path, 'w') as fid:
77+
image_pil.save(fid, 'PNG')
7878

7979

8080

0 commit comments

Comments
 (0)